@wikimedia/url-get

1.0.0 • Public • Published

url-get

This module contains library functions to fetch and parse YAML or JSON content at local or remote URLs.

NOTE: This module codebase currently lives in the EventGate repository. TODO: Move url-get to its own git repository.

url-get~objectFactory(data) ⇒ Object

Converts a utf-8 byte buffer or a YAML/JSON string into an object and returns it.

Kind: inner method of url-get

Param Type
data string | Buffer | Object

url-get~uriHasProtocol(uri) ⇒ boolean

Returns true if the uri has protocol schema on the front, else false.

Kind: inner method of url-get

Param Type
uri string

url-get~fileExtension(filename) ⇒ string

Returns the file extension (or the last part after a final '.' in a file basename) of a filename path. If no file extension is present, this returns an empty string. If the final part of a file name after '.' is numeric, this is not a file extension, and an empty string will be returned.

Kind: inner method of url-get

Param Type
filename string

url-get~resolveUri(uri, baseUri, defaultFileExtension) ⇒ Promise.<Object>

Takes a possibly relative uri, and augments it so that it is better suited for use in requests. If the uri is already qualified (e.g. is starts with a protocol scheme), baseUri will not be prepended. If the uri already ends in a file extensions, defaultFileExtension will not be appended. If the baseUri given does not have a protocol schema, it is assumed to be file://. file:// paths will be resolved with path.resolve to be transformed into absolute file paths.

Kind: inner method of url-get

Param Type Description
uri string uri to resolve with baseUri and defaultFileExtension
baseUri string If given, uris that don't start with a protocol scheme will be prepended with this.
defaultFileExtension string If given, uris that don't end with a file extension will be appended with this.

url-get~urlGet(url, options) ⇒ Promise.<string>

Given a string URL, returns a Promise of the contents at that URL. Supports both file:// (via fs.readFile) and other http based URLs with preq.get.

Kind: inner method of url-get

Param Type Description
url string
options Object Options to pass to the function used to open the url. This will be different for local files vs remote (http) URIs, so make sure you pass options that make sense for that url.

url-get~urlGetObject(url, options) ⇒ Promise.<Object>

Given a URL, returns a Promise of the contents at that converted into an Object. The content at URL must either be a JSON or YAML string.

Kind: inner method of url-get

Param Type Description
url string
options Object Options to pass to the function used to open the url. This will be different for local files vs remote (http) URIs, so make sure you pass options that make sense for that url.

url-get~urlGetFirstObject(urls, options) ⇒ Promise.<Object>

Given a list of URLs, returns a Promise of the first resolved result of urlGetObject. If no URL resolves, this will return the final rejection.

Kind: inner method of url-get

Param Type Description
urls Array.<string>
options Object Options to pass to the function used to open the url. This will be different for local files vs remote (http) URIs, so make sure you pass options that make sense for that url.

url-get~uriGetFirstObject(uri, baseUris, defaultFileExtension, options) ⇒ Promise.<Object>

Combines resolveUri and urlGetObjectFirst to return the first baseUri + uri combination that resolves to an object.

Kind: inner method of url-get

Param Type Description
uri string uri to resolve with baseUri and defaultFileExtension
baseUris Array.<string> If given, uris that don't start with a protocol scheme will be prepended with these.
defaultFileExtension string If given, uris that don't end with a file extension will be appended with this.
options Object Options to pass to the function used to open the url. This will be different for local files vs remote (http) URIs, so make sure you pass options that make sense for that url.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    5
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    5

Package Sidebar

Install

npm i @wikimedia/url-get

Weekly Downloads

5

Version

1.0.0

License

Apache-2.0

Unpacked Size

33.8 kB

Total Files

6

Last publish

Collaborators

  • mvolz
  • lwatz16
  • tchin25
  • egardner
  • ottomata
  • annetee
  • jgiannelos-wmf
  • joakin
  • krinkle
  • jdforrester
  • edg2s
  • volker_e
  • catrope
  • santhosh.thottingal
  • cscott
  • subbu_ss
  • arlolra
  • jdlrobson
  • mateusbs17
  • brightbyte
  • phuedx
  • nrayio
  • jandre3000
  • sbassett29
  • nikerabbit