npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wikimedia/url-get

v1.0.0

Published

Utility functions to get Objects from YAML or JSON at local or remote URIs

Downloads

22

Readme

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. |