{"id":15663880,"url":"https://github.com/kouhin/with-query","last_synced_at":"2025-05-05T21:46:49.156Z","repository":{"id":19198017,"uuid":"86480491","full_name":"kouhin/with-query","owner":"kouhin","description":"Format url with query (string or object), simple and fast, with the power of qs.","archived":false,"fork":false,"pushed_at":"2023-01-08T13:43:18.000Z","size":530,"stargazers_count":18,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-30T06:40:40.495Z","etag":null,"topics":["fetch","query","url"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/kouhin.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":"2017-03-28T16:05:24.000Z","updated_at":"2024-07-04T09:55:54.000Z","dependencies_parsed_at":"2023-01-13T21:00:41.374Z","dependency_job_id":null,"html_url":"https://github.com/kouhin/with-query","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kouhin%2Fwith-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kouhin%2Fwith-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kouhin%2Fwith-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kouhin%2Fwith-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kouhin","download_url":"https://codeload.github.com/kouhin/with-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252582477,"owners_count":21771669,"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","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":["fetch","query","url"],"created_at":"2024-10-03T13:40:17.253Z","updated_at":"2025-05-05T21:46:49.120Z","avatar_url":"https://github.com/kouhin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003ca href='https://github.com/kouhin/with-query'\u003e\u003cimg src='https://cloud.githubusercontent.com/assets/5006663/24417156/3d916d36-1422-11e7-85a4-ebd3d6620d46.png' height='60'\u003e\u003c/a\u003e\n\nFormat url with query (string or object), simple and fast, with the power of [qs](https://github.com/ljharb/qs).\n\nThe typical usage of this library is building URL for [Fetch API](https://fetch.spec.whatwg.org). It can be used both on server side and browser side.\n\n[![CircleCI](https://circleci.com/gh/kouhin/with-query/tree/master.svg?style=svg)](https://circleci.com/gh/kouhin/with-query/tree/master)\n[![Coverage Status](https://coveralls.io/repos/github/kouhin/with-query/badge.svg?branch=master)](https://coveralls.io/github/kouhin/with-query?branch=master)\n[![npm](https://img.shields.io/npm/v/with-query.svg)](https://www.npmjs.com/package/with-query)\n[![airbnb style](https://img.shields.io/badge/code_style-airbnb-blue.svg)](https://github.com/airbnb/javascript)\n\n``` javascript\nconst withQuery = require('with-query').default;\n\nfetch(withQuery('https://api.github.com/search/repositories', {\n  q: 'query',\n  sort: 'stars',\n  order: 'asc',\n}))\n.then(res =\u003e res.json())\n.then((json) =\u003e {\n  console.info(json);\n})\n.catch((err) =\u003e {\n  console.error(err);\n});\n```\n\n## Installation\n\n- npm\n\n``` shell\nnpm install with-query --save\n```\n\n- yarn\n\n``` shell\nyarn add with-query\n```\n\n## Usage\n\n``` javascript\nvar withQuery = require('with-query').default;\nvar assert = require('assert');\n\nconst result1 = withQuery('http://example.com', {\n  a: 1,\n  b: 'hello',\n});\nassert.equal(result1, 'http://example.com?a=1\u0026b=hello');\n\n// Append and override the query in url\nconst result2 = withQuery('http://example.com?a=3\u0026c=4\u0026d=5', {\n  a: 1,\n  b: 'hello',\n});\nassert.equal(result2, 'http://example.com?a=1\u0026c=4\u0026d=5\u0026b=hello');\n\n// Hash is also supported\nconst result3 = withQuery('http://example.com?a=3\u0026c=4\u0026d=5#Append', {\n  a: 1,\n  b: 'hello',\n});\nassert.equal(result3, 'http://example.com?a=1\u0026c=4\u0026d=5\u0026b=hello#Append');\n\n// Remove hash\nconst result4 = withQuery('http://example.com?a=3\u0026c=4\u0026d=5#Append', {\n  a: 1,\n  b: 'hello',\n}, { noHash: true });\nassert.equal(result4, 'http://example.com?a=1\u0026c=4\u0026d=5\u0026b=hello');\n\n// with the power of qs\nconst result5 = withQuery('http://example.com?e[]=f', {\n  a: {\n    b: 'c',\n  },\n});\nassert.equal(result5, 'http://example.com?e%5B0%5D=f\u0026a%5Bb%5D=c');\n\n// parseOpt and stringifyOpt for qs.parse and qs.stringify\n// see https://github.com/ljharb/qs\nconst result6 = withQuery('http://example.com\u0026e[]=f', {\n  a: {\n    b: 'c',\n  },\n}, {\n  stringifyOpt: {\n    encode: false,\n  },\n  parseOpt: {\n    parseArray: false,\n  },\n});\nassert.equal(result6, 'http://example.com\u0026e[]=f?a[b]=c');\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkouhin%2Fwith-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkouhin%2Fwith-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkouhin%2Fwith-query/lists"}