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

compositional-url

v1.0.0

Published

URL library with emphasis on composition / resolution between urls

Downloads

7

Readme

A URL library written to abstract protocol and non-protocol (base) URLs in a generic manner.

Resolution table

|Start URL Type|Resolution URL Type|Result Type| |---|---|---| |Protocol|Protocol Relative|Protocol| |Protocol Relative|Protocol|Protocol| |Base|Protocol|ERROR| |Base|Protocol Relative|ERROR| |Protocol Relative|Base|Protocol Relative| |Protocol|Base|Protocol| |Protocol|Protocol|Protocol| |Protocol Relative|Protocol Relative|Protocol Relative| |Base|Base|Base|

Usecase: reduce pathname to safer form

// create a new url
// first normalize the url (combine . and .. parts)
// second remove . and .. prefixes 
// shorthand for url.withPathname(url.pathname.normalize().base());
url.withPathname(url.pathname.safer());

ComposableURL

Container type for all the parts of a URL. It has a lossless .toString function which is used for safe combinations of URLs via .resolve(otherURL). The properties of this type are compatible with url.parse from node's standard library. By default the .toString will not include the auth information to help avoid leaks, use .toString(true) to show the auth information as well.

Has the properties:

String   .protocol
URLAuth  .auth
String   .hostname
Number   .port
URLPath  .pathname
URLQuery .search
String   .hash
Boolean  .isProtocolRelative // computed from other properties

Has the methods:

ComposableURL .withProtocol(String protocol);
ComposableURL .withAuth(URLAuth auth);
ComposableURL .withHostname(String hostname);
ComposableURL .withPort(Number port);
ComposableURL .withPathname(Number port);
ComposableURL .withPathname([String,URLPathname] path);
ComposableURL .withSearch([String,URLSearch] search);
ComposableURL .withHash(String hash);
String        .toString(Boolean showAuth);

Example:

const URL= require('compositional-url').URL;
const url = new URL('google.com');
// change the protocol since it is protocol relative
require('https').request(url.resolve('https:'));
require('http').request(url.resolve('http:'));

URLAuth

Simple container for user and secret parts of a URL. .toString will show the values of this if called against this type directly.

const URL= require('compositional-url').URL;
const URLAuth = require('compositional-url').URLAuth;
const url = new URL('google.com');
require('https').request(url.withAuth(new URLAuth('user','secret')));

Has the properties:

String .user
String .secret

Has the methods:

Boolean .empty();

URLPathname

Simple structure to lazily construct url paths as needed. This will attempt to put off combining path components as much as possible. It also will not normalize by default so . and .. will stay preserved unless normalization is explicitly requested.

const URL= require('compositional-url').URL;
const URLPathname = require('compositional-url').URLPathname;
const url = new URL('google.com');
require('https').request(url.withPathname(new URLPathname('.','..','..','f')));

Has the methods:

Boolean     .empty();
URLPathname .concat(String... components);
*String     .entries();
String      .raw();

// combines `.` and `..`s as possible while keeping the pathname
// base, relative, or absolute
String .normalize();

// removes any relative prefixing (`.`s and/or `..`s) from
// beginning of the pathname.
String .base();

URLSearch

Structure to allow lossless url search parameters. This allows for duplicate keys etc.

const URL= require('compositional-url').URL;
const URLSearch = require('compositional-url').URLSearch;
const url = new URL('google.com');
require('https').request(url.withSearch(new URLSearch('?a=b&a=c')));

Has the methods:

Boolean                     .empty();
URLSearch                   .concat({String key,String value} entry);
*{String key, String value} .entries();