New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

url2obj

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url2obj

It will take a URL and the object keys as arguments and convert it to an object. It support query params by using the names as obj keys.

latest
Source
npmnpm
Version
0.1.6
Version published
Maintainers
1
Created
Source

NPM version Build Status Dependency Status

URL2OBJ

It will take a URL and the object keys as arguments and convert it to an object. You can pass an array of keys or just a string with the url format. It support query params by using the names as obj keys.

url2obj( url, object keys, omit certain keys );
url2obj( url, format url string);

Install

$ npm install --save url2obj

Usage

first argument is the url that you want to convert, then you can pass an array of keys and then an array of the keys that you want to omit on your obj

var url2obj = require('url2obj');

var obj1 = url2obj( '/4/api/users/2', ['version', 'api', 'collection', 'id'], ['api'] );


// This will return an object like this:
{
  version: "4",
  collection: "users",
  id: "2"
}

var obj2 = url2obj( '/4/api/users/2?sort=desc&limit=10', ['version', 'api', 'collection', 'id'], ['api'] );


// If you have query params on your url it will use the names as keys:
{
  version: "4",
  collection: "users",
  id: "2",
  sort: "desc",
  limit: "10"
}

you have the option to pass only two arguments being the first one the url and the second one the format of your url, it will take the dynamic params as keys and omit the non dynamic ones.

var url2obj = require('url2obj');

var obj1 = url2obj( '/6/api/listings/3', "/:version/api/:collection/:id" );


// This will return an object like this:
{
  version: "4",
  collection: "users",
  id: "2"
}

var obj2 = url2obj( '/6/api/listings/3?sort=desc&limit=10', "/:version/api/:collection/:id" );


// If you have query params on your url it will use the names as keys:
{
  version: "4",
  collection: "users",
  id: "2",
  sort: "desc",
  limit: "10"
}
# creates a browser.js
$ npm run browser

License

MIT © Sebastian Baroni

Keywords

url2obj

FAQs

Package last updated on 31 May 2015

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