├── .gitignore ├── .npmignore ├── .prettierrc ├── README.md ├── package-lock.json ├── package.json └── src └── urlqueryobject.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /dist -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | .prettierrc 3 | .gitignore -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "singleQuote": true, 4 | "printWidth": 100, 5 | "tabWidth": 2 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # urlqueryobject 2 | 3 | A 180 byte (gzip) utility to get the current url query params as object. 4 | 5 | ## Install 6 | 7 | `npm i urlqueryobject` 8 | 9 | ## Example 10 | 11 | Url: `https://example.com?foo=baz&something=more` 12 | 13 | ``` 14 | import urlqueryobject from 'urlqueryobject'; 15 | 16 | const params = urlqueryobject(); 17 | 18 | console.log(params); 19 | 20 | { 21 | foo: 'baz', 22 | something: 'more', 23 | } 24 | 25 | ``` 26 | 27 | # License 28 | 29 | [MIT](https://oss.ninja/mit/mjanssen/) 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "urlqueryobject", 3 | "version": "0.0.4", 4 | "description": "A 180 byte (gzip) utility to get the current url query params as object.", 5 | "source": "src/urlqueryobject.js", 6 | "main": "dist/urlqueryobject.js", 7 | "module": "dist/urlqueryobject.module.js", 8 | "unpkg": "dist/urlqueryobject.umd.js", 9 | "scripts": { 10 | "prepublish": "microbundle", 11 | "build": "microbundle", 12 | "dev": "microbundle watch" 13 | }, 14 | "author": "", 15 | "license": "ISC", 16 | "devDependencies": { 17 | "microbundle": "^0.11.0" 18 | } 19 | } -------------------------------------------------------------------------------- /src/urlqueryobject.js: -------------------------------------------------------------------------------- 1 | export default function getUrlQueryData() { 2 | if (typeof window === 'undefined') return {}; 3 | const queryData = window.location.search.replace(/^\?/, '').split('&'); 4 | const d = {}; 5 | if (queryData) { 6 | queryData.forEach((k) => { 7 | const [key, value] = k.split('='); 8 | d[key] = value; 9 | }); 10 | } 11 | 12 | return d; 13 | } 14 | --------------------------------------------------------------------------------