A tool that lets you manipulate urls at will
npm:
npm install j2url
yarn:
yarn add j2url
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'}