query-string-manipulator
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "query-string-manipulator", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Manipulate query strings without effort", | ||
"main": "dist/qsm.js", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"prepublish": "npm test && npm run build", | ||
"pretest": "eslint lib", | ||
"build": "npm run build:regular && npm run build:minified", | ||
"build:regular": "babel lib -d dist", | ||
"build:minified": "babel --minified lib/qsm.js | uglifyjs --mangle --compress -o dist/qsm.minified.js", | ||
"test": "npm run test:coverage", | ||
"test:nocov": "mocha --require babel-core/register", | ||
"test:coverage": "babel-node node_modules/babel-istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha --report clover --report lcov --report html -- --recursive --require ./lib/qsm.js" | ||
"build": "babel -d lib src --ignore *test*", | ||
"clean": "rimraf lib", | ||
"prepack": "npm run clean && npm test && npm run build", | ||
"pretest": "eslint src", | ||
"test": "jest" | ||
}, | ||
@@ -35,3 +32,3 @@ "repository": { | ||
"files": [ | ||
"dist", | ||
"lib", | ||
"LICENSE", | ||
@@ -46,14 +43,12 @@ "README.md" | ||
"babel-preset-es2015": "^6.24.1", | ||
"chai": "^4.1.2", | ||
"eslint": "^4.15.0", | ||
"eslint-config-airbnb": "^16.1.0", | ||
"eslint-plugin-filenames": "^1.2.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-jest": "^21.12.2", | ||
"eslint-plugin-jsx-a11y": "^6.0.3", | ||
"eslint-plugin-mocha": "^4.11.0", | ||
"eslint-plugin-react": "^7.5.1", | ||
"mocha": "^4.1.0", | ||
"uglify": "^0.1.5", | ||
"uglify-js": "^3.3.5" | ||
"eslint-plugin-react": "^7.7.0", | ||
"jest": "^22.4.2" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -88,4 +88,6 @@ # Query String Manipulator | ||
If you like "symbols", you can go like this: | ||
```javascript | ||
import { | ||
import qsm, { | ||
URL_REMOVE, // Used for remove | ||
@@ -95,2 +97,95 @@ URL_SET, // Used for set | ||
} from 'query-string-manipulator'; | ||
qsm('http://example.com/', { | ||
[URL_REMOVE]: ['test'], | ||
[URL_TOGGLE]: [ | ||
{ | ||
key: 'foo', | ||
value: 'bar', | ||
}, | ||
], | ||
[URL_SET]: [ | ||
{ | ||
key: 'xxx', | ||
value: '123', | ||
}, | ||
] | ||
}) | ||
``` | ||
### Support methods | ||
But wait, there is more! | ||
#### Getting URL params | ||
Method `getUrlParams` returns list of all parameters in form of array of objects. It cannot be returned in form of key-pair values because there can be multiple same name query params. | ||
```javascript | ||
getUrlParams('https://example.com/foo?select=users&getId=10') | ||
/* returns | ||
[ | ||
{ | ||
key: 'select', | ||
value: 'users' | ||
}, | ||
{ | ||
key: 'getId', | ||
value: '10', | ||
} | ||
] | ||
*/ | ||
``` | ||
#### Resolve URL params | ||
Method `resolveUrlParams` returns parameters after changed by user specified actions. | ||
```javascript | ||
const urlParams = [ | ||
{ | ||
key: 'select', | ||
value: 'users' | ||
}, | ||
{ | ||
key: 'getId', | ||
value: '10' | ||
} | ||
]; | ||
const paramActions = { | ||
remove: ['getId'], | ||
set: { | ||
select: 'userGroups', | ||
}, | ||
}; | ||
resolveUrlParams(urlParams, paramActions) | ||
/* returns | ||
[ | ||
{ | ||
key: 'select', | ||
value: 'userGroups' | ||
} | ||
] | ||
*/ | ||
``` | ||
#### Putting params together | ||
Method `constructUrlParams` returns query string part of the URL from parameters. | ||
```javascript | ||
constructUrlParams([ | ||
{ | ||
key: 'select', | ||
value: 'users' | ||
}, | ||
{ | ||
key: 'getId', | ||
value: '10' | ||
} | ||
]) | ||
// returns "select=users&getId=10" | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12
97
190
10184
4