You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

urlapi

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urlapi

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

1.0.0
Source
npmnpm
Version published
Weekly downloads
42
-26.32%
Maintainers
1
Weekly downloads
 
Created
Source

#Urlapi#

This module contains methods for working with url:

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

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

FAQs

Package last updated on 02 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.