{"id":37681535,"url":"https://github.com/panoscool/qs-ts","last_synced_at":"2026-02-02T09:49:31.374Z","repository":{"id":332514187,"uuid":"1133760216","full_name":"panoscool/qs-ts","owner":"panoscool","description":null,"archived":false,"fork":false,"pushed_at":"2026-01-30T06:00:59.000Z","size":62,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-30T21:54:18.921Z","etag":null,"topics":[],"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/panoscool.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-13T19:30:24.000Z","updated_at":"2026-01-30T06:01:02.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/panoscool/qs-ts","commit_stats":null,"previous_names":["panoscool/qs-ts"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/panoscool/qs-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panoscool%2Fqs-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panoscool%2Fqs-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panoscool%2Fqs-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panoscool%2Fqs-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/panoscool","download_url":"https://codeload.github.com/panoscool/qs-ts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panoscool%2Fqs-ts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29009633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T08:40:12.472Z","status":"ssl_error","status_checked_at":"2026-02-02T08:40:10.926Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2026-01-16T12:25:28.837Z","updated_at":"2026-02-02T09:49:31.368Z","avatar_url":"https://github.com/panoscool.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# qs-ts\n\nA TypeScript library for parsing and stringifying URL query strings, inspired by the popular 'query-string' library. It provides robust handling of arrays, type inference, and encoding options.\n\n## Features\n\n- **Type Inference**: Automatically converts `\"true\"`/`\"false\"` to booleans, numeric strings to numbers, `\"null\"` to null\n- **Array Formats**: Support for `repeat` (key=a\u0026key=b) and `comma` (key=a,b) with configurable encoding\n- **Flexible Options**: Configurable encoding/decoding, null handling, array formatting\n- **TypeScript Support**: Full type definitions included\n- **Safe Parsing**: Handles malformed encodings gracefully\n- **Dual Package**: ESM and CommonJS support\n\n## Installation\n\n```bash\nnpm install qs-ts\n# or\nbun add qs-ts\n```\n\n## Usage\n\n### Basic Parsing\n\n```typescript\nimport { parse } from 'qs-ts';\n\nconst result = parse('a=1\u0026b=hello\u0026c=true');\nconsole.log(result);\n// { a: 1, b: 'hello', c: true }\n```\n\n### Basic Stringifying\n\n```typescript\nimport { stringify } from 'qs-ts';\n\nconst query = stringify({ a: 1, b: 'hello', c: true });\nconsole.log(query);\n// 'a=1\u0026b=hello\u0026c=true'\n```\n\n### CommonJS\n\n```javascript\nconst { parse, stringify } = require('qs-ts');\n```\n\n## API\n\n### parse(query: string, options?: ParseOptions): Record\u003cstring, any\u003e\n\nParses a query string into an object.\n\n#### Options\n\n- `decode?: boolean` (default: `true`) - Whether to decode percent-encoded characters\n- `inferTypes?: boolean` (default: `false`) - Whether to infer types for values\n- `array?: ArrayFormat` (default: `{ format: 'repeat' }`) - How arrays are represented\n- `types?: Record\u003cstring, ValueType\u003e` - Explicit type casting\n\n**ArrayFormat Definition:**\n```typescript\ntype ArrayFormat =\n  | { format: \"repeat\" }\n  | { format: \"comma\"; encoded: \"preserve\" | \"split\" };\n```\n\n\u003e [IMPORTANT]\n\u003e Comma-separated arrays depend on delimiter consistency. If values may be URL-encoded or come from external sources, **repeat is safer and more predictable**.\n\n- `encoded: \"preserve\"` splits on literal `,` only; `%2C` is treated as data.\n- `encoded: \"split\"` splits on literal `,` and on `%2C`/`%2c` so results don’t depend on upstream encoding.\n\n#### Examples\n\n##### Type Inference\n\n```typescript\nparse('a=1\u0026b=true\u0026c=null', { inferTypes: true });\n// { a: 1, b: true, c: null }\n\nparse('d=hello\u0026e=001\u0026f=12.5', { inferTypes: true });\n// { d: 'hello', e: 1, f: 12.5 }\n```\n\n##### Array Formats\n\n```typescript\n// Repeat (default)\nparse('tags=a\u0026tags=b');\n// { tags: ['a', 'b'] }\n\n// Comma (Preserve encoded commas)\nparse('tags=a,b%2Cc', { array: { format: 'comma', encoded: 'preserve' } });\n// { tags: ['a', 'b,c'] }\n\n// Comma (Split encoded commas)\nparse('tags=a,b%2Cc', { array: { format: 'comma', encoded: 'split' } });\n// { tags: ['a', 'b', 'c'] }\n```\n\n##### Explicit Types\n\n```typescript\nparse('count=5\u0026flags=on\u0026items=a\u0026items=b', {\n  inferTypes: true,\n  types: { count: 'string', flags: 'boolean', items: 'string[]' }\n});\n// { count: '5', flags: true, items: ['a', 'b'] }\n```\n\n##### Decoding Control\n\n```typescript\nparse('q=hello%20world', { decode: true });\n// { q: 'hello world' }\n\nparse('q=hello%20world', { decode: false });\n// { q: 'hello%20world' }\n```\n\n### stringify(object: Record\u003cstring, any\u003e, options?: StringifyOptions): string\n\nSerializes an object into a query string.\n\n#### Options\n\n- `encode?: boolean` (default: `true`) - Whether to encode special characters\n- `array?: ArrayFormat` (default: `{ format: 'repeat' }`) - How arrays are serialized\n- `skipNull?: boolean` (default: `false`) - Whether to skip null values\n- `skipEmptyString?: boolean` (default: `false`) - Whether to skip empty strings\n\n#### Examples\n\n##### Basic Usage\n\n```typescript\nstringify({ a: 1, b: 'hello', c: true });\n// 'a=1\u0026b=hello\u0026c=true'\n```\n\n##### Array Formats\n\n```typescript\n// Repeat (default)\nstringify({ tags: ['a', 'b', 'c'] });\n// 'tags=a\u0026tags=b\u0026tags=c'\n\n// Comma\nstringify({ tags: ['a', 'b', 'c'] }, { array: { format: 'comma', encoded: 'preserve' } });\n// 'tags=a,b,c'\n```\n\n##### Skipping Values\n\n```typescript\nstringify({ a: 1, b: null, c: '', d: undefined }, { skipNull: true, skipEmptyString: true });\n// 'a=1'\n\nstringify({ a: 1, b: null }, { skipNull: false });\n// 'a=1\u0026b'\n```\n\n##### Encoding Control\n\n```typescript\nstringify({ q: 'hello world' }, { encode: true });\n// 'q=hello%20world'\n\nstringify({ q: 'hello world' }, { encode: false });\n// 'q=hello world'\n```\n\n## Advanced Examples\n\n### Complex Objects\n\n**Note:** Nested objects are not supported. They are converted to their string representation.\n\n```typescript\nconst obj = {\n  user: 'john',\n  age: 30,\n  active: true,\n  tags: ['developer', 'typescript'],\n  metadata: {\n    created: '2025-01-01'  // This nested object will become '[object Object]'\n  }\n};\n\nconst query = stringify(obj, { array: { format: 'repeat' } });\nconsole.log(query);\n// 'user=john\u0026age=30\u0026active=true\u0026tags=developer\u0026tags=typescript\u0026metadata=%5Bobject%20Object%5D'\n\nconst parsed = parse(query, { inferTypes: true, array: { format: 'repeat' } });\nconsole.log(parsed);\n// { user: 'john', age: 30, active: true, tags: ['developer', 'typescript'], metadata: '[object Object]' }\n```\n\n### URL Integration\n\n```typescript\n// Parse from URL with repeat format (default)\nconst url2 = new URL('https://example.com/search?q=typescript\u0026tags=web\u0026tags=api\u0026limit=10');\nconst params2 = parse(url2.search.slice(1), { inferTypes: true, array: { format: 'repeat' } });\nconsole.log(params2);\n// { q: 'typescript', tags: ['web', 'api'], limit: 10 }\n\n// Parse from URL with comma format\nconst url3 = new URL('https://example.com/search?q=typescript\u0026tags=web,api\u0026limit=10');\nconst params3 = parse(url3.search.slice(1), { inferTypes: true, array: { format: 'comma', encoded: 'preserve' } });\nconsole.log(params3);\n// { q: 'typescript', tags: ['web', 'api'], limit: 10 }\n\n// Build URL\nconst baseUrl = 'https://example.com/search';\nconst queryString = stringify({ q: 'javascript', sort: 'recent' });\nconst fullUrl = `${baseUrl}?${queryString}`;\nconsole.log(fullUrl);\n// 'https://example.com/search?q=javascript\u0026sort=recent'\n```\n\n## Development\n\n### Building\n\n```bash\nbun run build\n```\n\n### Testing\n\n```bash\nbun test\n```\n\n### Verification\n\n```bash\nnode verify.mjs\n# or\nbun verify.mjs\n```\n\n## License\n\nMIT - see [LICENSE](LICENSE)\u003c/content\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanoscool%2Fqs-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpanoscool%2Fqs-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanoscool%2Fqs-ts/lists"}