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
-
~uriHasProtocol(uri) ⇒
boolean
-
~fileExtension(filename) ⇒
string
-
~resolveUri(uri, baseUri, defaultFileExtension) ⇒
Promise.<Object>
-
~urlGet(url, options) ⇒
Promise.<string>
-
~urlGetObject(url, options) ⇒
Promise.<Object>
-
~urlGetFirstObject(urls, options) ⇒
Promise.<Object>
-
~uriGetFirstObject(uri, baseUris, defaultFileExtension, options) ⇒
Promise.<Object>
-
~objectFactory(data) ⇒
Object
url-get~objectFactory(data) ⇒ 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
|
boolean
url-get~uriHasProtocol(uri) ⇒ Returns true if the uri has protocol schema on the front, else false.
Kind: inner method of url-get
Param | Type |
---|---|
uri | string |
string
url-get~fileExtension(filename) ⇒ 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 |
Promise.<Object>
url-get~resolveUri(uri, baseUri, defaultFileExtension) ⇒ 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. |
Promise.<string>
url-get~urlGet(url, options) ⇒ 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. |
Promise.<Object>
url-get~urlGetObject(url, options) ⇒ 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. |
Promise.<Object>
url-get~urlGetFirstObject(urls, options) ⇒ 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. |
Promise.<Object>
url-get~uriGetFirstObject(uri, baseUris, defaultFileExtension, options) ⇒ 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. |