{"id":18926820,"url":"https://github.com/ladjs/preserve-qs","last_synced_at":"2026-04-11T03:34:13.199Z","repository":{"id":42373025,"uuid":"118029673","full_name":"ladjs/preserve-qs","owner":"ladjs","description":"Preserve querystrings during redirect and creating new URLs for Node.js and browser environments (supports Lad, Koa, Express, and Connect)","archived":false,"fork":false,"pushed_at":"2022-04-08T15:39:03.000Z","size":91,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-04T09:55:44.970Z","etag":null,"topics":["browser","connect","express","javascript","koa","lad","merge","node","preserve","querystring","redirect","redirection","request","url","window"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ladjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-18T19:42:56.000Z","updated_at":"2022-03-17T19:22:12.000Z","dependencies_parsed_at":"2022-08-28T21:21:45.880Z","dependency_job_id":null,"html_url":"https://github.com/ladjs/preserve-qs","commit_stats":null,"previous_names":["niftylettuce/preserve-qs"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ladjs/preserve-qs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fpreserve-qs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fpreserve-qs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fpreserve-qs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fpreserve-qs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ladjs","download_url":"https://codeload.github.com/ladjs/preserve-qs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fpreserve-qs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31668049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T17:19:37.612Z","status":"online","status_checked_at":"2026-04-11T02:00:05.776Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["browser","connect","express","javascript","koa","lad","merge","node","preserve","querystring","redirect","redirection","request","url","window"],"created_at":"2024-11-08T11:17:15.401Z","updated_at":"2026-04-11T03:34:13.179Z","avatar_url":"https://github.com/ladjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# preserve-qs\n\n[![build status](https://img.shields.io/travis/niftylettuce/preserve-qs.svg)](https://travis-ci.org/niftylettuce/preserve-qs)\n[![code coverage](https://img.shields.io/codecov/c/github/niftylettuce/preserve-qs.svg)](https://codecov.io/gh/niftylettuce/preserve-qs)\n[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org)\n[![license](https://img.shields.io/github/license/niftylettuce/preserve-qs.svg)](LICENSE)\n\n\u003e Preserve querystrings during redirect and creating new URLs for [Node.js][node] and browser environments (supports [Lad][], [Koa][], [Express][], and [Connect][])\n\n\n## Table of Contents\n\n* [Install](#install)\n* [Usage](#usage)\n  * [Custom](#custom)\n  * [Browser](#browser)\n  * [Koa](#koa)\n  * [Express](#express)\n* [Override Properties](#override-properties)\n* [Blacklist Properties](#blacklist-properties)\n* [Contributors](#contributors)\n* [License](#license)\n\n\n## Install\n\n[npm][]:\n\n```sh\nnpm install preserve-qs\n```\n\n[yarn][]:\n\n```sh\nyarn add preserve-qs\n```\n\n\n## Usage\n\nImagine that we have the URL `/foo/bar?beep=boop\u0026limit=25` and we wish to redirect the user (or simply output) a new URL with pathname of `/foo/baz` – but also preserve the original querystring.\n\nThe examples below show how this package can be used for this, regardless of the environment being run in.\n\nWe assume you have imported the package in all these examples:\n\n```js\nconst preserveQs = require('preserve-qs');\n```\n\n### Custom\n\n```js\npreserveQs('/foo/bar?beep=boop\u0026limit=25', '/foo/baz');\n```\n\n### Browser\n\nThis uses `window.location.pathname` and `window.location.search`.\n\n```js\npreserveQs(window, '/foo/baz');\n```\n\n### Koa\n\nThis uses `ctx.request.originalUrl`.\n\n```js\npreserveQs(ctx, '/foo/baz');\n\n// ctx.redirect(preserveQs(ctx, '/foo/baz'));\n```\n\n### Express\n\nThis uses `req.originalUrl`.\n\n```js\npreserveQs(req, '/foo/baz');\n\n// res.redirect(preserveQs(req, '/foo/baz'));\n```\n\n\n## Override Properties\n\nIf you wish to override a property in the querystring, either from the original or the new URL, then you can pass a third argument of an object.\n\n```js\npreserveQs(req, '/foo/baz?hello=false', { hello: true });\n```\n\nIn the example above, the output would have the `?hello=false` be overriden and become `?hello=true`.\n\n\n## Blacklist Properties\n\nIf you wish to completely strip a single property or multiple from being included in the querystring then pass it as the third or fourth argument.\n\n```js\npreserveQs(req, '/foo/baz', [ 'page', 'limit' ]);\n```\n\nThis would strip the `page` and `limit` from the URL (e.g. it would not have `?page=1\u0026limit=10` in the URL).\n\nYou can also combine this with the `override` argument by invoking in order as `preserveQs(req, url, override, blacklist)`.\n\n\n## Contributors\n\n| Name           | Website                    |\n| -------------- | -------------------------- |\n| **Nick Baugh** | \u003chttp://niftylettuce.com/\u003e |\n\n\n## License\n\n[MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com/)\n\n\n## \n\n[npm]: https://www.npmjs.com/\n\n[yarn]: https://yarnpkg.com/\n\n[node]: https://nodejs.org/\n\n[lad]: https://lad.js.org/\n\n[koa]: http://koajs.com/\n\n[express]: https://expressjs.com/\n\n[connect]: https://github.com/senchalabs/connect\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fpreserve-qs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladjs%2Fpreserve-qs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fpreserve-qs/lists"}