npm

Join us for the upcoming webinar, "Enterprise JavaScript done right: the tools you love, the security you need."Sign up here »

j2url

1.0.1 • Public • Published

j2url

A tool that lets you manipulate urls at will

install

npm:

npm install j2url

yarn:

yarn add j2url

Usage

You can get every params

j2url.getParam('https://www.google.com/?a=1', 'a') // => 1
j2url.getParam('https://www.google.com/?a[]=1&a[]=2', 'a') // => [1, 2]
j2url.getParam('https://www.google.com/?a={'b': 1}', 'a') // => {b: 1}

You can also set the param of the url , the last argument defaults to false, if you set it to true, you will get a encoding url

j2url.setParam('https://www.google.com/?a=1', 'a', 2) // => https://www.google.com/?a=2
j2url.setParam('https://www.google.com/?a=1&b=2', 'c', 3) // => https://www.google.com/?a=1&b=2&c=3
j2url.setParam('https://www.google.com/?a=1', 'a', 2, true) // => https%3A%2F%2Fwww.google.com%2F%3Fa%3D2

You can get the url's params to json

j2url.toJson('https://www.google.com/?a=1&b=2') // => {a: 1,b: 2}
j2url.toJson('https://www.google.com/?a={'name''bob'}&b[]=1&b[]=2') // => {a: {name: bob},b:[1, 2]}

You can add the json to url

j2url.toUrl('https://www.google.com/','a','{'name''Tom'}') // => https://www.google.com/?a={'name': 'Tom'}

install

npm i j2url

Downloadsweekly downloads

6

version

1.0.1

license

ISC

last publish

collaborators

  • avatar
Report a vulnerability