@nr1e/commons 0.0.3-alpha.21 → 0.0.3-alpha.23

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 (41) hide show
  1. package/bitsnbytes/b64.js +1 -1
  2. package/bitsnbytes/b64.js.map +1 -1
  3. package/bitsnbytes/b64.test.d.ts +2 -0
  4. package/bitsnbytes/b64.test.d.ts.map +1 -0
  5. package/bitsnbytes/b64.test.js +55 -0
  6. package/bitsnbytes/b64.test.js.map +1 -0
  7. package/bitsnbytes/index.d.ts +1 -1
  8. package/bitsnbytes/index.d.ts.map +1 -1
  9. package/bitsnbytes/index.js +1 -1
  10. package/bitsnbytes/index.js.map +1 -1
  11. package/errors/errors.d.ts +1 -2
  12. package/errors/errors.d.ts.map +1 -1
  13. package/errors/errors.js +2 -3
  14. package/errors/errors.js.map +1 -1
  15. package/errors/errors.test.d.ts +2 -0
  16. package/errors/errors.test.d.ts.map +1 -0
  17. package/errors/errors.test.js +44 -0
  18. package/errors/errors.test.js.map +1 -0
  19. package/errors/index.d.ts +1 -1
  20. package/errors/index.d.ts.map +1 -1
  21. package/errors/index.js +1 -1
  22. package/errors/index.js.map +1 -1
  23. package/http/index.d.ts +2 -2
  24. package/http/index.d.ts.map +1 -1
  25. package/http/index.js +2 -2
  26. package/http/index.js.map +1 -1
  27. package/lang/index.d.ts +2 -2
  28. package/lang/index.d.ts.map +1 -1
  29. package/lang/index.js +2 -2
  30. package/lang/index.js.map +1 -1
  31. package/package.json +1 -1
  32. package/validator/index.d.ts +1 -1
  33. package/validator/index.d.ts.map +1 -1
  34. package/validator/index.js +1 -1
  35. package/validator/index.js.map +1 -1
  36. package/validator/validators.js +1 -1
  37. package/validator/validators.js.map +1 -1
  38. package/validator/validators.test.d.ts +2 -0
  39. package/validator/validators.test.d.ts.map +1 -0
  40. package/validator/validators.test.js +176 -0
  41. package/validator/validators.test.js.map +1 -0
package/bitsnbytes/b64.js CHANGED
@@ -1,4 +1,4 @@
1
- import { IllegalArgumentError } from '../errors';
1
+ import { IllegalArgumentError } from '../errors/errors.js';
2
2
  // eslint-disable-next-line node/no-unsupported-features/node-builtins
3
3
  const encoder = new TextEncoder();
4
4
  // eslint-disable-next-line node/no-unsupported-features/node-builtins
@@ -1 +1 @@
1
- {"version":3,"file":"b64.js","sourceRoot":"","sources":["../../src/bitsnbytes/b64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,WAAW,CAAC;AAE/C,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,MAAM,CAAC,MAAM,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,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,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,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,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';\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"]}
1
+ {"version":3,"file":"b64.js","sourceRoot":"","sources":["../../src/bitsnbytes/b64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAEzD,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,MAAM,CAAC,MAAM,YAAY,GAAe,IAAI,UA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,IAAI,QAAQ,CAAC,MAAM,KAAK,EAAE,EAAE;oBAC1B,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;oBACxB,GAAG,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
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0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vZiBwaSIgLS0gU3A-',
43
+ 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gUw--',
44
+ '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,8E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AG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,EAAC,QAAQ,EAAE,KAAK,EAAC,CAAC,CAC7D,CAAC;KACH;AACH,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 'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZ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XB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaQ--',\n ];\n for (let i = 0; i < b64s.length; i++) {\n expect(b64s[i]).toBe(\n stob64s(str.substring(0, str.length - i), {b64chars: 'yui'})\n );\n }\n});\n"]}
@@ -1,2 +1,2 @@
1
- export * from './b64';
1
+ export * from './b64.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bitsnbytes/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bitsnbytes/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
@@ -1,2 +1,2 @@
1
- export * from './b64';
1
+ export * from './b64.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bitsnbytes/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC","sourcesContent":["export * from './b64';\n"]}
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.
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAEhC;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,KAAK;IAC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yB,CAEhC;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAM,YAAW,SAAS;IACjE,QAAQ,CAAC,UAAU,kCAAkC;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,6 +1,5 @@
1
- import { HttpStatusCode } from '../http';
2
- import { isError, isObject } from '../lang';
3
- export { isError } from '../lang';
1
+ import { HttpStatusCode } from '../http/index.js';
2
+ import { isError, isObject } from '../lang/index.js';
4
3
  /**
5
4
  * Checks if the given parameter is an HttpError.
6
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,SAAS,CAAC;AACvC,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAahC;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,CAAW;IACrC,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KA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O,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC7B;AACH,CAAC","sourcesContent":["import {HttpStatusCode} from '../http';\nimport {isError, isObject} from '../lang';\nexport {isError} from '../lang';\n\n/**\n * An extended version of Error that includes an HttpStatusCode.\n * This can be useful in middleware error handlers to determine http status codes to return to the client.\n */\nexport interface HttpError extends Error {\n /**\n * The HTTP status code.\n */\n statusCode: HttpStatusCode | number;\n}\n\n/**\n * Checks if the given parameter is an HttpError.\n *\n * @param e The parameter to check\n */\nexport function isHttpError(e?: unknown): e is HttpError {\n return isObject(e) && !!(e && e.stack && e.statusCode && e.message && e.name);\n}\n\n/**\n * Thrown when a resource cannot be found.\n */\nexport class NotFoundError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.NOT_FOUND;\n /**\n * The max-age value to set in the Cache-Control header if used in a middleware.\n */\n readonly maxAge?: number;\n constructor(message?: string, maxAge?: number) {\n message = message ?? 'Not found';\n super(message);\n this.name = 'NotFoundError';\n this.maxAge = maxAge;\n }\n}\n\n/**\n * Checks if the given parameter is a NotFoundError.\n *\n * @param e The parameter to check\n */\nexport function isNotFoundError(e?: unknown): e is NotFoundError {\n return isHttpError(e) && e.name === 'NotFoundError';\n}\n\n/**\n * Thrown when a request is missing authentication credentials.\n */\nexport class UnauthorizedError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.UNAUTHORIZED;\n constructor(message?: string) {\n message = message ?? 'Unauthorized';\n super(message);\n this.name = 'UnauthorizedError';\n }\n}\n\n/**\n * Checks if the given parameter is a UnauthorizedError.\n *\n * @param e The parameter to check\n */\nexport function isUnauthorizedError(e?: unknown): e is UnauthorizedError {\n return isHttpError(e) && e.name === 'UnauthorizedError';\n}\n\n/**\n * Thrown when credentials are present, but the requested operations is not allowed.\n */\nexport class ForbiddenError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.FORBIDDEN;\n constructor(message?: string) {\n message = message ?? 'Forbidden';\n super(message);\n this.name = 'ForbiddenError';\n }\n}\n\n/**\n * Checks if the given parameter is a ForbiddenError.\n *\n * @param e The parameter to check\n */\nexport function isForbiddenError(e?: unknown): e is ForbiddenError {\n return isHttpError(e) && e.name === 'ForbiddenError';\n}\n\n/**\n * Thrown when a validation error occurs.\n */\nexport class ValidationError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.BAD_REQUEST;\n constructor(message?: string) {\n message = message ?? 'Validation error';\n super(message);\n this.name = 'ValidationError';\n }\n}\n\n/**\n * Checks if the given variable is a ValidationError.\n *\n * @param e The variable to check\n */\nexport function isValidationError(e?: unknown): e is ValidationError {\n return isHttpError(e) && e.name === 'ValidationError';\n}\n\n/**\n * Thrown when a bad request is made.\n */\nexport class BadRequestError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.BAD_REQUEST;\n constructor(message?: string) {\n message = message ?? 'Bad request';\n super(message ?? 'Bad request');\n this.name = 'BadRequestError';\n }\n}\n\n/**\n * Checks if the given parameter is a BadRequestError.\n *\n * @param e The parameter to check\n */\nexport function isBadRequestError(e?: unknown): e is BadRequestError {\n return isHttpError(e) && e.name === 'BadRequestError';\n}\n\n/**\n * Throws when an internal server error occurs.\n */\nexport class InternalServerError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR;\n constructor(message?: string) {\n message = message ?? 'Internal server error';\n super(message);\n this.name = 'InternalServerError';\n }\n}\n\n/**\n * Checks if the given parameter is a InternalServerError.\n *\n * @param e The parameter to check\n */\nexport function isInternalServerError(e?: unknown): e is InternalServerError {\n return isHttpError(e) && e.name === 'InternalServerError';\n}\n\n/**\n * Thrown when a conflict occurs.\n */\nexport class ConflictError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.CONFLICT;\n constructor(message?: string) {\n message = message ?? 'Conflict';\n super(message);\n this.name = 'ConflictError';\n }\n}\n\n/**\n * Checks if the given parameter is a ConflictError.\n *\n * @param e The parameter to check\n */\nexport function isConflictError(e?: unknown): e is ConflictError {\n return isHttpError(e) && e.name === 'ConflictError';\n}\n\n/**\n * Thrown when a unsupported media type is used.\n */\nexport class UnsupportedMediaTypeError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;\n constructor(message?: string) {\n message = message ?? 'Unsupported media type';\n super(message);\n this.name = 'UnsupportedMediaTypeError';\n }\n}\n\n/**\n * Checks if the given parameter is a UnsupportedMediaTypeError.\n *\n * @param e The parameter to check\n */\nexport function isUnsupportedMediaTypeError(\n e?: unknown\n): e is UnsupportedMediaTypeError {\n return isHttpError(e) && e.name === 'UnsupportedMediaTypeError';\n}\n\n/**\n * Thrown when a requested operation is not implemented.\n */\nexport class NotImplementedError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.NOT_IMPLEMENTED;\n readonly expose = true;\n constructor(message?: string) {\n message = message ?? 'Not implemented';\n super(message);\n this.name = 'NotImplementedError';\n }\n}\n\n/**\n * Checks if the given parameter is a NotImplementedError.\n *\n * @param e The parameter to check\n */\nexport function isNotImplementedError(e?: unknown): e is NotImplementedError {\n return isHttpError(e) && e.name === 'NotImplementedError';\n}\n\n/**\n * Thrown when an illegal argument is passed to a function.\n */\nexport class IllegalArgumentError extends Error {\n readonly argName: string;\n constructor(argName: string, message?: string) {\n message = message ?? `Illegal argument ${argName}`;\n super(message);\n this.argName = argName;\n this.name = 'IllegalArgumentError';\n }\n}\n\n/**\n * Checks if the given parameter is a IllegalArgumentError.\n *\n * @param e The parameter to check\n */\nexport function isIllegalArgumentError(e?: unknown): e is IllegalArgumentError {\n return isError(e) && e.name === 'IllegalArgumentError';\n}\n\n/**\n * Converts the given parameter to an HttpError.\n *\n * @param code The HTTP status code\n * @param message The error message\n */\nexport function toError(\n code: number | HttpStatusCode,\n message?: string\n): Error {\n switch (code) {\n case HttpStatusCode.NOT_FOUND:\n return new NotFoundError(message);\n case HttpStatusCode.FORBIDDEN:\n return new ForbiddenError(message);\n case HttpStatusCode.BAD_REQUEST:\n return new BadRequestError(message);\n case HttpStatusCode.INTERNAL_SERVER_ERROR:\n return new InternalServerError(message);\n case HttpStatusCode.CONFLICT:\n return new ConflictError(message);\n case HttpStatusCode.UNSUPPORTED_MEDIA_TYPE:\n return new UnsupportedMediaTypeError(message);\n case HttpStatusCode.NOT_IMPLEMENTED:\n return new NotImplementedError(message);\n default:\n return new Error(message);\n }\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAanD;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,CAAW;IACrC,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AAChF,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,UAAU,GAAG,cAAc,CAAC,SAAS,CAAC;IAC/C;;OAEG;IACM,MAAM,CAAU;IACzB,YAAY,OAAgB,EAAE,MAAe;QAC3C,OAAO,GAAG,OAAO,IAAI,WAAW,CAAC;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,CAAW;IACzC,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,eAAe,CAAC;AACtD,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,UAAU,GAAG,cAAc,CAAC,YAAY,CAAC;IAClD,YAAY,OAAgB;QAC1B,OAAO,GAAG,OAAO,IA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AO,CAAC,CAAC;QACpC,KAAK,cAAc,CAAC,SAAS;YAC3B,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QACrC,KAAK,cAAc,CAAC,WAAW;YAC7B,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;QACtC,KAAK,cAAc,CAAC,qBAAqB;YACvC,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC1C,KAAK,cAAc,CAAC,QAAQ;YAC1B,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QACpC,KAAK,cAAc,CAAC,sBAAsB;YACxC,OAAO,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;QAChD,KAAK,cAAc,CAAC,eAAe;YACjC,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC1C;YACE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC7B;AACH,CAAC","sourcesContent":["import {HttpStatusCode} from '../http/index.js';\nimport {isError, isObject} from '../lang/index.js';\n\n/**\n * An extended version of Error that includes an HttpStatusCode.\n * This can be useful in middleware error handlers to determine http status codes to return to the client.\n */\nexport interface HttpError extends Error {\n /**\n * The HTTP status code.\n */\n statusCode: HttpStatusCode | number;\n}\n\n/**\n * Checks if the given parameter is an HttpError.\n *\n * @param e The parameter to check\n */\nexport function isHttpError(e?: unknown): e is HttpError {\n return isObject(e) && !!(e && e.stack && e.statusCode && e.message && e.name);\n}\n\n/**\n * Thrown when a resource cannot be found.\n */\nexport class NotFoundError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.NOT_FOUND;\n /**\n * The max-age value to set in the Cache-Control header if used in a middleware.\n */\n readonly maxAge?: number;\n constructor(message?: string, maxAge?: number) {\n message = message ?? 'Not found';\n super(message);\n this.name = 'NotFoundError';\n this.maxAge = maxAge;\n }\n}\n\n/**\n * Checks if the given parameter is a NotFoundError.\n *\n * @param e The parameter to check\n */\nexport function isNotFoundError(e?: unknown): e is NotFoundError {\n return isHttpError(e) && e.name === 'NotFoundError';\n}\n\n/**\n * Thrown when a request is missing authentication credentials.\n */\nexport class UnauthorizedError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.UNAUTHORIZED;\n constructor(message?: string) {\n message = message ?? 'Unauthorized';\n super(message);\n this.name = 'UnauthorizedError';\n }\n}\n\n/**\n * Checks if the given parameter is a UnauthorizedError.\n *\n * @param e The parameter to check\n */\nexport function isUnauthorizedError(e?: unknown): e is UnauthorizedError {\n return isHttpError(e) && e.name === 'UnauthorizedError';\n}\n\n/**\n * Thrown when credentials are present, but the requested operations is not allowed.\n */\nexport class ForbiddenError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.FORBIDDEN;\n constructor(message?: string) {\n message = message ?? 'Forbidden';\n super(message);\n this.name = 'ForbiddenError';\n }\n}\n\n/**\n * Checks if the given parameter is a ForbiddenError.\n *\n * @param e The parameter to check\n */\nexport function isForbiddenError(e?: unknown): e is ForbiddenError {\n return isHttpError(e) && e.name === 'ForbiddenError';\n}\n\n/**\n * Thrown when a validation error occurs.\n */\nexport class ValidationError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.BAD_REQUEST;\n constructor(message?: string) {\n message = message ?? 'Validation error';\n super(message);\n this.name = 'ValidationError';\n }\n}\n\n/**\n * Checks if the given variable is a ValidationError.\n *\n * @param e The variable to check\n */\nexport function isValidationError(e?: unknown): e is ValidationError {\n return isHttpError(e) && e.name === 'ValidationError';\n}\n\n/**\n * Thrown when a bad request is made.\n */\nexport class BadRequestError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.BAD_REQUEST;\n constructor(message?: string) {\n message = message ?? 'Bad request';\n super(message ?? 'Bad request');\n this.name = 'BadRequestError';\n }\n}\n\n/**\n * Checks if the given parameter is a BadRequestError.\n *\n * @param e The parameter to check\n */\nexport function isBadRequestError(e?: unknown): e is BadRequestError {\n return isHttpError(e) && e.name === 'BadRequestError';\n}\n\n/**\n * Throws when an internal server error occurs.\n */\nexport class InternalServerError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR;\n constructor(message?: string) {\n message = message ?? 'Internal server error';\n super(message);\n this.name = 'InternalServerError';\n }\n}\n\n/**\n * Checks if the given parameter is a InternalServerError.\n *\n * @param e The parameter to check\n */\nexport function isInternalServerError(e?: unknown): e is InternalServerError {\n return isHttpError(e) && e.name === 'InternalServerError';\n}\n\n/**\n * Thrown when a conflict occurs.\n */\nexport class ConflictError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.CONFLICT;\n constructor(message?: string) {\n message = message ?? 'Conflict';\n super(message);\n this.name = 'ConflictError';\n }\n}\n\n/**\n * Checks if the given parameter is a ConflictError.\n *\n * @param e The parameter to check\n */\nexport function isConflictError(e?: unknown): e is ConflictError {\n return isHttpError(e) && e.name === 'ConflictError';\n}\n\n/**\n * Thrown when a unsupported media type is used.\n */\nexport class UnsupportedMediaTypeError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;\n constructor(message?: string) {\n message = message ?? 'Unsupported media type';\n super(message);\n this.name = 'UnsupportedMediaTypeError';\n }\n}\n\n/**\n * Checks if the given parameter is a UnsupportedMediaTypeError.\n *\n * @param e The parameter to check\n */\nexport function isUnsupportedMediaTypeError(\n e?: unknown\n): e is UnsupportedMediaTypeError {\n return isHttpError(e) && e.name === 'UnsupportedMediaTypeError';\n}\n\n/**\n * Thrown when a requested operation is not implemented.\n */\nexport class NotImplementedError extends Error implements HttpError {\n readonly statusCode = HttpStatusCode.NOT_IMPLEMENTED;\n readonly expose = true;\n constructor(message?: string) {\n message = message ?? 'Not implemented';\n super(message);\n this.name = 'NotImplementedError';\n }\n}\n\n/**\n * Checks if the given parameter is a NotImplementedError.\n *\n * @param e The parameter to check\n */\nexport function isNotImplementedError(e?: unknown): e is NotImplementedError {\n return isHttpError(e) && e.name === 'NotImplementedError';\n}\n\n/**\n * Thrown when an illegal argument is passed to a function.\n */\nexport class IllegalArgumentError extends Error {\n readonly argName: string;\n constructor(argName: string, message?: string) {\n message = message ?? `Illegal argument ${argName}`;\n super(message);\n this.argName = argName;\n this.name = 'IllegalArgumentError';\n }\n}\n\n/**\n * Checks if the given parameter is a IllegalArgumentError.\n *\n * @param e The parameter to check\n */\nexport function isIllegalArgumentError(e?: unknown): e is IllegalArgumentError {\n return isError(e) && e.name === 'IllegalArgumentError';\n}\n\n/**\n * Converts the given parameter to an HttpError.\n *\n * @param code The HTTP status code\n * @param message The error message\n */\nexport function toError(\n code: number | HttpStatusCode,\n message?: string\n): Error {\n switch (code) {\n case HttpStatusCode.NOT_FOUND:\n return new NotFoundError(message);\n case HttpStatusCode.FORBIDDEN:\n return new ForbiddenError(message);\n case HttpStatusCode.BAD_REQUEST:\n return new BadRequestError(message);\n case HttpStatusCode.INTERNAL_SERVER_ERROR:\n return new InternalServerError(message);\n case HttpStatusCode.CONFLICT:\n return new ConflictError(message);\n case HttpStatusCode.UNSUPPORTED_MEDIA_TYPE:\n return new UnsupportedMediaTypeError(message);\n case HttpStatusCode.NOT_IMPLEMENTED:\n return new NotImplementedError(message);\n default:\n return new Error(message);\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=errors.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../../src/errors/errors.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ import { BadRequestError, ForbiddenError, InternalServerError, isBadRequestError, isForbiddenError, isInternalServerError, isNotFoundError, isValidationError, NotFoundError, toError, ValidationError, } from './errors.js';
2
+ import { HttpStatusCode } from '../http/index.js';
3
+ test('Test isNotFoundError', () => {
4
+ expect(isNotFoundError(undefined)).toBeFalsy();
5
+ expect(isNotFoundError(null)).toBeFalsy();
6
+ expect(isNotFoundError({})).toBeFalsy();
7
+ expect(isNotFoundError(new ForbiddenError('just a test'))).toBeFalsy();
8
+ expect(isNotFoundError(new NotFoundError('just a test'))).toBeTruthy();
9
+ });
10
+ test('Test isForbiddenError', () => {
11
+ expect(isForbiddenError(undefined)).toBeFalsy();
12
+ expect(isForbiddenError(null)).toBeFalsy();
13
+ expect(isForbiddenError({})).toBeFalsy();
14
+ expect(isForbiddenError(new NotFoundError('just a test'))).toBeFalsy();
15
+ expect(isForbiddenError(new ForbiddenError('just a test'))).toBeTruthy();
16
+ });
17
+ test('Test isValidationError', () => {
18
+ expect(isValidationError(undefined)).toBeFalsy();
19
+ expect(isValidationError(null)).toBeFalsy();
20
+ expect(isValidationError({})).toBeFalsy();
21
+ expect(isValidationError(new NotFoundError('just a test'))).toBeFalsy();
22
+ expect(isValidationError(new ValidationError('just a test'))).toBeTruthy();
23
+ });
24
+ test('Test isBadRequestError', () => {
25
+ expect(isBadRequestError(undefined)).toBeFalsy();
26
+ expect(isBadRequestError(null)).toBeFalsy();
27
+ expect(isBadRequestError({})).toBeFalsy();
28
+ expect(isBadRequestError(new NotFoundError('just a test'))).toBeFalsy();
29
+ expect(isBadRequestError(new BadRequestError('just a test'))).toBeTruthy();
30
+ });
31
+ test('Test isInternalServerError', () => {
32
+ expect(isInternalServerError(undefined)).toBeFalsy();
33
+ expect(isInternalServerError(null)).toBeFalsy();
34
+ expect(isInternalServerError({})).toBeFalsy();
35
+ expect(isInternalServerError(new NotFoundError('just a test'))).toBeFalsy();
36
+ expect(isInternalServerError(new InternalServerError('just a test'))).toBeTruthy();
37
+ });
38
+ test('Test toError', () => {
39
+ expect(isNotFoundError(toError(HttpStatusCode.NOT_FOUND, 'some message'))).toBeTruthy();
40
+ expect(isForbiddenError(toError(HttpStatusCode.FORBIDDEN, 'some message'))).toBeTruthy();
41
+ expect(isBadRequestError(toError(HttpStatusCode.BAD_REQUEST, 'some message'))).toBeTruthy();
42
+ expect(isInternalServerError(toError(HttpStatusCode.INTERNAL_SERVER_ERROR, 'some message'))).toBeTruthy();
43
+ });
44
+ //# sourceMappingURL=errors.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAC9C,MAAM,CAAC,qBAAqB,CAAC,IAAI,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAC5E,MAAM,CACJ,qBAAqB,CAAC,IAAI,mBAAmB,CAAC,aAAa,CAAC,CAAC,CAC9D,CAAC,UAAU,EAAE,CAAC;AACjB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE;IACxB,MAAM,CACJ,eAAe,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CACnE,CAAC,UAAU,EAAE,CAAC;IACf,MAAM,CACJ,gBAAgB,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CACpE,CAAC,UAAU,EAAE,CAAC;IACf,MAAM,CACJ,iBAAiB,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CACvE,CAAC,UAAU,EAAE,CAAC;IACf,MAAM,CACJ,qBAAqB,CACnB,OAAO,CAAC,cAAc,CAAC,qBAAqB,EAAE,cAAc,CAAC,CAC9D,CACF,CAAC,UAAU,EAAE,CAAC;AACjB,CAAC,CAAC,CAAC","sourcesContent":["import {\n BadRequestError,\n ForbiddenError,\n InternalServerError,\n isBadRequestError,\n isForbiddenError,\n isInternalServerError,\n isNotFoundError,\n isValidationError,\n NotFoundError,\n toError,\n ValidationError,\n} from './errors.js';\nimport {HttpStatusCode} from '../http/index.js';\n\ntest('Test isNotFoundError', () => {\n expect(isNotFoundError(undefined)).toBeFalsy();\n expect(isNotFoundError(null)).toBeFalsy();\n expect(isNotFoundError({})).toBeFalsy();\n expect(isNotFoundError(new ForbiddenError('just a test'))).toBeFalsy();\n expect(isNotFoundError(new NotFoundError('just a test'))).toBeTruthy();\n});\n\ntest('Test isForbiddenError', () => {\n expect(isForbiddenError(undefined)).toBeFalsy();\n expect(isForbiddenError(null)).toBeFalsy();\n expect(isForbiddenError({})).toBeFalsy();\n expect(isForbiddenError(new NotFoundError('just a test'))).toBeFalsy();\n expect(isForbiddenError(new ForbiddenError('just a test'))).toBeTruthy();\n});\n\ntest('Test isValidationError', () => {\n expect(isValidationError(undefined)).toBeFalsy();\n expect(isValidationError(null)).toBeFalsy();\n expect(isValidationError({})).toBeFalsy();\n expect(isValidationError(new NotFoundError('just a test'))).toBeFalsy();\n expect(isValidationError(new ValidationError('just a test'))).toBeTruthy();\n});\n\ntest('Test isBadRequestError', () => {\n expect(isBadRequestError(undefined)).toBeFalsy();\n expect(isBadRequestError(null)).toBeFalsy();\n expect(isBadRequestError({})).toBeFalsy();\n expect(isBadRequestError(new NotFoundError('just a test'))).toBeFalsy();\n expect(isBadRequestError(new BadRequestError('just a test'))).toBeTruthy();\n});\n\ntest('Test isInternalServerError', () => {\n expect(isInternalServerError(undefined)).toBeFalsy();\n expect(isInternalServerError(null)).toBeFalsy();\n expect(isInternalServerError({})).toBeFalsy();\n expect(isInternalServerError(new NotFoundError('just a test'))).toBeFalsy();\n expect(\n isInternalServerError(new InternalServerError('just a test'))\n ).toBeTruthy();\n});\n\ntest('Test toError', () => {\n expect(\n isNotFoundError(toError(HttpStatusCode.NOT_FOUND, 'some message'))\n ).toBeTruthy();\n expect(\n isForbiddenError(toError(HttpStatusCode.FORBIDDEN, 'some message'))\n ).toBeTruthy();\n expect(\n isBadRequestError(toError(HttpStatusCode.BAD_REQUEST, 'some message'))\n ).toBeTruthy();\n expect(\n isInternalServerError(\n toError(HttpStatusCode.INTERNAL_SERVER_ERROR, 'some message')\n )\n ).toBeTruthy();\n});\n"]}
package/errors/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './errors';
1
+ export * from './errors.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
package/errors/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from './errors';
1
+ export * from './errors.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC","sourcesContent":["export * from './errors';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC","sourcesContent":["export * from './errors.js';\n"]}
package/http/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './http-status-code';
2
- export * from './http-method';
1
+ export * from './http-status-code.js';
2
+ export * from './http-method.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC"}
package/http/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './http-status-code';
2
- export * from './http-method';
1
+ export * from './http-status-code.js';
2
+ export * from './http-method.js';
3
3
  //# sourceMappingURL=index.js.map
package/http/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC","sourcesContent":["export * from './http-status-code';\nexport * from './http-method';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './http-status-code.js';\nexport * from './http-method.js';\n"]}
package/lang/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './type-functions';
2
- export * from './sleep';
1
+ export * from './type-functions.js';
2
+ export * from './sleep.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lang/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lang/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC"}
package/lang/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './type-functions';
2
- export * from './sleep';
1
+ export * from './type-functions.js';
2
+ export * from './sleep.js';
3
3
  //# sourceMappingURL=index.js.map
package/lang/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lang/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC","sourcesContent":["export * from './type-functions';\nexport * from './sleep';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lang/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC","sourcesContent":["export * from './type-functions.js';\nexport * from './sleep.js';\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nr1e/commons",
3
3
  "description": "Provides common patterns for validation",
4
- "version": "0.0.3-alpha.21",
4
+ "version": "0.0.3-alpha.23",
5
5
  "type": "module",
6
6
  "author": "NR1E, Inc.",
7
7
  "publishConfig": {
@@ -1,2 +1,2 @@
1
- export * from './validators';
1
+ export * from './validators.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -1,2 +1,2 @@
1
- export * from './validators';
1
+ export * from './validators.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC","sourcesContent":["export * from './validators';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './validators.js';\n"]}
@@ -1,4 +1,4 @@
1
- import { ValidationError } from '../errors';
1
+ import { ValidationError } from '../errors/index.js';
2
2
  /**
3
3
  * Tests if a value is null or undefined.
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/validator/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,WAAW,CAAC;AAE1C;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,CAAW;IACnC,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CACrB,IAAY,EACZ,CAAW;IAEX,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;QACjB,MAAM,IAAI,eAAe,CAAC,GAAG,IAAI,+BAA+B,CAAC,CAAC;KACnE;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,CAAW;IACpC,OAAO,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,C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,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import {ValidationError} from '../errors';\n\n/**\n * Tests if a value is null or undefined.\n *\n * @param o the value to check\n */\nexport function isNotNull(o?: unknown): o is NonNullable<unknown> {\n return o !== undefined && o !== null;\n}\n\n/**\n * Throws a ValidationError if the value is null or undefined.\n * This function also asserts the value to be NonNullable if the check passes.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function notNull(\n name: string,\n o?: unknown\n): asserts o is NonNullable<unknown> {\n if (!isNotNull(o)) {\n throw new ValidationError(`${name} may not be null or undefined`);\n }\n}\n\n/**\n * Tests if a value is empty, null, undefined or has a length of 0.\n *\n * @param o the value to check\n */\nexport function isNotEmpty(o?: unknown): o is NonNullable<unknown> {\n return !(o === undefined || o === null || o.toString().length === 0);\n}\n\n/**\n * Throws a ValidationError if the value is null, undefined or the length is 0.\n * This function also asserts the value to be NonNullable if the check passes.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function notEmpty(\n name: string,\n o?: unknown\n): asserts o is NonNullable<unknown> {\n if (!isNotEmpty(o)) {\n throw new ValidationError(`${name} may not be empty`);\n }\n}\n\n/**\n * Tests if a value is null, undefined, has a length of 0 or contains only whitespace.\n *\n * @param o the value to check\n */\nexport function isNotBlank(o?: unknown): o is NonNullable<unknown> {\n return !(o === undefined || o === null || o.toString().trim().length === 0);\n}\n\n/**\n * Throws a ValidationError if the value is null, undefined, has a length of 0 or contains only whitespace.\n * This function also asserts the value to be NonNullable if the check passes.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function notBlank(\n name: string,\n o?: unknown\n): asserts o is NonNullable<unknown> {\n if (!isNotBlank(o)) {\n throw new ValidationError(`${name} may not be blank`);\n }\n}\n\n/**\n * Tests if a value does not match the regular expression provided.\n * Undefined and null values are skipped and not tested.\n *\n * @param regex the regular expression to test with\n * @param o the value to check\n */\nexport function isMatch(regex: RegExp, o?: string | null): o is string {\n if (o === undefined || o === null) {\n return true;\n }\n return o.match(regex) !== null;\n}\n\n/**\n * Throws a ValidationError if the value matches the regular expression provided.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param regex the regular expression to validate with\n * @param o the value to check\n */\nexport function match(name: string, regex: RegExp, o?: string | null) {\n if (!isMatch(regex, o)) {\n throw new ValidationError(`${name} must match ${regex}`);\n }\n}\n\n/**\n * Tests if a value is a valid email address.\n * Undefined and null values are skipped and not validated.\n *\n * @param o the value to check\n */\nexport function isEmail(o?: string | null): o is string {\n const expression =\n /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;\n return !(o !== undefined && o !== null && !expression.test(o));\n}\n\n/**\n * Throws a ValidationError if the value provided is not an email.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function email(name: string, o?: string | null) {\n if (!isEmail(o)) {\n throw new ValidationError(`${name} is not a valid email address`);\n }\n}\n\n/**\n * Tests if a value has a length that is less than the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param length the maximum length of the variable\n * @param o the value to check\n */\nexport function isMaxLength(length: number, o?: string | unknown[] | null) {\n return !(o !== undefined && o !== null && o.length > length);\n}\n\n/**\n * Throws a ValidationError if the value provided has a length that exceeds the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param length the maximum length of the variable\n * @param o the value to check\n */\nexport function maxLength(\n name: string,\n length: number,\n o?: string | unknown[] | null\n) {\n if (!isMaxLength(length, o)) {\n throw new ValidationError(`length of ${name} may not exceed ${length}`);\n }\n}\n\n/**\n * Tests if a value has a length that is greater than the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param length the minimum length of the variable\n * @param o the value to check\n */\nexport function isMinLength(length: number, o?: string | unknown[] | null) {\n return !(o !== undefined && o !== null && o.length < length);\n}\n\n/**\n * Throws a ValidationError if the value provided has a length that is less than the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param length the minimum length of the variable\n * @param o the value to check\n */\nexport function minLength(\n name: string,\n length: number,\n o?: string | unknown[] | null\n) {\n if (!isMinLength(length, o)) {\n throw new ValidationError(\n `length of ${name} may not be less than ${length}`\n );\n }\n}\n\n/**\n * Tests if a value provided is a number.\n * Undefined and null values are skipped and not validated.\n *\n * @param o the value to check\n */\nexport function isNumber(o?: string | null | number): boolean {\n return o === undefined || o === null || !isNaN(+o);\n}\n\n/**\n * Throws a ValidationError if the value provided is not a number.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function number(name: string, o?: string | null | number) {\n if (!isNumber(o)) {\n throw new ValidationError(`${name} is not a number`);\n }\n}\n\n/**\n * Tests if a value is less than the provided minimum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param minValue the minimum value allowed\n * @param o the value to check\n */\nexport function isMinValue(minValue: number, o?: string | number | null) {\n return o === undefined || o === null || +o >= minValue;\n}\n\n/**\n * Throws a ValidationError if the value is less than the provided minimum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param minValue the minimum value allowed\n * @param o the value to check\n */\nexport function minValue(\n name: string,\n minValue: number,\n o?: number | string | null\n) {\n if (!isMinValue(minValue, o)) {\n throw new ValidationError(`${name} may not be less than ${minValue}`);\n }\n}\n\n/**\n * Tests if a value is more than the provided maximum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function isMaxValue(\n maxValue: number,\n o?: string | number | null\n): boolean {\n return !(o !== undefined && o !== null && +o > maxValue);\n}\n\n/**\n * Throws a ValidationError if the value is more than the provided maximum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function maxValue(\n name: string,\n maxValue: number,\n o?: number | string | null\n) {\n if (!isMaxValue(maxValue, o)) {\n throw new ValidationError(`${name} may not be greater than ${maxValue}`);\n }\n}\n\n/**\n * Tests if the value is between the provided minimum and maximum values inclusive.\n * Undefined and null values are skipped and not validated.\n *\n * @param minValue the minimum value allowed\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function isBetweenValues(\n minValue: number,\n maxValue: number,\n o?: string | number | null\n): boolean {\n return !(o !== undefined && o !== null && (+o < minValue || +o > maxValue));\n}\n\n/**\n * Throws a ValidationError if the value is not between the provided minimum and maximum values inclusive.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param minValue the minimum value allowed\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function betweenValues(\n name: string,\n minValue: number,\n maxValue: number,\n o?: string | number | null\n) {\n if (!isBetweenValues(minValue, maxValue, o)) {\n throw new ValidationError(\n `${name} must be between ${minValue} and ${maxValue}`\n );\n }\n}\n\nconst isString = (value: unknown): value is string => typeof value === 'string';\n\nexport interface StringValidationOptions {\n readonly required: boolean;\n readonly minLength?: number;\n readonly maxLength?: number;\n readonly regex?: RegExp;\n readonly notBlank?: boolean;\n readonly notEmpty?: boolean;\n readonly email?: boolean;\n readonly number?: boolean;\n}\n\nexport function isValidString(\n options: StringValidationOptions,\n value?: unknown\n): value is string {\n if (options.required) {\n if (!isNotNull(value)) {\n return false;\n }\n } else if (value === undefined || value === null) {\n return true;\n }\n if (!isString(value)) {\n return false;\n }\n if (options.minLength && !isMinLength(options.minLength, value)) {\n return false;\n }\n if (options.maxLength && !isMaxLength(options.maxLength, value)) {\n return false;\n }\n if (options.regex && !isMatch(options.regex, value)) {\n return false;\n }\n if (options.notBlank && !isNotBlank(value)) {\n return false;\n }\n if (options.notEmpty && !isNotEmpty(value)) {\n return false;\n }\n if (options.email && !isEmail(value)) {\n return false;\n }\n if (options.number && !isNumber(value)) {\n return false;\n }\n return true;\n}\n\nexport function validString(\n name: string,\n options: StringValidationOptions,\n value?: unknown\n): void {\n if (options.required) {\n notNull(name, value);\n } else if (value === undefined || value === null) {\n return;\n }\n if (!isString(value)) {\n throw new ValidationError(`${name} must be a string`);\n }\n options.minLength && minLength(name, options.minLength, value);\n options.maxLength && maxLength(name, options.maxLength, value);\n options.regex && match(name, options.regex, value);\n options.notBlank && notBlank(name, value);\n options.notEmpty && notEmpty(name, value);\n options.email && email(name, value);\n options.number && number(name, value);\n}\n"]}
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/validator/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAEnD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,CAAW;IACnC,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CACrB,IAAY,EACZ,CAAW;IAEX,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;QACjB,MAAM,IAAI,eAAe,CAAC,GAAG,IAAI,+BAA+B,CAAC,CAAC;KACnE;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,CAAW;IACpC,OAAO,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;AACvE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CACtB,IAAY,EACZ,CAAW;IAEX,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;QAClB,MAAM,IAAI,eAAe,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;KACvD;AAC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C,EAAE;QACpC,OAAO,KAAK,CAAC;KACd;IACD,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACtC,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,IAAY,EACZ,OAAgC,EAChC,KAAe;IAEf,IAAI,OAAO,CAAC,QAAQ,EAAE;QACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;KACtB;SAAM,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE;QAChD,OAAO;KACR;IACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACpB,MAAM,IAAI,eAAe,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;KACvD;IACD,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC/D,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC/D,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1C,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import {ValidationError} from '../errors/index.js';\n\n/**\n * Tests if a value is null or undefined.\n *\n * @param o the value to check\n */\nexport function isNotNull(o?: unknown): o is NonNullable<unknown> {\n return o !== undefined && o !== null;\n}\n\n/**\n * Throws a ValidationError if the value is null or undefined.\n * This function also asserts the value to be NonNullable if the check passes.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function notNull(\n name: string,\n o?: unknown\n): asserts o is NonNullable<unknown> {\n if (!isNotNull(o)) {\n throw new ValidationError(`${name} may not be null or undefined`);\n }\n}\n\n/**\n * Tests if a value is empty, null, undefined or has a length of 0.\n *\n * @param o the value to check\n */\nexport function isNotEmpty(o?: unknown): o is NonNullable<unknown> {\n return !(o === undefined || o === null || o.toString().length === 0);\n}\n\n/**\n * Throws a ValidationError if the value is null, undefined or the length is 0.\n * This function also asserts the value to be NonNullable if the check passes.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function notEmpty(\n name: string,\n o?: unknown\n): asserts o is NonNullable<unknown> {\n if (!isNotEmpty(o)) {\n throw new ValidationError(`${name} may not be empty`);\n }\n}\n\n/**\n * Tests if a value is null, undefined, has a length of 0 or contains only whitespace.\n *\n * @param o the value to check\n */\nexport function isNotBlank(o?: unknown): o is NonNullable<unknown> {\n return !(o === undefined || o === null || o.toString().trim().length === 0);\n}\n\n/**\n * Throws a ValidationError if the value is null, undefined, has a length of 0 or contains only whitespace.\n * This function also asserts the value to be NonNullable if the check passes.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function notBlank(\n name: string,\n o?: unknown\n): asserts o is NonNullable<unknown> {\n if (!isNotBlank(o)) {\n throw new ValidationError(`${name} may not be blank`);\n }\n}\n\n/**\n * Tests if a value does not match the regular expression provided.\n * Undefined and null values are skipped and not tested.\n *\n * @param regex the regular expression to test with\n * @param o the value to check\n */\nexport function isMatch(regex: RegExp, o?: string | null): o is string {\n if (o === undefined || o === null) {\n return true;\n }\n return o.match(regex) !== null;\n}\n\n/**\n * Throws a ValidationError if the value matches the regular expression provided.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param regex the regular expression to validate with\n * @param o the value to check\n */\nexport function match(name: string, regex: RegExp, o?: string | null) {\n if (!isMatch(regex, o)) {\n throw new ValidationError(`${name} must match ${regex}`);\n }\n}\n\n/**\n * Tests if a value is a valid email address.\n * Undefined and null values are skipped and not validated.\n *\n * @param o the value to check\n */\nexport function isEmail(o?: string | null): o is string {\n const expression =\n /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;\n return !(o !== undefined && o !== null && !expression.test(o));\n}\n\n/**\n * Throws a ValidationError if the value provided is not an email.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function email(name: string, o?: string | null) {\n if (!isEmail(o)) {\n throw new ValidationError(`${name} is not a valid email address`);\n }\n}\n\n/**\n * Tests if a value has a length that is less than the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param length the maximum length of the variable\n * @param o the value to check\n */\nexport function isMaxLength(length: number, o?: string | unknown[] | null) {\n return !(o !== undefined && o !== null && o.length > length);\n}\n\n/**\n * Throws a ValidationError if the value provided has a length that exceeds the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param length the maximum length of the variable\n * @param o the value to check\n */\nexport function maxLength(\n name: string,\n length: number,\n o?: string | unknown[] | null\n) {\n if (!isMaxLength(length, o)) {\n throw new ValidationError(`length of ${name} may not exceed ${length}`);\n }\n}\n\n/**\n * Tests if a value has a length that is greater than the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param length the minimum length of the variable\n * @param o the value to check\n */\nexport function isMinLength(length: number, o?: string | unknown[] | null) {\n return !(o !== undefined && o !== null && o.length < length);\n}\n\n/**\n * Throws a ValidationError if the value provided has a length that is less than the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param length the minimum length of the variable\n * @param o the value to check\n */\nexport function minLength(\n name: string,\n length: number,\n o?: string | unknown[] | null\n) {\n if (!isMinLength(length, o)) {\n throw new ValidationError(\n `length of ${name} may not be less than ${length}`\n );\n }\n}\n\n/**\n * Tests if a value provided is a number.\n * Undefined and null values are skipped and not validated.\n *\n * @param o the value to check\n */\nexport function isNumber(o?: string | null | number): boolean {\n return o === undefined || o === null || !isNaN(+o);\n}\n\n/**\n * Throws a ValidationError if the value provided is not a number.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function number(name: string, o?: string | null | number) {\n if (!isNumber(o)) {\n throw new ValidationError(`${name} is not a number`);\n }\n}\n\n/**\n * Tests if a value is less than the provided minimum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param minValue the minimum value allowed\n * @param o the value to check\n */\nexport function isMinValue(minValue: number, o?: string | number | null) {\n return o === undefined || o === null || +o >= minValue;\n}\n\n/**\n * Throws a ValidationError if the value is less than the provided minimum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param minValue the minimum value allowed\n * @param o the value to check\n */\nexport function minValue(\n name: string,\n minValue: number,\n o?: number | string | null\n) {\n if (!isMinValue(minValue, o)) {\n throw new ValidationError(`${name} may not be less than ${minValue}`);\n }\n}\n\n/**\n * Tests if a value is more than the provided maximum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function isMaxValue(\n maxValue: number,\n o?: string | number | null\n): boolean {\n return !(o !== undefined && o !== null && +o > maxValue);\n}\n\n/**\n * Throws a ValidationError if the value is more than the provided maximum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function maxValue(\n name: string,\n maxValue: number,\n o?: number | string | null\n) {\n if (!isMaxValue(maxValue, o)) {\n throw new ValidationError(`${name} may not be greater than ${maxValue}`);\n }\n}\n\n/**\n * Tests if the value is between the provided minimum and maximum values inclusive.\n * Undefined and null values are skipped and not validated.\n *\n * @param minValue the minimum value allowed\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function isBetweenValues(\n minValue: number,\n maxValue: number,\n o?: string | number | null\n): boolean {\n return !(o !== undefined && o !== null && (+o < minValue || +o > maxValue));\n}\n\n/**\n * Throws a ValidationError if the value is not between the provided minimum and maximum values inclusive.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param minValue the minimum value allowed\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function betweenValues(\n name: string,\n minValue: number,\n maxValue: number,\n o?: string | number | null\n) {\n if (!isBetweenValues(minValue, maxValue, o)) {\n throw new ValidationError(\n `${name} must be between ${minValue} and ${maxValue}`\n );\n }\n}\n\nconst isString = (value: unknown): value is string => typeof value === 'string';\n\nexport interface StringValidationOptions {\n readonly required: boolean;\n readonly minLength?: number;\n readonly maxLength?: number;\n readonly regex?: RegExp;\n readonly notBlank?: boolean;\n readonly notEmpty?: boolean;\n readonly email?: boolean;\n readonly number?: boolean;\n}\n\nexport function isValidString(\n options: StringValidationOptions,\n value?: unknown\n): value is string {\n if (options.required) {\n if (!isNotNull(value)) {\n return false;\n }\n } else if (value === undefined || value === null) {\n return true;\n }\n if (!isString(value)) {\n return false;\n }\n if (options.minLength && !isMinLength(options.minLength, value)) {\n return false;\n }\n if (options.maxLength && !isMaxLength(options.maxLength, value)) {\n return false;\n }\n if (options.regex && !isMatch(options.regex, value)) {\n return false;\n }\n if (options.notBlank && !isNotBlank(value)) {\n return false;\n }\n if (options.notEmpty && !isNotEmpty(value)) {\n return false;\n }\n if (options.email && !isEmail(value)) {\n return false;\n }\n if (options.number && !isNumber(value)) {\n return false;\n }\n return true;\n}\n\nexport function validString(\n name: string,\n options: StringValidationOptions,\n value?: unknown\n): void {\n if (options.required) {\n notNull(name, value);\n } else if (value === undefined || value === null) {\n return;\n }\n if (!isString(value)) {\n throw new ValidationError(`${name} must be a string`);\n }\n options.minLength && minLength(name, options.minLength, value);\n options.maxLength && maxLength(name, options.maxLength, value);\n options.regex && match(name, options.regex, value);\n options.notBlank && notBlank(name, value);\n options.notEmpty && notEmpty(name, value);\n options.email && email(name, value);\n options.number && number(name, value);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validators.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.test.d.ts","sourceRoot":"","sources":["../../src/validator/validators.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,176 @@
1
+ import { betweenValues, email, number, maxLength, maxValue, minLength, minValue, notBlank, notEmpty, notNull, validString, isNotNull, isNotEmpty, isNotBlank, match, isMatch, isEmail, isMaxLength, isMinLength, isNumber, isMinValue, isMaxValue, isBetweenValues, isValidString, } from './validators.js';
2
+ test('Test isNotNull', () => {
3
+ expect(isNotNull('bar')).toBeTruthy();
4
+ expect(isNotNull(null)).toBeFalsy();
5
+ expect(isNotNull(undefined)).toBeFalsy();
6
+ });
7
+ test('Test notNull', () => {
8
+ notNull('foo', 'bar');
9
+ expect(() => notNull('foo', null)).toThrow('foo may not be null or undefined');
10
+ expect(() => notNull('foo', undefined)).toThrow('foo may not be null or undefined');
11
+ });
12
+ test('Test isNotEmpty', () => {
13
+ expect(isNotEmpty('bar')).toBeTruthy();
14
+ expect(isNotEmpty('')).toBeFalsy();
15
+ expect(isNotEmpty(null)).toBeFalsy();
16
+ expect(isNotEmpty(undefined)).toBeFalsy();
17
+ });
18
+ test('Test notEmpty', () => {
19
+ notEmpty('foo', 'bar');
20
+ expect(() => notEmpty('foo', '')).toThrow('foo may not be empty');
21
+ expect(() => notEmpty('foo', null)).toThrow('foo may not be empty');
22
+ expect(() => notEmpty('foo', undefined)).toThrow('foo may not be empty');
23
+ });
24
+ test('Test isNotBlank', () => {
25
+ expect(isNotBlank('bar')).toBeTruthy();
26
+ expect(isNotBlank(' ')).toBeFalsy();
27
+ expect(isNotBlank('')).toBeFalsy();
28
+ expect(isNotBlank(null)).toBeFalsy();
29
+ expect(isNotBlank(undefined)).toBeFalsy();
30
+ });
31
+ test('Test notBlank', () => {
32
+ notBlank('foo', 'bar');
33
+ expect(() => notBlank('foo', ' ')).toThrow('foo may not be blank');
34
+ expect(() => notBlank('foo', '')).toThrow('foo may not be blank');
35
+ expect(() => notBlank('foo', null)).toThrow('foo may not be blank');
36
+ expect(() => notBlank('foo', undefined)).toThrow('foo may not be blank');
37
+ });
38
+ test('Test isMatch', () => {
39
+ expect(isMatch(/bar/, 'bar')).toBeTruthy();
40
+ expect(isMatch(/bar/, null)).toBeTruthy();
41
+ expect(isMatch(/bar/, undefined)).toBeTruthy();
42
+ expect(isMatch(/bar/, 'baz')).toBeFalsy();
43
+ });
44
+ test('Test match', () => {
45
+ match('foo', /bar/, 'bar');
46
+ match('foo', /bar/, null);
47
+ match('foo', /bar/, undefined);
48
+ expect(() => match('foo', /bar/, 'baz')).toThrow('foo must match /bar/');
49
+ });
50
+ test('Test isEmail', () => {
51
+ expect(isEmail('test@example.com')).toBeTruthy();
52
+ expect(isEmail(null)).toBeTruthy();
53
+ expect(isEmail(undefined)).toBeTruthy();
54
+ expect(isEmail('test')).toBeFalsy();
55
+ });
56
+ test('Test email', () => {
57
+ email('foo', 'test@example.com');
58
+ email('foo', null);
59
+ email('foo', undefined);
60
+ expect(() => email('foo', 'test')).toThrow('foo is not a valid email address');
61
+ });
62
+ test('Test isMaxLength', () => {
63
+ const arr = [];
64
+ arr.push('a', 'b', 'c');
65
+ expect(isMaxLength(3, 'bar')).toBeTruthy();
66
+ expect(isMaxLength(3, null)).toBeTruthy();
67
+ expect(isMaxLength(3, undefined)).toBeTruthy();
68
+ expect(isMaxLength(3, arr)).toBeTruthy();
69
+ expect(isMaxLength(2, 'baz')).toBeFalsy();
70
+ expect(isMaxLength(2, arr)).toBeFalsy();
71
+ });
72
+ test('Test maxLength', () => {
73
+ const arr = [];
74
+ arr.push('a', 'b', 'c');
75
+ maxLength('foo', 3, 'bar');
76
+ maxLength('foo', 3, null);
77
+ maxLength('foo', 3, undefined);
78
+ maxLength('foo', 3, arr);
79
+ expect(() => maxLength('foo', 2, 'baz')).toThrow('length of foo may not exceed 2');
80
+ expect(() => maxLength('foo', 2, arr)).toThrow('length of foo may not exceed 2');
81
+ });
82
+ test('Test isMinLength', () => {
83
+ const arr = [];
84
+ arr.push('a', 'b', 'c');
85
+ expect(isMinLength(3, 'bar')).toBeTruthy();
86
+ expect(isMinLength(3, null)).toBeTruthy();
87
+ expect(isMinLength(3, undefined)).toBeTruthy();
88
+ expect(isMinLength(3, arr)).toBeTruthy();
89
+ expect(isMinLength(4, 'baz')).toBeFalsy();
90
+ expect(isMinLength(4, arr)).toBeFalsy();
91
+ });
92
+ test('Test minLength', () => {
93
+ const arr = [];
94
+ arr.push('a', 'b', 'c');
95
+ minLength('foo', 3, 'bar');
96
+ minLength('foo', 3, null);
97
+ minLength('foo', 3, undefined);
98
+ minLength('foo', 3, arr);
99
+ expect(() => minLength('foo', 4, 'baz')).toThrow('length of foo may not be less than 4');
100
+ expect(() => minLength('foo', 4, arr)).toThrow('length of foo may not be less than 4');
101
+ });
102
+ test('Test isNumber', () => {
103
+ expect(isNumber(1)).toBeTruthy();
104
+ expect(isNumber('1')).toBeTruthy();
105
+ expect(isNumber(null)).toBeTruthy();
106
+ expect(isNumber(undefined)).toBeTruthy();
107
+ expect(isNumber('bar')).toBeFalsy();
108
+ });
109
+ test('Test number', () => {
110
+ number('foo', 1);
111
+ number('foo', '1');
112
+ number('foo', null);
113
+ number('foo', undefined);
114
+ expect(() => number('foo', 'bar')).toThrow('foo is not a number');
115
+ });
116
+ test('Test isMinValue', () => {
117
+ expect(isMinValue(1, 2)).toBeTruthy();
118
+ expect(isMinValue(1, '2')).toBeTruthy();
119
+ expect(isMinValue(1, null)).toBeTruthy();
120
+ expect(isMinValue(1, undefined)).toBeTruthy();
121
+ expect(isMinValue(2, 1)).toBeFalsy();
122
+ });
123
+ test('Test minValue', () => {
124
+ minValue('foo', 1, 2);
125
+ minValue('foo', 1, '2');
126
+ minValue('foo', 1, null);
127
+ minValue('foo', 1, undefined);
128
+ expect(() => minValue('foo', 2, 1)).toThrow('foo may not be less than 2');
129
+ });
130
+ test('Test isMaxValue', () => {
131
+ expect(isMaxValue(2, 1)).toBeTruthy();
132
+ expect(isMaxValue(2, '1')).toBeTruthy();
133
+ expect(isMaxValue(2, null)).toBeTruthy();
134
+ expect(isMaxValue(2, undefined)).toBeTruthy();
135
+ expect(isMaxValue(1, 2)).toBeFalsy();
136
+ });
137
+ test('Test maxValue', () => {
138
+ maxValue('foo', 2, 1);
139
+ maxValue('foo', 2, '1');
140
+ maxValue('foo', 2, null);
141
+ maxValue('foo', 2, undefined);
142
+ expect(() => maxValue('foo', 1, 2)).toThrow('foo may not be greater than 1');
143
+ });
144
+ test('Test isBetweenValues', () => {
145
+ expect(isBetweenValues(1, 3, 2)).toBeTruthy();
146
+ expect(isBetweenValues(1, 3, '2')).toBeTruthy();
147
+ expect(isBetweenValues(1, 3, null)).toBeTruthy();
148
+ expect(isBetweenValues(1, 3, undefined)).toBeTruthy();
149
+ expect(isBetweenValues(1, 3, 4)).toBeFalsy();
150
+ });
151
+ test('Test betweenValues', () => {
152
+ betweenValues('foo', 1, 3, 2);
153
+ betweenValues('foo', 1, 3, '2');
154
+ betweenValues('foo', 1, 3, null);
155
+ betweenValues('foo', 1, 3, undefined);
156
+ expect(() => betweenValues('foo', 1, 3, 4)).toThrow('foo must be between 1 and 3');
157
+ });
158
+ test('Test isValidString', () => {
159
+ expect(isValidString({ required: true }, 'bar')).toBeTruthy();
160
+ expect(isValidString({ required: true }, ' ')).toBeTruthy();
161
+ expect(isValidString({ required: true }, '')).toBeTruthy();
162
+ expect(isValidString({ required: false }, null)).toBeTruthy();
163
+ expect(isValidString({ required: false }, undefined)).toBeTruthy();
164
+ expect(isValidString({ required: true }, null)).toBeFalsy();
165
+ expect(isValidString({ required: true }, undefined)).toBeFalsy();
166
+ });
167
+ test('Test validString', () => {
168
+ validString('foo', { required: true }, 'bar');
169
+ validString('foo', { required: true }, ' ');
170
+ validString('foo', { required: true }, '');
171
+ validString('foo', { required: false }, null);
172
+ validString('foo', { required: false }, undefined);
173
+ expect(() => validString('foo', { required: true }, null)).toThrow('foo may not be null or undefined');
174
+ expect(() => validString('foo', { required: true }, undefined)).toThrow('foo may not be null or undefined');
175
+ });
176
+ //# sourceMappingURL=validators.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.test.js","sourceRoot":"","sources":["../../src/validator/validators.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,EACL,MAAM,EACN,SAAS,EACT,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAU,EACV,KAAK,EACL,OAAO,EACP,OAAO,EACP,WAAW,EACX,WAAW,EACX,QAAQ,EACR,UAAU,EACV,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,iBAAiB,CAAC;AAEzB,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC1B,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;IACtC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IACpC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAC3C,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE;IACxB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACtB,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CACxC,kCAAkC,CACnC,CAAC;IACF,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CA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AAI,CAAC,CAAC;IAC5C,WAAW,CAAC,KAAK,EAAE,EAAC,QAAQ,EAAE,KAAK,EAAC,EAAE,SAAS,CAAC,CAAC;IACjD,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAC9D,kCAAkC,CACnC,CAAC;IACF,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CACnE,kCAAkC,CACnC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import {\n betweenValues,\n email,\n number,\n maxLength,\n maxValue,\n minLength,\n minValue,\n notBlank,\n notEmpty,\n notNull,\n validString,\n isNotNull,\n isNotEmpty,\n isNotBlank,\n match,\n isMatch,\n isEmail,\n isMaxLength,\n isMinLength,\n isNumber,\n isMinValue,\n isMaxValue,\n isBetweenValues,\n isValidString,\n} from './validators.js';\n\ntest('Test isNotNull', () => {\n expect(isNotNull('bar')).toBeTruthy();\n expect(isNotNull(null)).toBeFalsy();\n expect(isNotNull(undefined)).toBeFalsy();\n});\n\ntest('Test notNull', () => {\n notNull('foo', 'bar');\n expect(() => notNull('foo', null)).toThrow(\n 'foo may not be null or undefined'\n );\n expect(() => notNull('foo', undefined)).toThrow(\n 'foo may not be null or undefined'\n );\n});\n\ntest('Test isNotEmpty', () => {\n expect(isNotEmpty('bar')).toBeTruthy();\n expect(isNotEmpty('')).toBeFalsy();\n expect(isNotEmpty(null)).toBeFalsy();\n expect(isNotEmpty(undefined)).toBeFalsy();\n});\n\ntest('Test notEmpty', () => {\n notEmpty('foo', 'bar');\n expect(() => notEmpty('foo', '')).toThrow('foo may not be empty');\n expect(() => notEmpty('foo', null)).toThrow('foo may not be empty');\n expect(() => notEmpty('foo', undefined)).toThrow('foo may not be empty');\n});\n\ntest('Test isNotBlank', () => {\n expect(isNotBlank('bar')).toBeTruthy();\n expect(isNotBlank(' ')).toBeFalsy();\n expect(isNotBlank('')).toBeFalsy();\n expect(isNotBlank(null)).toBeFalsy();\n expect(isNotBlank(undefined)).toBeFalsy();\n});\n\ntest('Test notBlank', () => {\n notBlank('foo', 'bar');\n expect(() => notBlank('foo', ' ')).toThrow('foo may not be blank');\n expect(() => notBlank('foo', '')).toThrow('foo may not be blank');\n expect(() => notBlank('foo', null)).toThrow('foo may not be blank');\n expect(() => notBlank('foo', undefined)).toThrow('foo may not be blank');\n});\n\ntest('Test isMatch', () => {\n expect(isMatch(/bar/, 'bar')).toBeTruthy();\n expect(isMatch(/bar/, null)).toBeTruthy();\n expect(isMatch(/bar/, undefined)).toBeTruthy();\n expect(isMatch(/bar/, 'baz')).toBeFalsy();\n});\n\ntest('Test match', () => {\n match('foo', /bar/, 'bar');\n match('foo', /bar/, null);\n match('foo', /bar/, undefined);\n expect(() => match('foo', /bar/, 'baz')).toThrow('foo must match /bar/');\n});\n\ntest('Test isEmail', () => {\n expect(isEmail('test@example.com')).toBeTruthy();\n expect(isEmail(null)).toBeTruthy();\n expect(isEmail(undefined)).toBeTruthy();\n expect(isEmail('test')).toBeFalsy();\n});\n\ntest('Test email', () => {\n email('foo', 'test@example.com');\n email('foo', null);\n email('foo', undefined);\n expect(() => email('foo', 'test')).toThrow(\n 'foo is not a valid email address'\n );\n});\n\ntest('Test isMaxLength', () => {\n const arr: string[] = [];\n arr.push('a', 'b', 'c');\n expect(isMaxLength(3, 'bar')).toBeTruthy();\n expect(isMaxLength(3, null)).toBeTruthy();\n expect(isMaxLength(3, undefined)).toBeTruthy();\n expect(isMaxLength(3, arr)).toBeTruthy();\n expect(isMaxLength(2, 'baz')).toBeFalsy();\n expect(isMaxLength(2, arr)).toBeFalsy();\n});\n\ntest('Test maxLength', () => {\n const arr: string[] = [];\n arr.push('a', 'b', 'c');\n maxLength('foo', 3, 'bar');\n maxLength('foo', 3, null);\n maxLength('foo', 3, undefined);\n maxLength('foo', 3, arr);\n expect(() => maxLength('foo', 2, 'baz')).toThrow(\n 'length of foo may not exceed 2'\n );\n expect(() => maxLength('foo', 2, arr)).toThrow(\n 'length of foo may not exceed 2'\n );\n});\n\ntest('Test isMinLength', () => {\n const arr: string[] = [];\n arr.push('a', 'b', 'c');\n expect(isMinLength(3, 'bar')).toBeTruthy();\n expect(isMinLength(3, null)).toBeTruthy();\n expect(isMinLength(3, undefined)).toBeTruthy();\n expect(isMinLength(3, arr)).toBeTruthy();\n expect(isMinLength(4, 'baz')).toBeFalsy();\n expect(isMinLength(4, arr)).toBeFalsy();\n});\n\ntest('Test minLength', () => {\n const arr: string[] = [];\n arr.push('a', 'b', 'c');\n minLength('foo', 3, 'bar');\n minLength('foo', 3, null);\n minLength('foo', 3, undefined);\n minLength('foo', 3, arr);\n expect(() => minLength('foo', 4, 'baz')).toThrow(\n 'length of foo may not be less than 4'\n );\n expect(() => minLength('foo', 4, arr)).toThrow(\n 'length of foo may not be less than 4'\n );\n});\n\ntest('Test isNumber', () => {\n expect(isNumber(1)).toBeTruthy();\n expect(isNumber('1')).toBeTruthy();\n expect(isNumber(null)).toBeTruthy();\n expect(isNumber(undefined)).toBeTruthy();\n expect(isNumber('bar')).toBeFalsy();\n});\n\ntest('Test number', () => {\n number('foo', 1);\n number('foo', '1');\n number('foo', null);\n number('foo', undefined);\n expect(() => number('foo', 'bar')).toThrow('foo is not a number');\n});\n\ntest('Test isMinValue', () => {\n expect(isMinValue(1, 2)).toBeTruthy();\n expect(isMinValue(1, '2')).toBeTruthy();\n expect(isMinValue(1, null)).toBeTruthy();\n expect(isMinValue(1, undefined)).toBeTruthy();\n expect(isMinValue(2, 1)).toBeFalsy();\n});\n\ntest('Test minValue', () => {\n minValue('foo', 1, 2);\n minValue('foo', 1, '2');\n minValue('foo', 1, null);\n minValue('foo', 1, undefined);\n expect(() => minValue('foo', 2, 1)).toThrow('foo may not be less than 2');\n});\n\ntest('Test isMaxValue', () => {\n expect(isMaxValue(2, 1)).toBeTruthy();\n expect(isMaxValue(2, '1')).toBeTruthy();\n expect(isMaxValue(2, null)).toBeTruthy();\n expect(isMaxValue(2, undefined)).toBeTruthy();\n expect(isMaxValue(1, 2)).toBeFalsy();\n});\n\ntest('Test maxValue', () => {\n maxValue('foo', 2, 1);\n maxValue('foo', 2, '1');\n maxValue('foo', 2, null);\n maxValue('foo', 2, undefined);\n expect(() => maxValue('foo', 1, 2)).toThrow('foo may not be greater than 1');\n});\n\ntest('Test isBetweenValues', () => {\n expect(isBetweenValues(1, 3, 2)).toBeTruthy();\n expect(isBetweenValues(1, 3, '2')).toBeTruthy();\n expect(isBetweenValues(1, 3, null)).toBeTruthy();\n expect(isBetweenValues(1, 3, undefined)).toBeTruthy();\n expect(isBetweenValues(1, 3, 4)).toBeFalsy();\n});\n\ntest('Test betweenValues', () => {\n betweenValues('foo', 1, 3, 2);\n betweenValues('foo', 1, 3, '2');\n betweenValues('foo', 1, 3, null);\n betweenValues('foo', 1, 3, undefined);\n expect(() => betweenValues('foo', 1, 3, 4)).toThrow(\n 'foo must be between 1 and 3'\n );\n});\n\ntest('Test isValidString', () => {\n expect(isValidString({required: true}, 'bar')).toBeTruthy();\n expect(isValidString({required: true}, ' ')).toBeTruthy();\n expect(isValidString({required: true}, '')).toBeTruthy();\n expect(isValidString({required: false}, null)).toBeTruthy();\n expect(isValidString({required: false}, undefined)).toBeTruthy();\n expect(isValidString({required: true}, null)).toBeFalsy();\n expect(isValidString({required: true}, undefined)).toBeFalsy();\n});\n\ntest('Test validString', () => {\n validString('foo', {required: true}, 'bar');\n validString('foo', {required: true}, ' ');\n validString('foo', {required: true}, '');\n validString('foo', {required: false}, null);\n validString('foo', {required: false}, undefined);\n expect(() => validString('foo', {required: true}, null)).toThrow(\n 'foo may not be null or undefined'\n );\n expect(() => validString('foo', {required: true}, undefined)).toThrow(\n 'foo may not be null or undefined'\n );\n});\n"]}