MCPcopy Create free account
hub / github.com/0010aor/FlashNotes / getQueryString

Function getQueryString

frontend/src/client/core/request.ts:40–66  ·  view source on GitHub ↗
(params: Record<string, unknown>)

Source from the content-addressed store, hash-verified

38}
39
40export const getQueryString = (params: Record<string, unknown>): string => {
41 const qs: string[] = []
42
43 const append = (key: string, value: unknown) => {
44 qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
45 }
46
47 const encodePair = (key: string, value: unknown) => {
48 if (value === undefined || value === null) {
49 return
50 }
51
52 if (value instanceof Date) {
53 append(key, value.toISOString())
54 } else if (Array.isArray(value)) {
55 value.forEach((v) => encodePair(key, v))
56 } else if (typeof value === 'object') {
57 Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v))
58 } else {
59 append(key, value)
60 }
61 }
62
63 Object.entries(params).forEach(([key, value]) => encodePair(key, value))
64
65 return qs.length ? `?${qs.join('&')}` : ''
66}
67
68const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
69 const encoder = config.ENCODE_PATH || encodeURI

Callers 1

getUrlFunction · 0.85

Calls 1

encodePairFunction · 0.85

Tested by

no test coverage detected