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'}

Package Sidebar

Install

npm i j2url

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

3.94 kB

Total Files

3

Last publish

Collaborators

  • xujiayihaoren1