@nr1e/commons 0.0.3-alpha.8 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/bitsnbytes/b64.d.ts +1 -0
  2. package/bitsnbytes/b64.d.ts.map +1 -0
  3. package/bitsnbytes/b64.js +17 -25
  4. package/bitsnbytes/b64.js.map +1 -1
  5. package/bitsnbytes/b64.test.d.ts +2 -0
  6. package/bitsnbytes/b64.test.d.ts.map +1 -0
  7. package/bitsnbytes/b64.test.js +55 -0
  8. package/bitsnbytes/b64.test.js.map +1 -0
  9. package/bitsnbytes/index.d.ts +2 -1
  10. package/bitsnbytes/index.d.ts.map +1 -0
  11. package/bitsnbytes/index.js +1 -17
  12. package/bitsnbytes/index.js.map +1 -1
  13. package/errors/errors.d.ts +2 -2
  14. package/errors/errors.d.ts.map +1 -0
  15. package/errors/errors.js +59 -81
  16. package/errors/errors.js.map +1 -1
  17. package/errors/errors.test.d.ts +2 -0
  18. package/errors/errors.test.d.ts.map +1 -0
  19. package/errors/errors.test.js +44 -0
  20. package/errors/errors.test.js.map +1 -0
  21. package/errors/index.d.ts +2 -1
  22. package/errors/index.d.ts.map +1 -0
  23. package/errors/index.js +1 -17
  24. package/errors/index.js.map +1 -1
  25. package/http/http-method.d.ts +1 -0
  26. package/http/http-method.d.ts.map +1 -0
  27. package/http/http-method.js +2 -5
  28. package/http/http-method.js.map +1 -1
  29. package/http/http-status-code.d.ts +1 -0
  30. package/http/http-status-code.d.ts.map +1 -0
  31. package/http/http-status-code.js +2 -5
  32. package/http/http-status-code.js.map +1 -1
  33. package/http/index.d.ts +3 -2
  34. package/http/index.d.ts.map +1 -0
  35. package/http/index.js +2 -18
  36. package/http/index.js.map +1 -1
  37. package/lang/index.d.ts +3 -2
  38. package/lang/index.d.ts.map +1 -0
  39. package/lang/index.js +2 -18
  40. package/lang/index.js.map +1 -1
  41. package/lang/sleep.d.ts +1 -0
  42. package/lang/sleep.d.ts.map +1 -0
  43. package/lang/sleep.js +1 -5
  44. package/lang/sleep.js.map +1 -1
  45. package/lang/type-functions.d.ts +1 -0
  46. package/lang/type-functions.d.ts.map +1 -0
  47. package/lang/type-functions.js +3 -9
  48. package/lang/type-functions.js.map +1 -1
  49. package/package.json +33 -19
  50. package/validator/index.d.ts +2 -1
  51. package/validator/index.d.ts.map +1 -0
  52. package/validator/index.js +1 -17
  53. package/validator/index.js.map +1 -1
  54. package/validator/validators.d.ts +1 -0
  55. package/validator/validators.d.ts.map +1 -0
  56. package/validator/validators.js +37 -64
  57. package/validator/validators.js.map +1 -1
  58. package/validator/validators.test.d.ts +2 -0
  59. package/validator/validators.test.d.ts.map +1 -0
  60. package/validator/validators.test.js +176 -0
  61. package/validator/validators.test.js.map +1 -0
  62. package/.prettierrc.js +0 -3
  63. package/LICENSE +0 -26
  64. package/README.md +0 -14
  65. package/index.d.ts +0 -5
  66. package/index.js +0 -9
  67. package/index.js.map +0 -1
  68. package/jest.config.js +0 -8
@@ -37,3 +37,4 @@ export declare function tob64s(buf: Uint8Array, opts?: Base64Options): string;
37
37
  * @return a base64 string
38
38
  */
39
39
  export declare function stob64s(str: string, opts?: Base64Options): string;
40
+ //# sourceMappingURL=b64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"b64.d.ts","sourceRoot":"","sources":["../../src/bitsnbytes/b64.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,EAAE,UAMzB,CAAC;AAOH,eAAO,MAAM,yBAAyB,EAAE,UAMtC,CAAC;AAOH,eAAO,MAAM,gBAAgB,EAAE,UAM7B,CAAC;AAOH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,aAAa,CAAC;CAChD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,aAAa,GAAG,UAAU,CA0B5E;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,UAAU,CAyCvE;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,MAAM,CAEpE;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,MAAM,CAEjE"}
package/bitsnbytes/b64.js CHANGED
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stob64s = exports.tob64s = exports.tob64 = exports.b64Charset = exports.YUI_BASE64_CHARS = exports.URL_MODIFIED_BASE64_CHARS = exports.BASE64_CHARS = void 0;
4
- const errors_1 = require("../errors");
1
+ import { IllegalArgumentError } from '../errors/errors.js';
5
2
  // eslint-disable-next-line node/no-unsupported-features/node-builtins
6
3
  const encoder = new TextEncoder();
7
4
  // eslint-disable-next-line node/no-unsupported-features/node-builtins
8
5
  const decoder = new TextDecoder();
9
- exports.BASE64_CHARS = new Uint8Array([
6
+ export const BASE64_CHARS = new Uint8Array([
10
7
  0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
11
8
  0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
12
9
  0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
@@ -18,7 +15,7 @@ exports.BASE64_CHARS = new Uint8Array([
18
15
  // 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
19
16
  // 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
20
17
  // '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '='
21
- exports.URL_MODIFIED_BASE64_CHARS = new Uint8Array([
18
+ export const URL_MODIFIED_BASE64_CHARS = new Uint8Array([
22
19
  0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
23
20
  0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
24
21
  0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
@@ -30,7 +27,7 @@ exports.URL_MODIFIED_BASE64_CHARS = new Uint8Array([
30
27
  // 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
31
28
  // 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
32
29
  // '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',
33
- exports.YUI_BASE64_CHARS = new Uint8Array([
30
+ export const YUI_BASE64_CHARS = new Uint8Array([
34
31
  0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
35
32
  0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
36
33
  0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
@@ -42,28 +39,27 @@ exports.YUI_BASE64_CHARS = new Uint8Array([
42
39
  *
43
40
  * @param b64chars a base64 character set
44
41
  */
45
- function b64Charset(b64chars) {
42
+ export function b64Charset(b64chars) {
46
43
  if (b64chars === undefined || b64chars === null) {
47
- return exports.BASE64_CHARS;
44
+ return BASE64_CHARS;
48
45
  }
49
46
  if (b64chars instanceof Uint8Array) {
50
47
  if (b64chars.length !== 65 && b64chars.length !== 64) {
51
- throw new errors_1.IllegalArgumentError('b64chars', 'Base 64 character sets must be 64 or 65 characters.');
48
+ throw new IllegalArgumentError('b64chars', 'Base 64 character sets must be 64 or 65 characters.');
52
49
  }
53
50
  return b64chars;
54
51
  }
55
52
  switch (b64chars) {
56
53
  case 'b64':
57
- return exports.BASE64_CHARS;
54
+ return BASE64_CHARS;
58
55
  case 'url':
59
- return exports.URL_MODIFIED_BASE64_CHARS;
56
+ return URL_MODIFIED_BASE64_CHARS;
60
57
  case 'yui':
61
- return exports.YUI_BASE64_CHARS;
58
+ return YUI_BASE64_CHARS;
62
59
  default:
63
- throw new errors_1.IllegalArgumentError('b64chars', `Invalid base64 character set '${b64chars}'`);
60
+ throw new IllegalArgumentError('b64chars', `Invalid base64 character set '${b64chars}'`);
64
61
  }
65
62
  }
66
- exports.b64Charset = b64Charset;
67
63
  /**
68
64
  * Base64 encodes a series of bytes.
69
65
  *
@@ -71,11 +67,10 @@ exports.b64Charset = b64Charset;
71
67
  * @param opts Encoding options
72
68
  * @return a base64 string
73
69
  */
74
- function tob64(buf, opts) {
75
- var _a, _b;
76
- const b64chars = b64Charset(opts === null || opts === void 0 ? void 0 : opts.b64chars);
77
- const toIndex = (_a = opts === null || opts === void 0 ? void 0 : opts.toIndex) !== null && _a !== void 0 ? _a : buf.length;
78
- const fromIndex = (_b = opts === null || opts === void 0 ? void 0 : opts.fromIndex) !== null && _b !== void 0 ? _b : 0;
70
+ export function tob64(buf, opts) {
71
+ const b64chars = b64Charset(opts?.b64chars);
72
+ const toIndex = opts?.toIndex ?? buf.length;
73
+ const fromIndex = opts?.fromIndex ?? 0;
79
74
  // every 3 bytes is 4 characters in padded base64 (6 bits per char)
80
75
  const num = toIndex - fromIndex;
81
76
  const numc = b64chars.length === 65
@@ -111,7 +106,6 @@ function tob64(buf, opts) {
111
106
  }
112
107
  return b64;
113
108
  }
114
- exports.tob64 = tob64;
115
109
  /**
116
110
  * Base64 encodes a series of bytes to a string.
117
111
  *
@@ -119,10 +113,9 @@ exports.tob64 = tob64;
119
113
  * @param opts Encoding options
120
114
  * @return a base64 string
121
115
  */
122
- function tob64s(buf, opts) {
116
+ export function tob64s(buf, opts) {
123
117
  return decoder.decode(tob64(buf, opts));
124
118
  }
125
- exports.tob64s = tob64s;
126
119
  /**
127
120
  * Base64 encodes a string to a string.
128
121
  *
@@ -130,8 +123,7 @@ exports.tob64s = tob64s;
130
123
  * @param opts Encoding options
131
124
  * @return a base64 string
132
125
  */
133
- function stob64s(str, opts) {
126
+ export function stob64s(str, opts) {
134
127
  return tob64s(encoder.encode(str), opts);
135
128
  }
136
- exports.stob64s = stob64s;
137
129
  //# sourceMappingURL=b64.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"b64.js","sourceRoot":"","sources":["b64.ts"],"names":[],"mappings":";;;AAAA,sCAA+C;AAE/C,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAErB,QAAA,YAAY,GAAe,IAAI,UAAU,CAAC;IACrD,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IAC5E,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IAC5E,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,I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,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;iBACzB;gBACD,MAAM;YACR,KAAK,CAAC,EAAE,yBAAyB;gBAC/B,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBACtC,IAAI,QAAQ,CAAC,MAAM,KAAK,EAAE,EAAE;oBAC1B,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;iBACzB;gBACD,MAAM;YACR;gBACE,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBACtC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBAC9B,MAAM;SACT;KACF;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,GAAe,EAAE,IAAoB;IAC1D,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,GAAW,EAAE,IAAoB;IACvD,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import {IllegalArgumentError} from '../errors/errors.js';\n\n// eslint-disable-next-line node/no-unsupported-features/node-builtins\nconst encoder = new TextEncoder();\n// eslint-disable-next-line node/no-unsupported-features/node-builtins\nconst decoder = new TextDecoder();\n\nexport const BASE64_CHARS: Uint8Array = new Uint8Array([\n 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,\n 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,\n 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,\n 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f, 0x3d,\n]);\n// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',\n// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\n// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',\n// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',\n// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '='\n\nexport const URL_MODIFIED_BASE64_CHARS: Uint8Array = new Uint8Array([\n 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,\n 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,\n 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,\n 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2d, 0x5f,\n]);\n// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',\n// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\n// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',\n// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',\n// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',\n\nexport const YUI_BASE64_CHARS: Uint8Array = new Uint8Array([\n 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,\n 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,\n 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,\n 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2e, 0x5f, 0x2d,\n]);\n// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',\n// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\n// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',\n// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',\n// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '_', '-'\n\nexport type Base64CharSet = 'b64' | 'url' | 'yui';\n\nexport interface Base64Options {\n readonly fromIndex?: number;\n readonly toIndex?: number;\n readonly b64chars?: Uint8Array | Base64CharSet;\n}\n\n/**\n * Returns a base64 character set and validates one if passed in.\n *\n * @param b64chars a base64 character set\n */\nexport function b64Charset(b64chars?: Uint8Array | Base64CharSet): Uint8Array {\n if (b64chars === undefined || b64chars === null) {\n return BASE64_CHARS;\n }\n if (b64chars instanceof Uint8Array) {\n if (b64chars.length !== 65 && b64chars.length !== 64) {\n throw new IllegalArgumentError(\n 'b64chars',\n 'Base 64 character sets must be 64 or 65 characters.'\n );\n }\n return b64chars;\n }\n switch (b64chars) {\n case 'b64':\n return BASE64_CHARS;\n case 'url':\n return URL_MODIFIED_BASE64_CHARS;\n case 'yui':\n return YUI_BASE64_CHARS;\n default:\n throw new IllegalArgumentError(\n 'b64chars',\n `Invalid base64 character set '${b64chars}'`\n );\n }\n}\n\n/**\n * Base64 encodes a series of bytes.\n *\n * @param buf Bytes to encode\n * @param opts Encoding options\n * @return a base64 string\n */\nexport function tob64(buf: Uint8Array, opts?: Base64Options): Uint8Array {\n const b64chars = b64Charset(opts?.b64chars);\n const toIndex = opts?.toIndex ?? buf.length;\n const fromIndex = opts?.fromIndex ?? 0;\n // every 3 bytes is 4 characters in padded base64 (6 bits per char)\n const num = toIndex - fromIndex;\n const numc =\n b64chars.length === 65\n ? ((num + 2 - ((num + 2) % 3)) / 3) * 4 // padded\n : (num * 8) / 6 + ((num * 8) % 6 !== 0 ? 1 : 0); // not padded\n const b64 = new Uint8Array(numc);\n let n = 0;\n for (let i = 0; i < toIndex; i += 3) {\n const v =\n ((buf[i] & 0xff) << 16) |\n (i + 1 < toIndex ? (buf[i + 1] & 0xff) << 8 : 0) |\n (i + 2 < toIndex ? buf[i + 2] & 0xff : 0);\n b64[n++] = b64chars[(v >>> 18) & 0x3f];\n b64[n++] = b64chars[(v >>> 12) & 0x3f];\n switch (\n toIndex - i // calculate bytes remaining to be processed\n ) {\n case 1: // 0 bytes left to process\n if (b64chars.length === 65) {\n b64[n++] = b64chars[64];\n b64[n++] = b64chars[64];\n }\n break;\n case 2: // 1 byte left to process\n b64[n++] = b64chars[(v >>> 6) & 0x3f];\n if (b64chars.length === 65) {\n b64[n++] = b64chars[64];\n }\n break;\n default:\n b64[n++] = b64chars[(v >>> 6) & 0x3f];\n b64[n++] = b64chars[v & 0x3f];\n break;\n }\n }\n return b64;\n}\n\n/**\n * Base64 encodes a series of bytes to a string.\n *\n * @param buf Bytes to encode\n * @param opts Encoding options\n * @return a base64 string\n */\nexport function tob64s(buf: Uint8Array, opts?: Base64Options): string {\n return decoder.decode(tob64(buf, opts));\n}\n\n/**\n * Base64 encodes a string to a string.\n *\n * @param str String to encode\n * @param opts Encoding options\n * @return a base64 string\n */\nexport function stob64s(str: string, opts?: Base64Options): string {\n return tob64s(encoder.encode(str), opts);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=b64.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"b64.test.d.ts","sourceRoot":"","sources":["../../src/bitsnbytes/b64.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,55 @@
1
+ import { stob64s } from './b64.js';
2
+ test('Test tob64', () => {
3
+ const str = '"Computer, compute to the last digit the value of pi" -- Spock';
4
+ let b64s = [
5
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3BvY2s=',
6
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3BvYw==',
7
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3Bv',
8
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3A=',
9
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gUw==',
10
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1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 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0g',
45
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0-',
46
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLQ--',
47
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIg',
48
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSI-',
49
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaQ--',
50
+ ];
51
+ for (let i = 0; i < b64s.length; i++) {
52
+ expect(b64s[i]).toBe(stob64s(str.substring(0, str.length - i), { b64chars: 'yui' }));
53
+ }
54
+ });
55
+ //# sourceMappingURL=b64.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"b64.test.js","sourceRoot":"","sources":["../../src/bitsnbytes/b64.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAEjC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE;IACtB,MAAM,GAAG,GAAG,gEAAgE,CAAC;IAC7E,IAAI,IAAI,GAAG;QACT,sFAAsF;QACtF,sFAAsF;QACtF,kFAAkF;QAClF,kFAAkF;QAClF,kFAAkF;QAClF,8EAA8E;QAC9E,8EAA8E;QAC9E,8EAA8E;QAC9E,0EAA0E;QAC1E,0EAA0E;QAC1E,0EAA0E;KAC3E,CAAC;IACF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,M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ACH,CAAC,CAAC,CAAC","sourcesContent":["import {stob64s} from './b64.js';\n\ntest('Test tob64', () => {\n const str = '\"Computer, compute to the last digit the value of pi\" -- Spock';\n let b64s = [\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3BvY2s=',\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3BvYw==',\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3Bv',\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3A=',\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gUw==',\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0g',\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0=',\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLQ==',\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIg',\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSI=',\n 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaQ==',\n ];\n for (let i =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(\n stob64s(str.substring(0, str.length - i), {b64chars: 'yui'})\n );\n }\n});\n"]}
@@ -1 +1,2 @@
1
- export * from './b64';
1
+ export * from './b64.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bitsnbytes/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
@@ -1,18 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./b64"), exports);
1
+ export * from './b64.js';
18
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bitsnbytes/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC","sourcesContent":["export * from './b64.js';\n"]}
@@ -1,5 +1,4 @@
1
- import { HttpStatusCode } from '../http';
2
- export { isError } from '../lang';
1
+ import { HttpStatusCode } from '../http/index.js';
3
2
  /**
4
3
  * An extended version of Error that includes an HttpStatusCode.
5
4
  * This can be useful in middleware error handlers to determine http status codes to return to the client.
@@ -158,3 +157,4 @@ export declare function isIllegalArgumentError(e?: unknown): e is IllegalArgumen
158
157
  * @param message The error message
159
158
  */
160
159
  export declare function toError(code: number | HttpStatusCode, message?: string): Error;
160
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAGhD;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,KAAK;IACtC;;OAEG;IACH,UAAU,EAAE,cAAc,GAAG,MAAM,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,SAAS,CAEvD;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAM,YAAW,SAAS;IAC3D,QAAQ,CAAC,UAAU,4BAA4B;IAC/C;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBACb,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAM9C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,aAAa,CAE/D;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAM,YAAW,SAAS;IAC/D,QAAQ,CAAC,UAAU,+BAA+B;gBACtC,OAAO,CAAC,EAAE,MAAM;CAK7B;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,iBAAiB,CAEvE;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAM,YAAW,SAAS;IAC5D,QAAQ,CAAC,UAAU,4BAA4B;gBACnC,OAAO,CAAC,EAAE,MAAM;CAK7B;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,cAAc,C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kC;IACrD,QAAQ,CAAC,MAAM,QAAQ;gBACX,OAAO,CAAC,EAAE,MAAM;CAK7B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,mBAAmB,CAE3E;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAM9C;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,oBAAoB,CAE7E;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,GAAG,cAAc,EAC7B,OAAO,CAAC,EAAE,MAAM,GACf,KAAK,CAmBP"}
package/errors/errors.js CHANGED
@@ -1,256 +1,234 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toError = exports.isIllegalArgumentError = exports.IllegalArgumentError = exports.isNotImplementedError = exports.NotImplementedError = exports.isUnsupportedMediaTypeError = exports.UnsupportedMediaTypeError = exports.isConflictError = exports.ConflictError = exports.isInternalServerError = exports.InternalServerError = exports.isBadRequestError = exports.BadRequestError = exports.isValidationError = exports.ValidationError = exports.isForbiddenError = exports.ForbiddenError = exports.isUnauthorizedError = exports.UnauthorizedError = exports.isNotFoundError = exports.NotFoundError = exports.isHttpError = exports.isError = void 0;
4
- const http_1 = require("../http");
5
- const lang_1 = require("../lang");
6
- var lang_2 = require("../lang");
7
- Object.defineProperty(exports, "isError", { enumerable: true, get: function () { return lang_2.isError; } });
1
+ import { HttpStatusCode } from '../http/index.js';
2
+ import { isError, isObject } from '../lang/index.js';
8
3
  /**
9
4
  * Checks if the given parameter is an HttpError.
10
5
  *
11
6
  * @param e The parameter to check
12
7
  */
13
- function isHttpError(e) {
14
- return (0, lang_1.isObject)(e) && !!(e && e.stack && e.statusCode && e.message && e.name);
8
+ export function isHttpError(e) {
9
+ return isObject(e) && !!(e && e.stack && e.statusCode && e.message && e.name);
15
10
  }
16
- exports.isHttpError = isHttpError;
17
11
  /**
18
12
  * Thrown when a resource cannot be found.
19
13
  */
20
- class NotFoundError extends Error {
14
+ export class NotFoundError extends Error {
15
+ statusCode = HttpStatusCode.NOT_FOUND;
16
+ /**
17
+ * The max-age value to set in the Cache-Control header if used in a middleware.
18
+ */
19
+ maxAge;
21
20
  constructor(message, maxAge) {
22
- message = message !== null && message !== void 0 ? message : 'Not found';
21
+ message = message ?? 'Not found';
23
22
  super(message);
24
- this.statusCode = http_1.HttpStatusCode.NOT_FOUND;
25
23
  this.name = 'NotFoundError';
26
24
  this.maxAge = maxAge;
27
25
  }
28
26
  }
29
- exports.NotFoundError = NotFoundError;
30
27
  /**
31
28
  * Checks if the given parameter is a NotFoundError.
32
29
  *
33
30
  * @param e The parameter to check
34
31
  */
35
- function isNotFoundError(e) {
32
+ export function isNotFoundError(e) {
36
33
  return isHttpError(e) && e.name === 'NotFoundError';
37
34
  }
38
- exports.isNotFoundError = isNotFoundError;
39
35
  /**
40
36
  * Thrown when a request is missing authentication credentials.
41
37
  */
42
- class UnauthorizedError extends Error {
38
+ export class UnauthorizedError extends Error {
39
+ statusCode = HttpStatusCode.UNAUTHORIZED;
43
40
  constructor(message) {
44
- message = message !== null && message !== void 0 ? message : 'Unauthorized';
41
+ message = message ?? 'Unauthorized';
45
42
  super(message);
46
- this.statusCode = http_1.HttpStatusCode.UNAUTHORIZED;
47
43
  this.name = 'UnauthorizedError';
48
44
  }
49
45
  }
50
- exports.UnauthorizedError = UnauthorizedError;
51
46
  /**
52
47
  * Checks if the given parameter is a UnauthorizedError.
53
48
  *
54
49
  * @param e The parameter to check
55
50
  */
56
- function isUnauthorizedError(e) {
51
+ export function isUnauthorizedError(e) {
57
52
  return isHttpError(e) && e.name === 'UnauthorizedError';
58
53
  }
59
- exports.isUnauthorizedError = isUnauthorizedError;
60
54
  /**
61
55
  * Thrown when credentials are present, but the requested operations is not allowed.
62
56
  */
63
- class ForbiddenError extends Error {
57
+ export class ForbiddenError extends Error {
58
+ statusCode = HttpStatusCode.FORBIDDEN;
64
59
  constructor(message) {
65
- message = message !== null && message !== void 0 ? message : 'Forbidden';
60
+ message = message ?? 'Forbidden';
66
61
  super(message);
67
- this.statusCode = http_1.HttpStatusCode.FORBIDDEN;
68
62
  this.name = 'ForbiddenError';
69
63
  }
70
64
  }
71
- exports.ForbiddenError = ForbiddenError;
72
65
  /**
73
66
  * Checks if the given parameter is a ForbiddenError.
74
67
  *
75
68
  * @param e The parameter to check
76
69
  */
77
- function isForbiddenError(e) {
70
+ export function isForbiddenError(e) {
78
71
  return isHttpError(e) && e.name === 'ForbiddenError';
79
72
  }
80
- exports.isForbiddenError = isForbiddenError;
81
73
  /**
82
74
  * Thrown when a validation error occurs.
83
75
  */
84
- class ValidationError extends Error {
76
+ export class ValidationError extends Error {
77
+ statusCode = HttpStatusCode.BAD_REQUEST;
85
78
  constructor(message) {
86
- message = message !== null && message !== void 0 ? message : 'Validation error';
79
+ message = message ?? 'Validation error';
87
80
  super(message);
88
- this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
89
81
  this.name = 'ValidationError';
90
82
  }
91
83
  }
92
- exports.ValidationError = ValidationError;
93
84
  /**
94
85
  * Checks if the given variable is a ValidationError.
95
86
  *
96
87
  * @param e The variable to check
97
88
  */
98
- function isValidationError(e) {
89
+ export function isValidationError(e) {
99
90
  return isHttpError(e) && e.name === 'ValidationError';
100
91
  }
101
- exports.isValidationError = isValidationError;
102
92
  /**
103
93
  * Thrown when a bad request is made.
104
94
  */
105
- class BadRequestError extends Error {
95
+ export class BadRequestError extends Error {
96
+ statusCode = HttpStatusCode.BAD_REQUEST;
106
97
  constructor(message) {
107
- message = message !== null && message !== void 0 ? message : 'Bad request';
108
- super(message !== null && message !== void 0 ? message : 'Bad request');
109
- this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
98
+ message = message ?? 'Bad request';
99
+ super(message ?? 'Bad request');
110
100
  this.name = 'BadRequestError';
111
101
  }
112
102
  }
113
- exports.BadRequestError = BadRequestError;
114
103
  /**
115
104
  * Checks if the given parameter is a BadRequestError.
116
105
  *
117
106
  * @param e The parameter to check
118
107
  */
119
- function isBadRequestError(e) {
108
+ export function isBadRequestError(e) {
120
109
  return isHttpError(e) && e.name === 'BadRequestError';
121
110
  }
122
- exports.isBadRequestError = isBadRequestError;
123
111
  /**
124
112
  * Throws when an internal server error occurs.
125
113
  */
126
- class InternalServerError extends Error {
114
+ export class InternalServerError extends Error {
115
+ statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR;
127
116
  constructor(message) {
128
- message = message !== null && message !== void 0 ? message : 'Internal server error';
117
+ message = message ?? 'Internal server error';
129
118
  super(message);
130
- this.statusCode = http_1.HttpStatusCode.INTERNAL_SERVER_ERROR;
131
119
  this.name = 'InternalServerError';
132
120
  }
133
121
  }
134
- exports.InternalServerError = InternalServerError;
135
122
  /**
136
123
  * Checks if the given parameter is a InternalServerError.
137
124
  *
138
125
  * @param e The parameter to check
139
126
  */
140
- function isInternalServerError(e) {
127
+ export function isInternalServerError(e) {
141
128
  return isHttpError(e) && e.name === 'InternalServerError';
142
129
  }
143
- exports.isInternalServerError = isInternalServerError;
144
130
  /**
145
131
  * Thrown when a conflict occurs.
146
132
  */
147
- class ConflictError extends Error {
133
+ export class ConflictError extends Error {
134
+ statusCode = HttpStatusCode.CONFLICT;
148
135
  constructor(message) {
149
- message = message !== null && message !== void 0 ? message : 'Conflict';
136
+ message = message ?? 'Conflict';
150
137
  super(message);
151
- this.statusCode = http_1.HttpStatusCode.CONFLICT;
152
138
  this.name = 'ConflictError';
153
139
  }
154
140
  }
155
- exports.ConflictError = ConflictError;
156
141
  /**
157
142
  * Checks if the given parameter is a ConflictError.
158
143
  *
159
144
  * @param e The parameter to check
160
145
  */
161
- function isConflictError(e) {
146
+ export function isConflictError(e) {
162
147
  return isHttpError(e) && e.name === 'ConflictError';
163
148
  }
164
- exports.isConflictError = isConflictError;
165
149
  /**
166
150
  * Thrown when a unsupported media type is used.
167
151
  */
168
- class UnsupportedMediaTypeError extends Error {
152
+ export class UnsupportedMediaTypeError extends Error {
153
+ statusCode = HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
169
154
  constructor(message) {
170
- message = message !== null && message !== void 0 ? message : 'Unsupported media type';
155
+ message = message ?? 'Unsupported media type';
171
156
  super(message);
172
- this.statusCode = http_1.HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
173
157
  this.name = 'UnsupportedMediaTypeError';
174
158
  }
175
159
  }
176
- exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError;
177
160
  /**
178
161
  * Checks if the given parameter is a UnsupportedMediaTypeError.
179
162
  *
180
163
  * @param e The parameter to check
181
164
  */
182
- function isUnsupportedMediaTypeError(e) {
165
+ export function isUnsupportedMediaTypeError(e) {
183
166
  return isHttpError(e) && e.name === 'UnsupportedMediaTypeError';
184
167
  }
185
- exports.isUnsupportedMediaTypeError = isUnsupportedMediaTypeError;
186
168
  /**
187
169
  * Thrown when a requested operation is not implemented.
188
170
  */
189
- class NotImplementedError extends Error {
171
+ export class NotImplementedError extends Error {
172
+ statusCode = HttpStatusCode.NOT_IMPLEMENTED;
173
+ expose = true;
190
174
  constructor(message) {
191
- message = message !== null && message !== void 0 ? message : 'Not implemented';
175
+ message = message ?? 'Not implemented';
192
176
  super(message);
193
- this.statusCode = http_1.HttpStatusCode.NOT_IMPLEMENTED;
194
- this.expose = true;
195
177
  this.name = 'NotImplementedError';
196
178
  }
197
179
  }
198
- exports.NotImplementedError = NotImplementedError;
199
180
  /**
200
181
  * Checks if the given parameter is a NotImplementedError.
201
182
  *
202
183
  * @param e The parameter to check
203
184
  */
204
- function isNotImplementedError(e) {
185
+ export function isNotImplementedError(e) {
205
186
  return isHttpError(e) && e.name === 'NotImplementedError';
206
187
  }
207
- exports.isNotImplementedError = isNotImplementedError;
208
188
  /**
209
189
  * Thrown when an illegal argument is passed to a function.
210
190
  */
211
- class IllegalArgumentError extends Error {
191
+ export class IllegalArgumentError extends Error {
192
+ argName;
212
193
  constructor(argName, message) {
213
- message = message !== null && message !== void 0 ? message : `Illegal argument ${argName}`;
194
+ message = message ?? `Illegal argument ${argName}`;
214
195
  super(message);
215
196
  this.argName = argName;
216
197
  this.name = 'IllegalArgumentError';
217
198
  }
218
199
  }
219
- exports.IllegalArgumentError = IllegalArgumentError;
220
200
  /**
221
201
  * Checks if the given parameter is a IllegalArgumentError.
222
202
  *
223
203
  * @param e The parameter to check
224
204
  */
225
- function isIllegalArgumentError(e) {
226
- return (0, lang_1.isError)(e) && e.name === 'IllegalArgumentError';
205
+ export function isIllegalArgumentError(e) {
206
+ return isError(e) && e.name === 'IllegalArgumentError';
227
207
  }
228
- exports.isIllegalArgumentError = isIllegalArgumentError;
229
208
  /**
230
209
  * Converts the given parameter to an HttpError.
231
210
  *
232
211
  * @param code The HTTP status code
233
212
  * @param message The error message
234
213
  */
235
- function toError(code, message) {
214
+ export function toError(code, message) {
236
215
  switch (code) {
237
- case http_1.HttpStatusCode.NOT_FOUND:
216
+ case HttpStatusCode.NOT_FOUND:
238
217
  return new NotFoundError(message);
239
- case http_1.HttpStatusCode.FORBIDDEN:
218
+ case HttpStatusCode.FORBIDDEN:
240
219
  return new ForbiddenError(message);
241
- case http_1.HttpStatusCode.BAD_REQUEST:
220
+ case HttpStatusCode.BAD_REQUEST:
242
221
  return new BadRequestError(message);
243
- case http_1.HttpStatusCode.INTERNAL_SERVER_ERROR:
222
+ case HttpStatusCode.INTERNAL_SERVER_ERROR:
244
223
  return new InternalServerError(message);
245
- case http_1.HttpStatusCode.CONFLICT:
224
+ case HttpStatusCode.CONFLICT:
246
225
  return new ConflictError(message);
247
- case http_1.HttpStatusCode.UNSUPPORTED_MEDIA_TYPE:
226
+ case HttpStatusCode.UNSUPPORTED_MEDIA_TYPE:
248
227
  return new UnsupportedMediaTypeError(message);
249
- case http_1.HttpStatusCode.NOT_IMPLEMENTED:
228
+ case HttpStatusCode.NOT_IMPLEMENTED:
250
229
  return new NotImplementedError(message);
251
230
  default:
252
231
  return new Error(message);
253
232
  }
254
233
  }
255
- exports.toError = toError;
256
234
  //# sourceMappingURL=errors.js.map