deno.land / x / jose@v5.2.4 / lib / invalid_key_input.ts

invalid_key_input.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function message(msg: string, actual: unknown, ...types: string[]) { if (types.length > 2) { const last = types.pop() msg += `one of type ${types.join(', ')}, or ${last}.` } else if (types.length === 2) { msg += `one of type ${types[0]} or ${types[1]}.` } else { msg += `of type ${types[0]}.` }
if (actual == null) { msg += ` Received ${actual}` } else if (typeof actual === 'function' && actual.name) { msg += ` Received function ${actual.name}` } else if (typeof actual === 'object' && actual != null) { if (actual.constructor?.name) { msg += ` Received an instance of ${actual.constructor.name}` } }
return msg}
export default (actual: unknown, ...types: string[]) => { return message('Key must be ', actual, ...types)}
export function withAlg(alg: string, actual: unknown, ...types: string[]) { return message(`Key for the ${alg} algorithm must be `, actual, ...types)}
jose

Version Info

Tagged at
a month ago