Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hogart/location-search-parser
SearchParser is very simple utility for parsing and manipulating window.location.string
https://github.com/hogart/location-search-parser
Last synced: about 2 months ago
JSON representation
SearchParser is very simple utility for parsing and manipulating window.location.string
- Host: GitHub
- URL: https://github.com/hogart/location-search-parser
- Owner: hogart
- Created: 2013-02-26T09:12:42.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-02-26T09:40:48.000Z (almost 12 years ago)
- Last Synced: 2024-10-18T16:37:34.745Z (3 months ago)
- Language: JavaScript
- Size: 109 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
location-search-parser
======================SearchParser is very simple utility for parsing and manipulating `window.location.string`. Works with AMD and plain browser environment;
### Usage
```javascript
var parser = new SearchParser(window.location.search.substr(1)); // same as new SearchParser
parser.parsed; // {test: 'ok'}
parser.extend({a: 42, b: 38}).compile(); // 'a=42&b=38&test=ok', but actual order may differ
```### API
`SearchParser`
* `constructor(searchString)` — `searchString` defaults to `window.location.search.substr(1)`. Calls `SearchParser#parse`;
* `SearchParser#parse(searchString)` — parses `searchString` which has format of `'key1=val&key2=val2'`. Returns `Object` and can be used as static method;
* `SearchParser#parsed` — contains parsed parameters from `searchString`;
* `SearchParser#compile(params)` — `params` must be object. When called as instance method, `params` defaults to `this.parsed`. Returns `String` and can be used as static method;
* `SearchParser#extend(params)` — `params` must be object. Merges `params` and `this.parsed`.