Installations
npm install typed-url-params
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
14.16.0
NPM Version
6.14.11
Score
79
Supply Chain
92.4
Quality
75.2
Maintenance
100
Vulnerability
100
License
Contributors
Unable to fetch Contributors
Languages
TypeScript (93.25%)
Makefile (6.75%)
Developer
menduz
Download Statistics
Total Downloads
271,723
Last Day
40
Last Week
511
Last Month
5,475
Last Year
108,456
GitHub Statistics
86 Stars
3 Commits
3 Watching
3 Branches
1 Contributors
Bundle Size
205.00 B
Minified
172.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.0.1
Package Id
typed-url-params@1.0.1
Size
5.23 kB
NPM Version
6.14.11
Node Version
14.16.0
Publised On
08 Apr 2021
Total Downloads
Cumulative downloads
Total Downloads
271,723
Last day
-64.6%
40
Compared to previous day
Last week
-50.2%
511
Compared to previous week
Last month
-79.3%
5,475
Compared to previous month
Last year
-2.6%
108,456
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
typed-url-params
Types your URL parameters in compliance with Express.js router and https://github.com/pillarjs/path-to-regexp
Install
npm install typed-url-params
Usage
1type Params = ParseUrlParams<"/test"> // { } 2type Params = ParseUrlParams<"/:abc"> // { abc: string } 3type Params = ParseUrlParams<"/:abc+"> // { abc: string | string[] } 4type Params = ParseUrlParams<"/:abc*"> // { abc?: string | string[] } 5type Params = ParseUrlParams<"/users/:userId"> // { userId: string } 6type Params = ParseUrlParams<"/flights/:from-:to"> // { from: string, to: string }
Usage with Express
This library only offers typings. You must write your own wrapper for Express. You can do it like this:
1function handleGet<TypedUrl extends string>( 2 app: Express.Application, 3 url: TypedUrl, 4 handler: (req: Express.Request & { params: ParseUrlParams<TypedUrl> }, res: Express.Response, next) => void 5) { 6 // noop 7}
More examples
1 2import { ParseUrlParams } from "typed-url-params" 3 4function assert<T extends string = string>(r: ParseUrlParams<T>): asserts r is ParseUrlParams<T> {} 5 6assert<"/:asd/b">({ asd: "" }) 7assert<"/xxx/:asd/bbb:dsa">({ asd: "", dsa: "" }) 8assert<"/xxx/:asd/bbb/:dsa">({ asd: "", dsa: "" }) 9assert<"/xxx/:asd/bbb/:dsa">({ asd: "", dsa: "" }) 10assert<"/:test*-bar">({ test: [] }) 11assert<"/:test*-bar">({}) 12assert<"/:test*-bar">({ test: "asd" }) 13assert<"/:test*-bar">({ test: ["asd"] }) 14assert<"/:test+-bar">({ test: [""] }) 15assert<"/:test*">({ test: [] }) 16assert<"/:test+">({ test: "" }) 17assert<"/:test+">({ test: [""] }) 18assert<"/:test?-bar">({ test: "" }) 19assert<"/:test?">({ test: "" }) 20assert<"/:test(\\d+)">({ test: "" }) 21assert<"/:test(\\d+)+">({ test: "" }) 22assert<"/:test(\\d+)+">({ test: [""] }) 23assert<"/route.:ext(json|xml)?">({}) 24assert<"/route.:ext(json|xml)?">({ ext: "" }) 25assert<"/route.:ext(json|xml)">({ ext: "" }) 26assert<"/route.:ext(json|xml)+">({ ext: "" }) 27assert<"/route.:ext(json|xml)+">({ ext: [""] }) 28assert<"/route.:ext([a-z]+)*/:asd">({ ext: [""], asd: "" }) 29assert<"/route.:ext([a-z]+)*/:asd">({ asd: "" }) 30assert<"/route.:ext([a-z]+)*">({ ext: [""] }) 31assert<"/route.:ext([a-z]+)/:asd">({ ext: "", asd: "" }) 32assert<"/:test(.*)">({ test: "" }) 33assert<"/route\\(\\\\(\\d+\\\\)\\)">({}) 34assert<"/{apple-}?icon-:res(\\d+).png">({ res: "" }) 35assert<"/:foo/:bar">({ foo: "", bar: "" }) 36assert<"/users/:user_id/:asd+">({ user_id: "", asd: [] }) 37assert<"/flights/:from-:to">({ from: "", to: "" })
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
7 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-qgmg-gppg-76g5
Reason
Found 0/3 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/menduz/typed-url-params/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/menduz/typed-url-params/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/menduz/typed-url-params/ci.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:17
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 1 are checked with a SAST tool
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
Score
2.5
/10
Last Scanned on 2024-07-08
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More