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

urlapi

v1.0.4

Published

Url api for serialize from object to string and parse string to object

Downloads

239

Readme

Urlapi

This module contains methods for working with url:

  • serialize from object to string (serialize({ }));
  • parse string to object (parse(' ')).

Good abilities for working with queries and authentication in object types.

Installation

In your cmd/terminal

npm install urlapi

then add module to your project

var urlapi = require('urlapi');

or for ES2015 use

import * as urlapi from 'urlapi';

urlapi.serialize({ })

Takes object with next attributes and return string

  • protocol: protocol with or without colon-slash-slash, colon (example: http, http://, mailto:) - string;
  • auth: authentication data (example: user:password, { login: 'user', password: 'password'}) - string or object;
  • host: hostname and port if exist (example: site_name.com:3333, site_name.com, localhost) - string;
  • hostname: hostname (example: site_name.com) - string;
  • port: port (example: 3333) - string or number;
  • path: full path with search and queries (with or without leading slash) (example: path/inner/page?ref=1&close=false) - string;
  • pathname: path without search and queries (with or without leading slash) (example: path/inner/page) - string;
  • search: part of path with leading question mark (with or without question mark) (example: ?ref=1&close=false) - string;
  • query: part of path with parameters (example: ref=1&close=false, {ref: '1', close: 'false'}) - string or object;
  • hash: part of url with pound-sign (with or without pound-sign) (example: #g=where&a=find, {g: 'where', a: 'find'}) - string or object;

Additionaly:

  • None attribute is required but add to object protocol and host is good idea.
  • If host exist hostname and port will not touch.
  • If path exist pathname, search, query will not touch.

Example

import * as urlapi from 'urlapi';

let preparedObject = {
    protocol: 'http',
    auth: {
        login : 'user',
        password: 'password'
    },
    host: 'site_name.com:3333',
    hostname: 'site_name.com',
    port: 3333,
    path: 'path/inner/page?ref=1&close=false',
    pathname: 'path/inner/page',
    search: '?ref=1&close=false',
    query: {
        ref: '1',
        close: 'false'
    },
    hash: {
        g: 'where',
        a: 'find'
    }
};

console.log(urlapi.serialize(preparedObject)); 

return --> 

http://user:password@site_name.com:3333/path/inner/page?ref=1&close=false#g=where&a=find

urlapi.parse(' ')

Takes string and return object

Additionaly:

  • None attribute is required but add to object protocol and host is good idea.

Example

import * as urlapi from 'urlapi';

let stringParse = 'http://user:password@site_name.com:3333/path/inner/page?ref=1&close=false#g=where&a=find';

console.log(urlapi.parse(stringParse));

return -->

{
    protocol: 'http',
    auth: {
        login : 'user',
        password: 'password'
    },
    host: 'site_name.com:3333',
    hostname: 'site_name.com',
    port: 3333,
    path: 'path/inner/page?ref=1&close=false',
    pathname: 'path/inner/page',
    search: '?ref=1&close=false',
    query: {
        ref: '1',
        close: 'false'
    },
    hash: {
        g: 'where',
        a: 'find'
    }
}

Finally

You can find this documentation and a little bit more (example project with es2015 original code, tests and etc.) on GitHub.