{"id":23635344,"url":"https://github.com/filefoxper/type-query-parser","last_synced_at":"2026-06-29T22:31:05.818Z","repository":{"id":128608054,"uuid":"268499160","full_name":"filefoxper/type-query-parser","owner":"filefoxper","description":null,"archived":false,"fork":false,"pushed_at":"2021-03-26T09:10:02.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-05T14:17:19.564Z","etag":null,"topics":["query-parser","template","types","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/filefoxper.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-01T11:09:35.000Z","updated_at":"2021-03-26T09:10:05.000Z","dependencies_parsed_at":"2023-06-26T01:16:47.272Z","dependency_job_id":null,"html_url":"https://github.com/filefoxper/type-query-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/filefoxper/type-query-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filefoxper%2Ftype-query-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filefoxper%2Ftype-query-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filefoxper%2Ftype-query-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filefoxper%2Ftype-query-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/filefoxper","download_url":"https://codeload.github.com/filefoxper/type-query-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filefoxper%2Ftype-query-parser/sbom","scorecard":{"id":399480,"data":{"date":"2025-08-11","repo":{"name":"github.com/filefoxper/type-query-parser","commit":"277464f9c546bd7d1e50e042b47863f941af820b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Code-Review","score":0,"reason":"Found 0/7 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-18T19:47:08.045Z","repository_id":128608054,"created_at":"2025-08-18T19:47:08.045Z","updated_at":"2025-08-18T19:47:08.045Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34945707,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"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":["query-parser","template","types","typescript"],"created_at":"2024-12-28T05:34:05.970Z","updated_at":"2026-06-29T22:31:05.790Z","avatar_url":"https://github.com/filefoxper.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[npm link](https://www.npmjs.com/package/type-query-parser) \u0026 [github link](https://github.com/filefoxper/type-query-parser)\n# problem\nWhen we parse a search from location, we often get an object like ```{[key: string]: string|string[]|undefined}```, \nbut we really want an object like ```{[key:string]:number|boolean|Date|string|string[]...} ``` which can describe more \ntypes about the values. Also we want to validate these values, if they are invalid we can replace them from an default.\n\n# resolve\nHere is a tool ```type-query-parser``` which can do something like transforming value type and replacing value which is invalid.\n It parses query with your template.\n\n# example (more in [test](https://github.com/filefoxper/type-query-parser/blob/master/test/index.test.ts))\nbasic usage\n```js\n    import {parse,Parsers} from 'type-query-parser';\n\n    const source = {\n        id: '123456',\n        name: 'jimmy ',\n        active: 'true',\n        role: 'MASTER'\n    };\n\n    test('stringify before equals parse after', () =\u003e {\n\n        const template = {\n            id: Parsers.natural(),\n            name: Parsers.string(),\n            active: Parsers.boolean(),\n            role: Parsers.enum(['GUEST', 'USER', 'MASTER', 'ADMIN'])\n        };\n\n        const target = parse(source, template);\n\n        expect(target).toEqual({\n            id: 123456,\n            name: 'jimmy ',\n            active: true,\n            role: 'MASTER'\n        });\n    });\n    \n    test('with defaults', () =\u003e {\n\n        const template = {\n            id: Parsers.natural(),\n            name: Parsers.string(true),\n            active: Parsers.boolean(),\n            role: Parsers.enum(['GUEST', 'USER'])\n        };\n\n        const defaults = {\n            role: 'GUEST'\n        };\n\n        const target = parse(source, template, defaults);\n\n        expect(target.role).toBe(defaults.role);\n    });\n```\nstring parser\n```js\n    import {parse,Parsers} from 'type-query-parser';\n\n    test('Parsers.string', () =\u003e {\n\n        const query = {\n            name: ' jimmy '\n        };\n        //with out trim\n        expect(parse(query, {name: Parsers.string()}).name).toBe(query.name);\n        //with trim\n        expect(parse(query, {name: Parsers.string(true)}).name).toBe(query.name.trim());\n    });\n```\nnumber parser\n```js\n    import {parse,Parsers} from 'type-query-parser';\n\n    test('Parsers.number', () =\u003e {\n\n        const query = {\n            price: '12.34'\n        };\n\n        expect(parse(query, {price: Parsers.number()}).price).toBe(12.34);\n    });\n```\n# api\n\u003cstrong\u003eparse\u003c/strong\u003e `query` to an object you want by `template` and `defaults` in `opt`.\n\ntypes:\n\ntype Parser = (value?: string|string[]) =\u003e any|void;\n`any function matches Parser is used to transform value to you want`\n\ntype Template = {\n    [key: string]: Template | Parser\n} | Parser[];\n`any object matches Template is used to structure result you want`\n\ntype {defaults?:any} \n`the default value you provide, when the value is undefined, the value in defaults with same key will replace the undefined one.`\n```js\nfunction parse(search:string,template?:Template,defaults?: any)\n```\n\u003cstrong\u003eParsers\u003c/strong\u003e provide some `Parser`, which is helpful, also you can write yourself Parsers.\n\n\u003cstrong\u003eParsers.number:\u003c/strong\u003e\n```\nfunction Parsers.number() return a Parser\n \nParser:(value?:string)=\u003enumber|undefined\n\nif the value isNaN (can not be a number), it will return an undefined value, \nelse it will provide a number value (typeof returnValue==='number').\n```\n\n\u003cstrong\u003eParsers.natural:\u003c/strong\u003e\n```\nfunction Parsers.natural() return a Parser\n \nParser:(value?:string)=\u003enumber|undefined\n\nif the value can not be a natural number, it will return an undefined value, \nelse it will provide a natural number value (typeof returnValue==='number').\n```\n\n\u003cstrong\u003eParsers.integer:\u003c/strong\u003e\n```\nfunction Parsers.natural() return a Parser\n \nParser:(value?:string)=\u003enumber|undefined\n\nif the value can not be a integer, it will return an undefined value, \nelse it will provide a integer value (typeof returnValue==='number').\n```\n\n\u003cstrong\u003eParsers.string:\u003c/strong\u003e\n```\nfunction Parsers.string(trim:boolean) return a Parser\n \nParser:(value?:string)=\u003estring\n\nthe value will be a string, if you set trim:true the string value will be trimmed.\n```\n\n\u003cstrong\u003eParsers.boolean:\u003c/strong\u003e\n```\nfunction Parsers.boolean() return a Parser\n \nParser:(value?:string)=\u003eboolean|undefined\n\nif the value trimmed is not 'true' or 'false', it will return an undefined value, \nelse it will provide a boolean value (typeof returnValue==='boolean').\n```\n\n\u003cstrong\u003eParsers.enum:\u003c/strong\u003e\n```\nfunction Parsers.enum(array:Array\u003cany\u003e) return a Parser\n \nParser:(value?:string)=\u003eany|undefined\n\nif the value trimmed is not included in array, it will return an undefined value, \nelse it will return the one in array which matches value by '==' not '==='.\n```\n\n\u003cstrong\u003eParsers.array:\u003c/strong\u003e\n```\nfunction Parsers.array(mapper?: (data: string) =\u003e any) return a Parser\n \nParser: (value?: string | Array\u003cstring\u003e)=\u003eArray\u003cany\u003e|Array\u003cstring\u003e\n\nif the value is string, it will transform to array by string.split, then the array will map with mapper, \nat last the mapped array will filter out the datas to a new array which data is not undefined.\n```\n\n\u003cstrong\u003eParsers.regExp:\u003c/strong\u003e\n```\nfunction Parsers.regExp(regExp: RegExp) return a Parser\n \nParser:(value?:string)=\u003estring|undefined\n\nif the value 'regExp.test(value)' is passed, it will return value, else it will undefined.\n```\n\n\u003cstrong\u003eParsers.date:\u003c/strong\u003e\n```\nfunction Parsers.date(...dateLikeReduces: Array\u003cDateLikeReduce\u003e) return a Parser\n \nParser:(value?:string)=\u003eDateLike|undefined\n\ntype DateLike = string | number | Date;\n\ntype DateLikeReduce = (dateLike: DateLike) =\u003e DateLike\n\nif the value trimmed can be a Date value, it will return a DateLike value, \nwhich might be produced by dateLikeReduces, else it will return undefined.\n\nhere is some dateLikeReduces provided, they can help you use it more quickly:\n\nstartOfDay(dateLike: DateLike)=\u003eDate                // DateLike[2020-05-23 12:11:34] =\u003e new Date(2020-05-23 00:00:00:000)\nendOfDay(dateLike: DateLike)=\u003eDate                  // DateLike[2020-05-23 12:11:34] =\u003e new Date(2020-05-23 23:59:59:999)\ntoDateString(date: DateLike)=\u003estring                // DateLike[2020-05-23 12:11:34] =\u003e '2020-05-23'\ntoDatetimeString(date: DateLike)=\u003estring            // DateLike[2020-05-23 12:11:34] =\u003e '2020-05-23 12:11:34'\npattern(pat: string)=\u003eformatDateLike(dateLike: DateLike)=\u003estring\n                                                    // pattern('YYYY-MM-DD HH:mm')=\u003eformatter\n                                                    // formatter(DateLike[2020-05-23 12:11:34])\n                                                    // =\u003e'2020-05-23 12:11'\n                                                    \nwe can use like this:\nimport {parse,Parsers} from 'type-query-parser';\nimport {startOfDay,pattern} from 'type-query-parser/libs';\n\nconst template={\n    start:Parsers.date(startOfDay,pattern('YYYY-MM-DD HH:mm:ss')),\n    end:Parsers.date(endOfDay,toDatetimeString)\n};\n\nconst data=parse({start:'2020-01-01 11:02:30',end:'2020-12-13 20:02:15'},template);\n\n/*** result ***/\n{\n    start:'2020-01-01 00:00:00',\n    end:'2020-12-13 23:59:59'\n}\n```\n\n\u003cstrong\u003eParsers.datePattern:\u003c/strong\u003e\n```\nfunction Parsers.datePattern(...dateLikeReduces: Array\u003cDateLikeReduce\u003e) return a Parser\n \nParser:(value?:string)=\u003estring|undefined\n\nit is just a wrap on Parsers.date, and returns a 'YYYY-MM-DD' formatted string value or undefined.\n```\n\n\u003cstrong\u003eParsers.datetimePattern:\u003c/strong\u003e\n```\nfunction Parsers.datetimePattern(...dateLikeReduces: Array\u003cDateLikeReduce\u003e) return a Parser\n \nParser:(value?:string)=\u003estring|undefined\n\nit is just a wrap on Parsers.date, and returns a 'YYYY-MM-DD HH:mm:ss' formatted string value or undefined.\n```\n\n# summary\nif you like this tool, give me a little start, thank you.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilefoxper%2Ftype-query-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilefoxper%2Ftype-query-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilefoxper%2Ftype-query-parser/lists"}