api Page updated: refactor to make it looks like article
This commit is contained in:
1 parent
68b7f4225d
commit
348c3baba8
11 files changed
+160
-63
No files matched your search
@@ -3,3 +3,16 @@ export function unique<T>(items: T[], key: (item: T) => string): T[]{
|
||||
|
||||
return [...map.values()]
|
||||
}
|
||||
|
||||
export function ensureArray<T>(value: T | T[]): T[] {
|
||||
if (!value) {
|
||||
return []
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value
|
||||
}
|
||||
|
||||
return [value]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { Request } from 'express'
|
||||
import { ensureArray } from './array'
|
||||
|
||||
export function dropTrailingSlash(path: string) {
|
||||
if (path === '/' || path === '') {
|
||||
return '/'
|
||||
@@ -26,3 +29,16 @@ export function getPathWaterfall(path: string): string[] {
|
||||
|
||||
return ['/', ...parts]
|
||||
}
|
||||
|
||||
export function readQueryInt(req: Request, key: string) {
|
||||
const int = (value: string | string[]) => parseInt(Array.isArray(value)
|
||||
? value[0]
|
||||
: value
|
||||
)
|
||||
|
||||
return int(req.query[key]) || 0
|
||||
}
|
||||
|
||||
export function readQueryArray(req: Request, key: string) {
|
||||
return ensureArray(req.query[key])
|
||||
}
|
||||
Reference in new issue
Block a user