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

@grimen/connection-uri

v0.1.1

Published

A robust connection URI parser/stringifier - for Node/JavaScript.

Downloads

89

Readme

js-connection-uri NPM version Build Status Coverage Status

A robust connection URI parser/stringifier - for JavaScript/Node.

Introduction

This connection URI library was implemented in lack of robust JavaScript/Node.js alternatives. This one supports absolute/relative multi-host connection URIs with smart fallbacks.

Install

Install using npm:

$ npm install @grimen/connection-uri

Install using yarn:

$ yarn add @grimen/connection-uri

Use

Very basic example:

const connectionURI = require('@grimen/connection-uri')

basicConnectionURI = 'localhost:3000/namespace/foo/'
basicConnectionOptions = connectionURI.unpack(basicConnectionURI)

console.log(`\n\`connectionURI.unpack("${basicConnectionURI}")\`\n\nRESULT:`, basicConnectionOptions, '\n')
//
// {
//     'protocol': 'http',
//     'auth': None,
//
//     'endpoint': 'localhost:3000',
//     'endpoints': ['localhost:3000'],
//
//     'host': 'localhost',
//     'hosts': ['localhost'],
//
//     'port': 3000,
//     'ports': [3000],
//
//     'path': '/namespace/foo/',
//     'query': {},
//
//     'credentials': {
//         'username': None,
//         'password': None,
//     },
//     'key': 'namespace/foo',
//     'namespace': 'namespace/foo',
//
//     'url': 'http://localhost:3000/namespace/foo/',
//     'urls': [
//         'http://localhost:3000/namespace/foo/'
//     ],
// }
//

basicConnectionURI = connectionURI.pack(basicConnectionOptions)

console.log(`\n\`connectionURI.pack(${JSON.stringify(basicConnectionOptions)})\`\n\nRESULT:`, JSON.stringify(basicConnectionURI), '\n')
//
// 'http://localhost:3000/namespace/foo/'
//

complexMultihostURI = 'foo://m+4.gTe~5e^(:m+4.gTe~5e^(@ds143144-a0.mlab.com:43144,ds143144-a1.mlab.com:43145/bar-baz'
complexMultihostOptions = connectionURI.unpack(complexMultihostURI)

console.log(`\n\`connectionURI.unpack("${complexMultihostURI}")\`\n\nRESULT:`, complexMultihostOptions, '\n')
//
// {
//     'protocol': 'foo',
//     'auth': 'm+4.gTe~5e^(:m+4.gTe~5e^(',
//
//     'host': 'ds143144-a0.mlab.com',
//     'port': 43144,
//
//     'endpoint': 'ds143144-a0.mlab.com:43144',
//     'endpoints': ['ds143144-a0.mlab.com:43144', 'ds143144-a1.mlab.com:43145'],
//
//     'host': 'ds143144-a0.mlab.com',
//     'hosts': ['ds143144-a0.mlab.com', 'ds143144-a1.mlab.com'],
//
//     'port': 43144,
//     'ports': [43144, 43145],
//
//     'path': '/bar-baz',
//     'query': {},
//
//     'credentials': {
//         'username': 'm+4.gTe~5e^(',
//         'password': 'm+4.gTe~5e^(',
//     },
//     'key': 'bar-baz',
//     'namespace': 'bar-baz',
//
//     'url': 'foo://m+4.gTe~5e^(:m+4.gTe~5e^(@ds143144-a0.mlab.com:43144,ds143144-a1.mlab.com:43145/bar-baz',
//     'urls': [
//         'foo://m+4.gTe~5e^(:m+4.gTe~5e^(@ds143144-a0.mlab.com:43144/bar-baz',
//         'foo://m+4.gTe~5e^(:m+4.gTe~5e^(@ds143144-a1.mlab.com:43145/bar-baz'
//     ],
// }
//

complexMultihostURI = connectionURI.pack(complexMultihostOptions)

console.log(`\n\`connectionURI.pack(${JSON.stringify(complexMultihostOptions)})\`\n\nRESULT:`, JSON.stringify(complexMultihostURI), '\n')
//
// 'foo://m+4.gTe~5e^(:m+4.gTe~5e^(@ds143144-a0.mlab.com:43144,ds143144-a1.mlab.com:43145/bar-baz'
//

// NOTE: see tests for more advanced examples, e.g. the library handles absolute and relative URIs, etc.

Test

Clone down source code:

$ make install

Run colorful tests using jest:

$ make test

Related

About

This project was mainly initiated - in lack of solid existing alternatives - to be used at our work at Markable.ai to have common code conventions between various programming environments where Node.js (for I/O heavy operations) is heavily used.

License

Released under the MIT license.