{"id":23814428,"url":"https://github.com/stuartpb/loquate","last_synced_at":"2025-07-23T04:05:17.505Z","repository":{"id":7492413,"uuid":"8841556","full_name":"stuartpb/loquate","owner":"stuartpb","description":"Add a location.query map without breaking a sweat","archived":false,"fork":false,"pushed_at":"2016-08-22T20:27:07.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-21T20:17:18.497Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stuartpb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-17T21:02:40.000Z","updated_at":"2019-07-26T10:30:16.000Z","dependencies_parsed_at":"2022-09-02T02:51:25.808Z","dependency_job_id":null,"html_url":"https://github.com/stuartpb/loquate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stuartpb/loquate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuartpb%2Floquate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuartpb%2Floquate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuartpb%2Floquate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuartpb%2Floquate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stuartpb","download_url":"https://codeload.github.com/stuartpb/loquate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stuartpb%2Floquate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266614366,"owners_count":23956357,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-02T03:47:33.504Z","updated_at":"2025-07-23T04:05:17.479Z","avatar_url":"https://github.com/stuartpb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"loquate\n=======\n\nLoquate is a JavaScript library for the wide, wide world of making an object\nfrom a query string.\n\n## Usage\n\nBy default, Loquate adds a `query` property to `location` based on\n`location.search`, so if you don't need anything fancier than plain old\n`?shana=na+na\u0026bat=ba%2fna%2fna` pair handling, you can just use\n`location.query` right after including `loquate.js`,\n[like so](http://stuartpb.github.io/loquate/example.html):\n\n```html\n\u003cscript src=\"loquate.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\nif(!location.query){ //if there's no query string on the URL\n  document.write('\u003cform method=\"GET\"\u003e\u003cinput name=\"name\" value=\"Stuart\"\u003e'+\n    '\u003cinput name=\"hairInches\" value=\"1.2\"\u003e inches'+\n    '\u003cinput type=\"submit\" value=\"I need some hair advice\"\u003e\u003c/form\u003e');\n} else {\n  document.write('\u003ch1\u003eShould I, '\n    + (location.query.name || \"Anonymous\") + ', cut my hair?\u003c/h1\u003e');\n  if(location.query.hairInches == 0)\n    document.write(\"\u003cp\u003eWhat hair?\u003c/p\u003e\");\n  else if(location.query.hairInches \u003c 80)\n    document.write(\"\u003cp\u003eAsk a hairdresser\u003c/p\u003e\");\n  else if(location.query.hairInches \u003c 221.54)\n    document.write(\"\u003cp\u003eOnly if you like riding on escalators\u003c/p\u003e\");\n  else document.write(\"\u003cp\u003eNot now, you're setting the world record!\u003c/p\u003e\");\n}\u003c/script\u003e\n```\n\nIf you want anything more complex than that, you can get a new object by\ncalling the Loquate method with your desired options (see below). If you want\nto use Loquate's default string decoder (which converts plusses to spaces and\nnormalizes all whitespace on top of doing decodeURIComponent), you can\nconstruct an instance of it with `Loquate.decode({newline: newline})`, where\n`newline` is the string to normalize newlines to (or a defined falsy value to\nleave all CR/LF/CRLF instances as they are).\n\n```js\n//We keep our options in a hashbang with JSON-esque syntax\nvar hashoptions = Loquate(location.hash.slice(2),{\n    sep: ',', eq: ':', decode: function(str){\n    return Loquate.decoder()(str).replace(/^\\s*\"|\"\\s*$/g,'')}})\n```\n\n## Options\n\nYou can override pretty much any constant behavior on Loquate with options:\n\n- **sep**: The string or regex to match when splitting the query string into\n  pairs. Defaults to `/[\u0026;]/g`, [per W3C recommendation][1].\n- **eq**: The string or regex to match when splitting a pair into key and value.\n  Defaults to `'='`.\n- **decode**: The filter to apply to keys and values. Defaults to\n  `Loquate.decode(opts)`. This means you can modify the default decoder\n  constructor for all later `Loquate` calls by assigning to `Loquate.decode`.\n  - **newline**: Used by the default decoder as the sequence to normalize\n    newlines to. Defaults to `'\\n'`.\n- **onbool**: The behavior to use when encountering elements without pair\n  separators (eg. `?keybyitself\u0026anotherlonelykey`). If unrecognized, treats the\n  element as a key and assigns it the value of **boolval**.\n  - `'undefined'`: Assign the key to the value of `undefined`. (This is\n    controlled by **onbool** because setting **boolval** to `undefined` will\n    cause it to use the default value.\n  - `'ignore'`: Ignore completely.\n  - `'both'`: Assign the key at the name of the element to the value of the\n    element.\n  - `'value'` Assign the value of the element to the key named in **boolval**.\n    (If multiple values are present in this fashion, they will be assigned to\n    the key accoring to the behavior specified in **multival**.)\n- **boolval**: In the absence of a recognized value for **onbool**, the value\n  to assign to keys without specified values. Defaults to `true` if `boolval`\n  is `undefined`.\n- **multival**: Which behavior to use when encountering the same key multiple\n    times.\n    - `'first'`: Only use the dirst definition of the value.\n    - `'last'`: Only use the last definition of the value.\n    - `'always'`: Use an array for every value, defined multiple times or not.\n      - This allows for closer matching of Python's behavior.\n\n[1]: http://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.2.2\n\n## Compatiblity\n\nQuery string handling is surprisingly ill-defined, and different environments\nhave different behaviors. Here are the options to match the behavior of other\nquerystring parsing implementations.\n\n### Node querystring module\n```js\n{ sep: '\u0026',\n  boolval: '' }\n```\n\n### Python (urlparse/urllib.parse).parse_qs\n```js\n{ sep: '\u0026',\n  onbool: 'ignore', //omit this line for keep_blank_values = True behavior\n  boolval: '',\n  multival: 'always' }\n```\n\n## FAQ\n\n### Extending the DOM offends my delicate sensibilities.\n\nLoquate only adds `location.query` if it's definitely not going to block access\nto anything. If you can't tolerate its existence, you can delete it right after\nincluding the script:\n\n```html\n\u003cscript src=\"//stuartpb.github.io/loquate/loquate.js\"\u003e\u003c/script\u003e\n\u003cscript\u003eif(location.query) delete location.query;\u003c/script\u003e\n```\n\nIf your whole site is programmed to set off alarm bells whenever anything is\nassigned to DOM objects, make your own local copy of the script and delete the\nlast ten lines.\n\n## Roadmap\n\n- Add options:\n  - **subindex**: A pattern (applied before decoding) for matching subindexing\n    elements in keys. If `true`, defaults to `/\\[([^\\]*)\\]/g`.\n  - **dot**: A pattern (applied before decoding) for separating subindexing\n    elements in keys. If true, defaults to `'.'`.\n- Evaluate other querystring implementations and maybe change the defaults to\n  match the most common cases.\n- Make the `Loquate()` interface at least come close to following normal\n  JavaScript object conventions.\n  - At least extend all options to work something like how `decode` does.\n  - Maybe either make `Loquate` a proper constructor or decapitalize the name.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstuartpb%2Floquate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstuartpb%2Floquate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstuartpb%2Floquate/lists"}