@nr1e/commons 0.1.0-alpha.1 → 0.1.1-alpha.0
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.
- package/.editorconfig +19 -0
- package/.eslintignore +3 -0
- package/.eslintrc.json +4 -0
- package/.git/COMMIT_EDITMSG +5 -0
- package/.git/FETCH_HEAD +1 -0
- package/.git/HEAD +1 -0
- package/.git/config +18 -0
- package/.git/config.worktree +5 -0
- package/.git/description +1 -0
- package/.git/hooks/applypatch-msg.sample +15 -0
- package/.git/hooks/commit-msg.sample +24 -0
- package/.git/hooks/fsmonitor-watchman.sample +174 -0
- package/.git/hooks/post-update.sample +8 -0
- package/.git/hooks/pre-applypatch.sample +14 -0
- package/.git/hooks/pre-commit.sample +49 -0
- package/.git/hooks/pre-merge-commit.sample +13 -0
- package/.git/hooks/pre-push.sample +53 -0
- package/.git/hooks/pre-rebase.sample +169 -0
- package/.git/hooks/pre-receive.sample +24 -0
- package/.git/hooks/prepare-commit-msg.sample +42 -0
- package/.git/hooks/push-to-checkout.sample +78 -0
- package/.git/hooks/sendemail-validate.sample +77 -0
- package/.git/hooks/update.sample +128 -0
- package/.git/index +0 -0
- package/.git/info/exclude +6 -0
- package/.git/logs/HEAD +2 -0
- package/.git/logs/refs/heads/develop +2 -0
- package/.git/logs/refs/remotes/origin/develop +2 -0
- package/.git/objects/07/c0af7cd711cab6a55ad3dc349ac8c70775623c +0 -0
- package/.git/objects/09/8fb5a5ff070a1ee3ea11db1a3568af3fea6fa2 +0 -0
- package/.git/objects/0d/698432e2c44311c17b845cc63093a898972b95 +0 -0
- package/.git/objects/10/ba4a7d64968326293182d571a9c73f5e041fb6 +3 -0
- package/.git/objects/12/069a5aa45479564e00749f730582627a276a55 +3 -0
- package/.git/objects/14/5ab9cf82c40696a07ab42f117ba199acb2a50b +4 -0
- package/.git/objects/17/7b0dc4bf884f8ae0403b4aad053e76baafd632 +2 -0
- package/.git/objects/1d/a517ce3527df45a4f28e52ff2c0d9d1c8179f6 +0 -0
- package/.git/objects/26/d9a4912af870ce319f5cb5102651d49baac4ab +1 -0
- package/.git/objects/27/50076ed23b5211a52ef834f40f183ddecb917a +0 -0
- package/.git/objects/2a/96e4bb57fa4bd69c719dca224b17b569e94e82 +2 -0
- package/.git/objects/2b/38c26b4ec43b8f5574acb164d2ba64bca8e230 +0 -0
- package/.git/objects/2c/61d463bee185f04e7c2bd1d2a15ad1117c589e +0 -0
- package/.git/objects/2d/22dbc836cfd75c8d7640ebe5a4fe90bd2c23c6 +0 -0
- package/.git/objects/38/0be191ee415827a1217f46626fea4fefba48e5 +0 -0
- package/.git/objects/4c/bb28de66d7aaeb4d7737cc2be955adc0c886b5 +0 -0
- package/.git/objects/50/150b739272269be2ede552448013eba65323da +0 -0
- package/.git/objects/53/2b7b796ffd3223f913a5a5e1e17743ee3591fe +0 -0
- package/.git/objects/54/f13d9d62fbedd19b41134ba17153c4328de95b +0 -0
- package/.git/objects/5d/4aa0709f62f1bc1fa80251208b570cb3b89d9c +0 -0
- package/.git/objects/63/1c43e00d4c34ba914c510f4fe2e6df15b8b06e +0 -0
- package/.git/objects/63/9900d13c6182e452e33a3bd638e70a0146c785 +2 -0
- package/.git/objects/64/3fa02661c3a1b54205729a75d2fb5f013833af +0 -0
- package/.git/objects/6c/59086d862516d2fffa5da2035e5003100fb5c7 +0 -0
- package/.git/objects/6c/b74f90a0c799eea1c54a04d8d6a8a9e9691cca +2 -0
- package/.git/objects/6d/f39e776d6a89628ce4a005a011911298651635 +0 -0
- package/.git/objects/70/0e093acb1c1e55d523507411b7940a01a3bb65 +0 -0
- package/.git/objects/74/c82ffe8eb71efecbccfdf67b590949c944dd1a +0 -0
- package/.git/objects/76/1413a07839108abb46ef0e4490bd1c1444b4fc +0 -0
- package/.git/objects/77/96f8282f2c553ecdde72bc976478eb3a8a948e +0 -0
- package/.git/objects/79/ee123c2b23e069e35ed634d687e17f731cc702 +0 -0
- package/.git/objects/7d/80af9735f0527db35ecc79ae3c887e445cb3e0 +0 -0
- package/.git/objects/85/1d8d26c2a946ccfd5461a2573665c1fb7d71f7 +0 -0
- package/.git/objects/85/c5f24b8c55496f82a2680f94a7d3fa32887ea0 +0 -0
- package/.git/objects/87/00b3833597b600e6f0ffcfbaf622fd8cfaa9c3 +1 -0
- package/.git/objects/87/f31d3df8e7edbf96e45d80126f878b8e0c243f +0 -0
- package/.git/objects/8d/d819967bdc8457f04c1b5498bce89380d6552b +7 -0
- package/.git/objects/92/608c4e069a4301d466d8d18daecbe7abc9500e +0 -0
- package/.git/objects/94/a25f7f4cb416c083d265558da75d457237d671 +0 -0
- package/.git/objects/9c/69411050eac81b5dce09314516a30b38c41a20 +3 -0
- package/.git/objects/9f/54b5b21769da383f12fb9c7bd364bdb05e13a9 +0 -0
- package/.git/objects/a5/886c22eb68b152bb95ec5151504676d8e78ae1 +0 -0
- package/.git/objects/a6/582c9510e264f3b46fc3b20597a16923a03523 +0 -0
- package/.git/objects/a9/d7db9c0a81b2db47ca92e4e180b30090b27632 +0 -0
- package/.git/objects/aa/8ae6a0af7014d738cc551d1ffebeb4e19e6b73 +0 -0
- package/.git/objects/ad/c418f9105db9ec488de6831584b82e3929eaef +0 -0
- package/.git/objects/ae/14b04cdf65ade0f70577cdea2f85203f4c1bde +0 -0
- package/.git/objects/b0/c1c68fbbad6b190434cd2bb0e807796bd56fca +0 -0
- package/.git/objects/b1/0f0d0ef3bc5aaf3a91be0b991cb6fe0fcadc40 +0 -0
- package/.git/objects/b1/3c15806ef3856ecd8660b0bb36f39830daa3c2 +0 -0
- package/.git/objects/b6/3b642cfb4254fc0f7058903abc5b481895c4ef +0 -0
- package/.git/objects/b8/a2c461d7ffed9d4ba242c58a52341832b99e0a +0 -0
- package/.git/objects/bc/91e0079eb00d56dcde16714748f36a10dbd525 +0 -0
- package/.git/objects/c1/beeb895b71b709e48560460199db11b3fc18af +0 -0
- package/.git/objects/c5/166c2aeebaeb0a0f7654223c843c50cd4c8953 +0 -0
- package/.git/objects/d4/0a2096fc36c1fd9c7a9263c458d5e8a4a5bee7 +0 -0
- package/.git/objects/e8/019be9e978a8e2f094e748cbb6ce0c7163adee +0 -0
- package/.git/objects/eb/1d744c4e9b47bc902647298424320078e32980 +0 -0
- package/.git/objects/ee/15af38be7f3c3862229e59c6b5688f8e0f6099 +0 -0
- package/.git/objects/f1/9e0f429f231c34432784f9e33b92ac1d598c17 +0 -0
- package/.git/objects/f9/86f2fe82493e85651396b6d5886316d1c890dd +0 -0
- package/.git/refs/heads/develop +1 -0
- package/.git/refs/remotes/origin/develop +1 -0
- package/.git/shallow +1 -0
- package/.github/dependabot.yml +10 -0
- package/.github/workflows/ci.yml +12 -0
- package/.github/workflows/issues.yml +13 -0
- package/.github/workflows/publish.yml +20 -0
- package/.gitignore +13 -0
- package/.idea/.gitignore +10 -0
- package/.idea/aws.xml +11 -0
- package/.idea/codeStyles/Project.xml +58 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/commons-js.iml +14 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/.npmrc +1 -0
- package/.prettierignore +7 -0
- package/.prettierrc.cjs +3 -0
- package/LICENSE +26 -0
- package/README.md +14 -0
- package/coverage/base.css +224 -0
- package/coverage/bitsnbytes/b64.mts.html +559 -0
- package/coverage/bitsnbytes/index.html +131 -0
- package/coverage/bitsnbytes/index.mts.html +88 -0
- package/coverage/clover.xml +1003 -0
- package/coverage/coverage-final.json +15 -0
- package/coverage/errors/errors.mts.html +898 -0
- package/coverage/errors/index.html +131 -0
- package/coverage/errors/index.mts.html +88 -0
- package/coverage/favicon.png +0 -0
- package/coverage/http/http-method.mts.html +112 -0
- package/coverage/http/http-status-code.mts.html +211 -0
- package/coverage/http/index.html +146 -0
- package/coverage/http/index.mts.html +91 -0
- package/coverage/index.html +191 -0
- package/coverage/lang/index.html +146 -0
- package/coverage/lang/index.mts.html +91 -0
- package/coverage/lang/sleep.mts.html +109 -0
- package/coverage/lang/type-functions.mts.html +124 -0
- package/coverage/oauth/crypto-functions.mts.html +217 -0
- package/coverage/oauth/index.html +131 -0
- package/coverage/oauth/index.mts.html +88 -0
- package/coverage/prettify.css +1 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/validator/index.html +131 -0
- package/coverage/validator/index.mts.html +88 -0
- package/coverage/validator/validators.mts.html +1237 -0
- package/dist/package.json +72 -0
- package/node_modules/@eslint/eslintrc/LICENSE +19 -0
- package/node_modules/@eslint/eslintrc/README.md +115 -0
- package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +1104 -0
- package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +1 -0
- package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +4344 -0
- package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +1 -0
- package/node_modules/@eslint/eslintrc/package.json +82 -0
- package/node_modules/@eslint/eslintrc/universal.js +9 -0
- package/node_modules/@eslint/js/LICENSE +19 -0
- package/node_modules/@eslint/js/README.md +57 -0
- package/node_modules/@eslint/js/package.json +31 -0
- package/node_modules/@eslint/js/src/index.js +17 -0
- package/node_modules/@eslint-community/eslint-utils/LICENSE +21 -0
- package/node_modules/@eslint-community/eslint-utils/README.md +37 -0
- package/node_modules/@eslint-community/eslint-utils/index.js +2068 -0
- package/node_modules/@eslint-community/eslint-utils/index.js.map +1 -0
- package/node_modules/@eslint-community/eslint-utils/index.mjs +2027 -0
- package/node_modules/@eslint-community/eslint-utils/index.mjs.map +1 -0
- package/node_modules/@eslint-community/eslint-utils/package.json +73 -0
- package/node_modules/@eslint-community/regexpp/LICENSE +21 -0
- package/node_modules/@eslint-community/regexpp/README.md +177 -0
- package/node_modules/@eslint-community/regexpp/index.d.ts +1065 -0
- package/node_modules/@eslint-community/regexpp/index.js +2747 -0
- package/node_modules/@eslint-community/regexpp/index.js.map +1 -0
- package/node_modules/@eslint-community/regexpp/index.mjs +2737 -0
- package/node_modules/@eslint-community/regexpp/index.mjs.map +1 -0
- package/node_modules/@eslint-community/regexpp/package.json +93 -0
- package/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/@types/node/README.md +15 -0
- package/node_modules/@types/node/package.json +217 -0
- package/node_modules/@typescript-eslint/eslint-plugin/LICENSE +21 -0
- package/node_modules/@typescript-eslint/eslint-plugin/README.md +10 -0
- package/node_modules/@typescript-eslint/eslint-plugin/dist/index.js +23 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/README.md +23 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/TEMPLATE.md +26 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/adjacent-overload-signatures.md +93 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/array-type.md +103 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/await-thenable.md +40 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/ban-ts-comment.md +148 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/ban-tslint-comment.md +39 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/ban-types.md +183 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/block-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/brace-style.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/camelcase.md +10 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/class-literal-property-style.md +114 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/comma-dangle.md +22 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/comma-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-generic-constructors.md +73 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-indexed-object-style.md +80 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-type-assertions.md +108 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-type-definitions.md +82 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-type-exports.md +100 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-type-imports.md +105 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/default-param-last.md +48 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/dot-notation.md +77 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/explicit-function-return-type.md +319 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/explicit-member-accessibility.md +331 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/explicit-module-boundary-types.md +250 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/func-call-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/indent.md +20 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/init-declarations.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/key-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/keyword-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/lines-around-comment.md +37 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/lines-between-class-members.md +63 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/member-delimiter-style.md +161 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/member-ordering.md +1360 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/method-signature-style.md +110 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/naming-convention.md +706 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-array-constructor.md +35 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-base-to-string.md +88 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md +56 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-confusing-void-expression.md +116 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-dupe-class-members.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-duplicate-enum-values.md +50 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-duplicate-imports.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-duplicate-type-constituents.md +61 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-dynamic-delete.md +53 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-empty-function.md +88 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-empty-interface.md +70 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-explicit-any.md +174 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-extra-non-null-assertion.md +52 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-extra-parens.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-extra-semi.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-extraneous-class.md +294 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-floating-promises.md +106 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-for-in-array.md +56 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-implicit-any-catch.md +73 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-implied-eval.md +101 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-import-type-side-effects.md +75 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-inferrable-types.md +103 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-invalid-this.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-invalid-void-type.md +113 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-loop-func.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-loss-of-precision.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-magic-numbers.md +131 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-meaningless-void-operator.md +47 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-misused-new.md +46 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-misused-promises.md +245 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-mixed-enums.md +88 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-namespace.md +129 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md +49 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md +35 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-non-null-assertion.md +42 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-parameter-properties.md +406 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-redeclare.md +73 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-redundant-type-constituents.md +78 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-require-imports.md +37 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-restricted-imports.md +63 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-shadow.md +101 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-this-alias.md +38 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-throw-literal.md +111 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-type-alias.md +602 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md +133 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-condition.md +103 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-qualifier.md +51 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md +73 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md +77 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md +55 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-argument.md +83 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-assignment.md +86 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-call.md +58 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-declaration-merging.md +54 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-enum-comparison.md +75 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-member-access.md +64 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-return.md +103 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unused-expressions.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unused-vars.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-use-before-define.md +97 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-useless-constructor.md +21 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-useless-empty-export.md +43 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-var-requires.md +37 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md +41 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/object-curly-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/padding-line-between-statements.md +35 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/parameter-properties.md +485 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-as-const.md +44 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-enum-initializers.md +62 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-for-of.md +46 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-function-type.md +92 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-includes.md +77 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-literal-enum-member.md +101 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-namespace-keyword.md +47 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-nullish-coalescing.md +164 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-optional-chain.md +71 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md +268 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-readonly.md +87 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md +58 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-regexp-exec.md +46 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-return-this-type.md +87 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md +57 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-ts-expect-error.md +69 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/promise-function-async.md +59 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/quotes.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/require-array-sort-compare.md +78 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/require-await.md +24 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/restrict-plus-operands.md +208 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/restrict-template-expressions.md +117 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/return-await.md +216 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/semi.md +16 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/sort-type-constituents.md +101 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/sort-type-union-intersection-members.md +106 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/space-before-blocks.md +42 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/space-before-function-paren.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/space-infix-ops.md +16 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/strict-boolean-expressions.md +183 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/switch-exhaustiveness-check.md +106 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/triple-slash-reference.md +61 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/type-annotation-spacing.md +303 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/typedef.md +320 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/unbound-method.md +103 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/unified-signatures.md +70 -0
- package/node_modules/@typescript-eslint/eslint-plugin/index.d.ts +4 -0
- package/node_modules/@typescript-eslint/eslint-plugin/package.json +87 -0
- package/node_modules/@typescript-eslint/parser/LICENSE +22 -0
- package/node_modules/@typescript-eslint/parser/README.md +10 -0
- package/node_modules/@typescript-eslint/parser/dist/index.js +17 -0
- package/node_modules/@typescript-eslint/parser/package.json +75 -0
- package/node_modules/@typescript-eslint/scope-manager/LICENSE +21 -0
- package/node_modules/@typescript-eslint/scope-manager/README.md +8 -0
- package/node_modules/@typescript-eslint/scope-manager/dist/index.js +31 -0
- package/node_modules/@typescript-eslint/scope-manager/package.json +67 -0
- package/node_modules/@typescript-eslint/type-utils/LICENSE +21 -0
- package/node_modules/@typescript-eslint/type-utils/README.md +12 -0
- package/node_modules/@typescript-eslint/type-utils/dist/index.js +36 -0
- package/node_modules/@typescript-eslint/type-utils/package.json +71 -0
- package/node_modules/@typescript-eslint/types/LICENSE +21 -0
- package/node_modules/@typescript-eslint/types/README.md +12 -0
- package/node_modules/@typescript-eslint/types/dist/index.js +24 -0
- package/node_modules/@typescript-eslint/types/package.json +84 -0
- package/node_modules/@typescript-eslint/typescript-estree/LICENSE +26 -0
- package/node_modules/@typescript-eslint/typescript-estree/README.md +10 -0
- package/node_modules/@typescript-eslint/typescript-estree/dist/index.js +38 -0
- package/node_modules/@typescript-eslint/typescript-estree/package.json +85 -0
- package/node_modules/@typescript-eslint/utils/LICENSE +21 -0
- package/node_modules/@typescript-eslint/utils/README.md +10 -0
- package/node_modules/@typescript-eslint/utils/dist/index.js +41 -0
- package/node_modules/@typescript-eslint/utils/package.json +70 -0
- package/node_modules/@typescript-eslint/visitor-keys/LICENSE +21 -0
- package/node_modules/@typescript-eslint/visitor-keys/README.md +10 -0
- package/node_modules/@typescript-eslint/visitor-keys/dist/index.js +8 -0
- package/node_modules/@typescript-eslint/visitor-keys/package.json +60 -0
- package/node_modules/@vitest/coverage-v8/LICENSE +21 -0
- package/node_modules/@vitest/coverage-v8/dist/index.js +54 -0
- package/node_modules/@vitest/coverage-v8/package.json +72 -0
- package/package.json +6 -6
- package/pnpm-lock.yaml +3277 -0
- package/src/bitsnbytes/b64.mts +158 -0
- package/src/bitsnbytes/b64.test.mts +78 -0
- package/src/bitsnbytes/index.mts +1 -0
- package/src/errors/errors.mts +271 -0
- package/src/errors/errors.test.mts +74 -0
- package/src/errors/index.mts +1 -0
- package/src/http/http-method.mts +9 -0
- package/src/http/http-status-code.mts +42 -0
- package/src/http/index.mts +2 -0
- package/src/lang/index.mts +2 -0
- package/src/lang/sleep.mts +8 -0
- package/src/lang/type-functions.mts +13 -0
- package/src/oauth/crypto-functions.mts +44 -0
- package/src/oauth/crypto-functions.test.mts +48 -0
- package/src/oauth/index.mts +1 -0
- package/src/validator/index.mts +1 -0
- package/src/validator/validators.mts +384 -0
- package/src/validator/validators.test.mts +245 -0
- package/tsconfig.json +18 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.d.mts +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.d.mts.map +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.mjs +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.mjs.map +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.test.d.mts +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.test.d.mts.map +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.test.mjs +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.test.mjs.map +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/index.d.mts +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/index.d.mts.map +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/index.mjs +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/index.mjs.map +0 -0
- /package/{errors → dist/errors}/errors.d.mts +0 -0
- /package/{errors → dist/errors}/errors.d.mts.map +0 -0
- /package/{errors → dist/errors}/errors.mjs +0 -0
- /package/{errors → dist/errors}/errors.mjs.map +0 -0
- /package/{errors → dist/errors}/errors.test.d.mts +0 -0
- /package/{errors → dist/errors}/errors.test.d.mts.map +0 -0
- /package/{errors → dist/errors}/errors.test.mjs +0 -0
- /package/{errors → dist/errors}/errors.test.mjs.map +0 -0
- /package/{errors → dist/errors}/index.d.mts +0 -0
- /package/{errors → dist/errors}/index.d.mts.map +0 -0
- /package/{errors → dist/errors}/index.mjs +0 -0
- /package/{errors → dist/errors}/index.mjs.map +0 -0
- /package/{http → dist/http}/http-method.d.mts +0 -0
- /package/{http → dist/http}/http-method.d.mts.map +0 -0
- /package/{http → dist/http}/http-method.mjs +0 -0
- /package/{http → dist/http}/http-method.mjs.map +0 -0
- /package/{http → dist/http}/http-status-code.d.mts +0 -0
- /package/{http → dist/http}/http-status-code.d.mts.map +0 -0
- /package/{http → dist/http}/http-status-code.mjs +0 -0
- /package/{http → dist/http}/http-status-code.mjs.map +0 -0
- /package/{http → dist/http}/index.d.mts +0 -0
- /package/{http → dist/http}/index.d.mts.map +0 -0
- /package/{http → dist/http}/index.mjs +0 -0
- /package/{http → dist/http}/index.mjs.map +0 -0
- /package/{lang → dist/lang}/index.d.mts +0 -0
- /package/{lang → dist/lang}/index.d.mts.map +0 -0
- /package/{lang → dist/lang}/index.mjs +0 -0
- /package/{lang → dist/lang}/index.mjs.map +0 -0
- /package/{lang → dist/lang}/sleep.d.mts +0 -0
- /package/{lang → dist/lang}/sleep.d.mts.map +0 -0
- /package/{lang → dist/lang}/sleep.mjs +0 -0
- /package/{lang → dist/lang}/sleep.mjs.map +0 -0
- /package/{lang → dist/lang}/type-functions.d.mts +0 -0
- /package/{lang → dist/lang}/type-functions.d.mts.map +0 -0
- /package/{lang → dist/lang}/type-functions.mjs +0 -0
- /package/{lang → dist/lang}/type-functions.mjs.map +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.d.mts +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.d.mts.map +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.mjs +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.mjs.map +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.test.d.mts +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.test.d.mts.map +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.test.mjs +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.test.mjs.map +0 -0
- /package/{oauth → dist/oauth}/index.d.mts +0 -0
- /package/{oauth → dist/oauth}/index.d.mts.map +0 -0
- /package/{oauth → dist/oauth}/index.mjs +0 -0
- /package/{oauth → dist/oauth}/index.mjs.map +0 -0
- /package/{validator → dist/validator}/index.d.mts +0 -0
- /package/{validator → dist/validator}/index.d.mts.map +0 -0
- /package/{validator → dist/validator}/index.mjs +0 -0
- /package/{validator → dist/validator}/index.mjs.map +0 -0
- /package/{validator → dist/validator}/validators.d.mts +0 -0
- /package/{validator → dist/validator}/validators.d.mts.map +0 -0
- /package/{validator → dist/validator}/validators.mjs +0 -0
- /package/{validator → dist/validator}/validators.mjs.map +0 -0
- /package/{validator → dist/validator}/validators.test.d.mts +0 -0
- /package/{validator → dist/validator}/validators.test.d.mts.map +0 -0
- /package/{validator → dist/validator}/validators.test.mjs +0 -0
- /package/{validator → dist/validator}/validators.test.mjs.map +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {IllegalArgumentError} from '../errors/errors.mjs';
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
4
|
+
const encoder = new TextEncoder();
|
|
5
|
+
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
6
|
+
const decoder = new TextDecoder();
|
|
7
|
+
|
|
8
|
+
export const BASE64_CHARS: Uint8Array = new Uint8Array([
|
|
9
|
+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
|
|
10
|
+
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
|
|
11
|
+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
|
|
12
|
+
0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
|
|
13
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f, 0x3d,
|
|
14
|
+
]);
|
|
15
|
+
// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
16
|
+
// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
17
|
+
// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
18
|
+
// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
19
|
+
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '='
|
|
20
|
+
|
|
21
|
+
export const URL_MODIFIED_BASE64_CHARS: Uint8Array = new Uint8Array([
|
|
22
|
+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
|
|
23
|
+
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
|
|
24
|
+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
|
|
25
|
+
0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
|
|
26
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2d, 0x5f,
|
|
27
|
+
]);
|
|
28
|
+
// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
29
|
+
// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
30
|
+
// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
31
|
+
// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
32
|
+
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',
|
|
33
|
+
|
|
34
|
+
export const YUI_BASE64_CHARS: Uint8Array = new Uint8Array([
|
|
35
|
+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
|
|
36
|
+
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
|
|
37
|
+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
|
|
38
|
+
0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
|
|
39
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2e, 0x5f, 0x2d,
|
|
40
|
+
]);
|
|
41
|
+
// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
42
|
+
// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
43
|
+
// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
44
|
+
// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
45
|
+
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '_', '-'
|
|
46
|
+
|
|
47
|
+
export type Base64CharSet = 'b64' | 'url' | 'yui';
|
|
48
|
+
|
|
49
|
+
export interface Base64Options {
|
|
50
|
+
readonly fromIndex?: number;
|
|
51
|
+
readonly toIndex?: number;
|
|
52
|
+
readonly b64chars?: Uint8Array | Base64CharSet;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns a base64 character set and validates one if passed in.
|
|
57
|
+
*
|
|
58
|
+
* @param b64chars a base64 character set
|
|
59
|
+
*/
|
|
60
|
+
export function b64Charset(b64chars?: Uint8Array | Base64CharSet): Uint8Array {
|
|
61
|
+
if (b64chars === undefined || b64chars === null) {
|
|
62
|
+
return BASE64_CHARS;
|
|
63
|
+
}
|
|
64
|
+
if (b64chars instanceof Uint8Array) {
|
|
65
|
+
if (b64chars.length !== 65 && b64chars.length !== 64) {
|
|
66
|
+
throw new IllegalArgumentError(
|
|
67
|
+
'b64chars',
|
|
68
|
+
'Base 64 character sets must be 64 or 65 characters.'
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return b64chars;
|
|
72
|
+
}
|
|
73
|
+
switch (b64chars) {
|
|
74
|
+
case 'b64':
|
|
75
|
+
return BASE64_CHARS;
|
|
76
|
+
case 'url':
|
|
77
|
+
return URL_MODIFIED_BASE64_CHARS;
|
|
78
|
+
case 'yui':
|
|
79
|
+
return YUI_BASE64_CHARS;
|
|
80
|
+
default:
|
|
81
|
+
throw new IllegalArgumentError(
|
|
82
|
+
'b64chars',
|
|
83
|
+
`Invalid base64 character set '${b64chars}'`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Base64 encodes a series of bytes.
|
|
90
|
+
*
|
|
91
|
+
* @param buf Bytes to encode
|
|
92
|
+
* @param opts Encoding options
|
|
93
|
+
* @return a base64 string
|
|
94
|
+
*/
|
|
95
|
+
export function tob64(buf: Uint8Array, opts?: Base64Options): Uint8Array {
|
|
96
|
+
const b64chars = b64Charset(opts?.b64chars);
|
|
97
|
+
const toIndex = opts?.toIndex ?? buf.length;
|
|
98
|
+
const fromIndex = opts?.fromIndex ?? 0;
|
|
99
|
+
// every 3 bytes is 4 characters in padded base64 (6 bits per char)
|
|
100
|
+
const num = toIndex - fromIndex;
|
|
101
|
+
const numc =
|
|
102
|
+
b64chars.length === 65
|
|
103
|
+
? ((num + 2 - ((num + 2) % 3)) / 3) * 4 // padded
|
|
104
|
+
: (num * 8) / 6 + ((num * 8) % 6 !== 0 ? 1 : 0); // not padded
|
|
105
|
+
const b64 = new Uint8Array(numc);
|
|
106
|
+
let n = 0;
|
|
107
|
+
for (let i = 0; i < toIndex; i += 3) {
|
|
108
|
+
const v =
|
|
109
|
+
((buf[i] & 0xff) << 16) |
|
|
110
|
+
(i + 1 < toIndex ? (buf[i + 1] & 0xff) << 8 : 0) |
|
|
111
|
+
(i + 2 < toIndex ? buf[i + 2] & 0xff : 0);
|
|
112
|
+
b64[n++] = b64chars[(v >>> 18) & 0x3f];
|
|
113
|
+
b64[n++] = b64chars[(v >>> 12) & 0x3f];
|
|
114
|
+
switch (
|
|
115
|
+
toIndex - i // calculate bytes remaining to be processed
|
|
116
|
+
) {
|
|
117
|
+
case 1: // 0 bytes left to process
|
|
118
|
+
if (b64chars.length === 65) {
|
|
119
|
+
b64[n++] = b64chars[64];
|
|
120
|
+
b64[n++] = b64chars[64];
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
case 2: // 1 byte left to process
|
|
124
|
+
b64[n++] = b64chars[(v >>> 6) & 0x3f];
|
|
125
|
+
if (b64chars.length === 65) {
|
|
126
|
+
b64[n++] = b64chars[64];
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
b64[n++] = b64chars[(v >>> 6) & 0x3f];
|
|
131
|
+
b64[n++] = b64chars[v & 0x3f];
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return b64;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Base64 encodes a series of bytes to a string.
|
|
140
|
+
*
|
|
141
|
+
* @param buf Bytes to encode
|
|
142
|
+
* @param opts Encoding options
|
|
143
|
+
* @return a base64 string
|
|
144
|
+
*/
|
|
145
|
+
export function tob64s(buf: Uint8Array, opts?: Base64Options): string {
|
|
146
|
+
return decoder.decode(tob64(buf, opts));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Base64 encodes a string to a string.
|
|
151
|
+
*
|
|
152
|
+
* @param str String to encode
|
|
153
|
+
* @param opts Encoding options
|
|
154
|
+
* @return a base64 string
|
|
155
|
+
*/
|
|
156
|
+
export function stob64s(str: string, opts?: Base64Options): string {
|
|
157
|
+
return tob64s(encoder.encode(str), opts);
|
|
158
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {test, expect} from 'vitest';
|
|
2
|
+
import {stob64s, tob64s} from './b64.mjs';
|
|
3
|
+
import * as crypto from 'crypto';
|
|
4
|
+
|
|
5
|
+
test('Test tob64', () => {
|
|
6
|
+
const str = '"Computer, compute to the last digit the value of pi" -- Spock';
|
|
7
|
+
let b64s = [
|
|
8
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3BvY2s=',
|
|
9
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3BvYw==',
|
|
10
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3Bv',
|
|
11
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3A=',
|
|
12
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gUw==',
|
|
13
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0g',
|
|
14
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0=',
|
|
15
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLQ==',
|
|
16
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIg',
|
|
17
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSI=',
|
|
18
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaQ==',
|
|
19
|
+
];
|
|
20
|
+
for (let i = 0; i < b64s.length; i++) {
|
|
21
|
+
expect(b64s[i]).toBe(stob64s(str.substring(0, str.length - i)));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Test URL modified base64 encoding
|
|
25
|
+
b64s = [
|
|
26
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3BvY2s',
|
|
27
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3BvYw',
|
|
28
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3Bv',
|
|
29
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3A',
|
|
30
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gUw',
|
|
31
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0g',
|
|
32
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0',
|
|
33
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLQ',
|
|
34
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIg',
|
|
35
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSI',
|
|
36
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaQ',
|
|
37
|
+
];
|
|
38
|
+
for (let i = 0; i < b64s.length; i++) {
|
|
39
|
+
expect(b64s[i]).toBe(
|
|
40
|
+
stob64s(str.substring(0, str.length - i), {b64chars: 'url'})
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Test YUI modified base64 encoding
|
|
45
|
+
b64s = [
|
|
46
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3BvY2s-',
|
|
47
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3BvYw--',
|
|
48
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3Bv',
|
|
49
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gU3A-',
|
|
50
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0gUw--',
|
|
51
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0g',
|
|
52
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLS0-',
|
|
53
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIgLQ--',
|
|
54
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSIg',
|
|
55
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaSI-',
|
|
56
|
+
'IkNvbXB1dGVyLCBjb21wdXRlIHRvIHRoZSBsYXN0IGRpZ2l0IHRoZSB2YWx1ZSBvZiBwaQ--',
|
|
57
|
+
];
|
|
58
|
+
for (let i = 0; i < b64s.length; i++) {
|
|
59
|
+
expect(b64s[i]).toBe(
|
|
60
|
+
stob64s(str.substring(0, str.length - i), {b64chars: 'yui'})
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('Compare to Node', () => {
|
|
66
|
+
for (let i = 0; i < 100; i++) {
|
|
67
|
+
const bytes = crypto.randomBytes(16);
|
|
68
|
+
const str = tob64s(bytes, {b64chars: 'url'});
|
|
69
|
+
const nodeStr = bytes.toString('base64url');
|
|
70
|
+
expect(str).toEqual(nodeStr);
|
|
71
|
+
}
|
|
72
|
+
for (let i = 0; i < 100; i++) {
|
|
73
|
+
const bytes = crypto.randomBytes(16);
|
|
74
|
+
const str = tob64s(bytes, {b64chars: 'b64'});
|
|
75
|
+
const nodeStr = bytes.toString('base64');
|
|
76
|
+
expect(str).toEqual(nodeStr);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './b64.mjs';
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import {HttpStatusCode} from '../http/index.mjs';
|
|
2
|
+
import {isError, isObject} from '../lang/index.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* An extended version of Error that includes an HttpStatusCode.
|
|
6
|
+
* This can be useful in middleware error handlers to determine http status codes to return to the client.
|
|
7
|
+
*/
|
|
8
|
+
export interface HttpError extends Error {
|
|
9
|
+
/**
|
|
10
|
+
* The HTTP status code.
|
|
11
|
+
*/
|
|
12
|
+
statusCode: HttpStatusCode | number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the given parameter is an HttpError.
|
|
17
|
+
*
|
|
18
|
+
* @param e The parameter to check
|
|
19
|
+
*/
|
|
20
|
+
export function isHttpError(e?: unknown): e is HttpError {
|
|
21
|
+
return isObject(e) && !!(e && e.stack && e.statusCode && e.message && e.name);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Thrown when a resource cannot be found.
|
|
26
|
+
*/
|
|
27
|
+
export class NotFoundError extends Error implements HttpError {
|
|
28
|
+
readonly statusCode = HttpStatusCode.NOT_FOUND;
|
|
29
|
+
/**
|
|
30
|
+
* The max-age value to set in the Cache-Control header if used in a middleware.
|
|
31
|
+
*/
|
|
32
|
+
readonly maxAge?: number;
|
|
33
|
+
constructor(message?: string, maxAge?: number) {
|
|
34
|
+
message = message ?? 'Not found';
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = 'NotFoundError';
|
|
37
|
+
this.maxAge = maxAge;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the given parameter is a NotFoundError.
|
|
43
|
+
*
|
|
44
|
+
* @param e The parameter to check
|
|
45
|
+
*/
|
|
46
|
+
export function isNotFoundError(e?: unknown): e is NotFoundError {
|
|
47
|
+
return isHttpError(e) && e.name === 'NotFoundError';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Thrown when a request is missing authentication credentials.
|
|
52
|
+
*/
|
|
53
|
+
export class UnauthorizedError extends Error implements HttpError {
|
|
54
|
+
readonly statusCode = HttpStatusCode.UNAUTHORIZED;
|
|
55
|
+
constructor(message?: string) {
|
|
56
|
+
message = message ?? 'Unauthorized';
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = 'UnauthorizedError';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Checks if the given parameter is a UnauthorizedError.
|
|
64
|
+
*
|
|
65
|
+
* @param e The parameter to check
|
|
66
|
+
*/
|
|
67
|
+
export function isUnauthorizedError(e?: unknown): e is UnauthorizedError {
|
|
68
|
+
return isHttpError(e) && e.name === 'UnauthorizedError';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Thrown when credentials are present, but the requested operations is not allowed.
|
|
73
|
+
*/
|
|
74
|
+
export class ForbiddenError extends Error implements HttpError {
|
|
75
|
+
readonly statusCode = HttpStatusCode.FORBIDDEN;
|
|
76
|
+
constructor(message?: string) {
|
|
77
|
+
message = message ?? 'Forbidden';
|
|
78
|
+
super(message);
|
|
79
|
+
this.name = 'ForbiddenError';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the given parameter is a ForbiddenError.
|
|
85
|
+
*
|
|
86
|
+
* @param e The parameter to check
|
|
87
|
+
*/
|
|
88
|
+
export function isForbiddenError(e?: unknown): e is ForbiddenError {
|
|
89
|
+
return isHttpError(e) && e.name === 'ForbiddenError';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Thrown when a validation error occurs.
|
|
94
|
+
*/
|
|
95
|
+
export class ValidationError extends Error implements HttpError {
|
|
96
|
+
readonly statusCode = HttpStatusCode.BAD_REQUEST;
|
|
97
|
+
constructor(message?: string) {
|
|
98
|
+
message = message ?? 'Validation error';
|
|
99
|
+
super(message);
|
|
100
|
+
this.name = 'ValidationError';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Checks if the given variable is a ValidationError.
|
|
106
|
+
*
|
|
107
|
+
* @param e The variable to check
|
|
108
|
+
*/
|
|
109
|
+
export function isValidationError(e?: unknown): e is ValidationError {
|
|
110
|
+
return isHttpError(e) && e.name === 'ValidationError';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Thrown when a bad request is made.
|
|
115
|
+
*/
|
|
116
|
+
export class BadRequestError extends Error implements HttpError {
|
|
117
|
+
readonly statusCode = HttpStatusCode.BAD_REQUEST;
|
|
118
|
+
constructor(message?: string) {
|
|
119
|
+
message = message ?? 'Bad request';
|
|
120
|
+
super(message ?? 'Bad request');
|
|
121
|
+
this.name = 'BadRequestError';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Checks if the given parameter is a BadRequestError.
|
|
127
|
+
*
|
|
128
|
+
* @param e The parameter to check
|
|
129
|
+
*/
|
|
130
|
+
export function isBadRequestError(e?: unknown): e is BadRequestError {
|
|
131
|
+
return isHttpError(e) && e.name === 'BadRequestError';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Throws when an internal server error occurs.
|
|
136
|
+
*/
|
|
137
|
+
export class InternalServerError extends Error implements HttpError {
|
|
138
|
+
readonly statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR;
|
|
139
|
+
constructor(message?: string) {
|
|
140
|
+
message = message ?? 'Internal server error';
|
|
141
|
+
super(message);
|
|
142
|
+
this.name = 'InternalServerError';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Checks if the given parameter is a InternalServerError.
|
|
148
|
+
*
|
|
149
|
+
* @param e The parameter to check
|
|
150
|
+
*/
|
|
151
|
+
export function isInternalServerError(e?: unknown): e is InternalServerError {
|
|
152
|
+
return isHttpError(e) && e.name === 'InternalServerError';
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Thrown when a conflict occurs.
|
|
157
|
+
*/
|
|
158
|
+
export class ConflictError extends Error implements HttpError {
|
|
159
|
+
readonly statusCode = HttpStatusCode.CONFLICT;
|
|
160
|
+
constructor(message?: string) {
|
|
161
|
+
message = message ?? 'Conflict';
|
|
162
|
+
super(message);
|
|
163
|
+
this.name = 'ConflictError';
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Checks if the given parameter is a ConflictError.
|
|
169
|
+
*
|
|
170
|
+
* @param e The parameter to check
|
|
171
|
+
*/
|
|
172
|
+
export function isConflictError(e?: unknown): e is ConflictError {
|
|
173
|
+
return isHttpError(e) && e.name === 'ConflictError';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Thrown when a unsupported media type is used.
|
|
178
|
+
*/
|
|
179
|
+
export class UnsupportedMediaTypeError extends Error implements HttpError {
|
|
180
|
+
readonly statusCode = HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
|
|
181
|
+
constructor(message?: string) {
|
|
182
|
+
message = message ?? 'Unsupported media type';
|
|
183
|
+
super(message);
|
|
184
|
+
this.name = 'UnsupportedMediaTypeError';
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Checks if the given parameter is a UnsupportedMediaTypeError.
|
|
190
|
+
*
|
|
191
|
+
* @param e The parameter to check
|
|
192
|
+
*/
|
|
193
|
+
export function isUnsupportedMediaTypeError(
|
|
194
|
+
e?: unknown
|
|
195
|
+
): e is UnsupportedMediaTypeError {
|
|
196
|
+
return isHttpError(e) && e.name === 'UnsupportedMediaTypeError';
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Thrown when a requested operation is not implemented.
|
|
201
|
+
*/
|
|
202
|
+
export class NotImplementedError extends Error implements HttpError {
|
|
203
|
+
readonly statusCode = HttpStatusCode.NOT_IMPLEMENTED;
|
|
204
|
+
readonly expose = true;
|
|
205
|
+
constructor(message?: string) {
|
|
206
|
+
message = message ?? 'Not implemented';
|
|
207
|
+
super(message);
|
|
208
|
+
this.name = 'NotImplementedError';
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Checks if the given parameter is a NotImplementedError.
|
|
214
|
+
*
|
|
215
|
+
* @param e The parameter to check
|
|
216
|
+
*/
|
|
217
|
+
export function isNotImplementedError(e?: unknown): e is NotImplementedError {
|
|
218
|
+
return isHttpError(e) && e.name === 'NotImplementedError';
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Thrown when an illegal argument is passed to a function.
|
|
223
|
+
*/
|
|
224
|
+
export class IllegalArgumentError extends Error {
|
|
225
|
+
readonly argName: string;
|
|
226
|
+
constructor(argName: string, message?: string) {
|
|
227
|
+
message = message ?? `Illegal argument ${argName}`;
|
|
228
|
+
super(message);
|
|
229
|
+
this.argName = argName;
|
|
230
|
+
this.name = 'IllegalArgumentError';
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Checks if the given parameter is a IllegalArgumentError.
|
|
236
|
+
*
|
|
237
|
+
* @param e The parameter to check
|
|
238
|
+
*/
|
|
239
|
+
export function isIllegalArgumentError(e?: unknown): e is IllegalArgumentError {
|
|
240
|
+
return isError(e) && e.name === 'IllegalArgumentError';
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Converts the given parameter to an HttpError.
|
|
245
|
+
*
|
|
246
|
+
* @param code The HTTP status code
|
|
247
|
+
* @param message The error message
|
|
248
|
+
*/
|
|
249
|
+
export function toError(
|
|
250
|
+
code: number | HttpStatusCode,
|
|
251
|
+
message?: string
|
|
252
|
+
): Error {
|
|
253
|
+
switch (code) {
|
|
254
|
+
case HttpStatusCode.NOT_FOUND:
|
|
255
|
+
return new NotFoundError(message);
|
|
256
|
+
case HttpStatusCode.FORBIDDEN:
|
|
257
|
+
return new ForbiddenError(message);
|
|
258
|
+
case HttpStatusCode.BAD_REQUEST:
|
|
259
|
+
return new BadRequestError(message);
|
|
260
|
+
case HttpStatusCode.INTERNAL_SERVER_ERROR:
|
|
261
|
+
return new InternalServerError(message);
|
|
262
|
+
case HttpStatusCode.CONFLICT:
|
|
263
|
+
return new ConflictError(message);
|
|
264
|
+
case HttpStatusCode.UNSUPPORTED_MEDIA_TYPE:
|
|
265
|
+
return new UnsupportedMediaTypeError(message);
|
|
266
|
+
case HttpStatusCode.NOT_IMPLEMENTED:
|
|
267
|
+
return new NotImplementedError(message);
|
|
268
|
+
default:
|
|
269
|
+
return new Error(message);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {test, expect} from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
BadRequestError,
|
|
4
|
+
ForbiddenError,
|
|
5
|
+
InternalServerError,
|
|
6
|
+
isBadRequestError,
|
|
7
|
+
isForbiddenError,
|
|
8
|
+
isInternalServerError,
|
|
9
|
+
isNotFoundError,
|
|
10
|
+
isValidationError,
|
|
11
|
+
NotFoundError,
|
|
12
|
+
toError,
|
|
13
|
+
ValidationError,
|
|
14
|
+
} from './errors.mjs';
|
|
15
|
+
import {HttpStatusCode} from '../http/index.mjs';
|
|
16
|
+
|
|
17
|
+
test('Test isNotFoundError', () => {
|
|
18
|
+
expect(isNotFoundError(undefined)).toBeFalsy();
|
|
19
|
+
expect(isNotFoundError(null)).toBeFalsy();
|
|
20
|
+
expect(isNotFoundError({})).toBeFalsy();
|
|
21
|
+
expect(isNotFoundError(new ForbiddenError('just a test'))).toBeFalsy();
|
|
22
|
+
expect(isNotFoundError(new NotFoundError('just a test'))).toBeTruthy();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('Test isForbiddenError', () => {
|
|
26
|
+
expect(isForbiddenError(undefined)).toBeFalsy();
|
|
27
|
+
expect(isForbiddenError(null)).toBeFalsy();
|
|
28
|
+
expect(isForbiddenError({})).toBeFalsy();
|
|
29
|
+
expect(isForbiddenError(new NotFoundError('just a test'))).toBeFalsy();
|
|
30
|
+
expect(isForbiddenError(new ForbiddenError('just a test'))).toBeTruthy();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('Test isValidationError', () => {
|
|
34
|
+
expect(isValidationError(undefined)).toBeFalsy();
|
|
35
|
+
expect(isValidationError(null)).toBeFalsy();
|
|
36
|
+
expect(isValidationError({})).toBeFalsy();
|
|
37
|
+
expect(isValidationError(new NotFoundError('just a test'))).toBeFalsy();
|
|
38
|
+
expect(isValidationError(new ValidationError('just a test'))).toBeTruthy();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('Test isBadRequestError', () => {
|
|
42
|
+
expect(isBadRequestError(undefined)).toBeFalsy();
|
|
43
|
+
expect(isBadRequestError(null)).toBeFalsy();
|
|
44
|
+
expect(isBadRequestError({})).toBeFalsy();
|
|
45
|
+
expect(isBadRequestError(new NotFoundError('just a test'))).toBeFalsy();
|
|
46
|
+
expect(isBadRequestError(new BadRequestError('just a test'))).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('Test isInternalServerError', () => {
|
|
50
|
+
expect(isInternalServerError(undefined)).toBeFalsy();
|
|
51
|
+
expect(isInternalServerError(null)).toBeFalsy();
|
|
52
|
+
expect(isInternalServerError({})).toBeFalsy();
|
|
53
|
+
expect(isInternalServerError(new NotFoundError('just a test'))).toBeFalsy();
|
|
54
|
+
expect(
|
|
55
|
+
isInternalServerError(new InternalServerError('just a test'))
|
|
56
|
+
).toBeTruthy();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('Test toError', () => {
|
|
60
|
+
expect(
|
|
61
|
+
isNotFoundError(toError(HttpStatusCode.NOT_FOUND, 'some message'))
|
|
62
|
+
).toBeTruthy();
|
|
63
|
+
expect(
|
|
64
|
+
isForbiddenError(toError(HttpStatusCode.FORBIDDEN, 'some message'))
|
|
65
|
+
).toBeTruthy();
|
|
66
|
+
expect(
|
|
67
|
+
isBadRequestError(toError(HttpStatusCode.BAD_REQUEST, 'some message'))
|
|
68
|
+
).toBeTruthy();
|
|
69
|
+
expect(
|
|
70
|
+
isInternalServerError(
|
|
71
|
+
toError(HttpStatusCode.INTERNAL_SERVER_ERROR, 'some message')
|
|
72
|
+
)
|
|
73
|
+
).toBeTruthy();
|
|
74
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './errors.mjs';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export enum HttpStatusCode {
|
|
2
|
+
CONTINUE = 100,
|
|
3
|
+
SWITCHING_PROTOCOLS = 101,
|
|
4
|
+
OK = 200,
|
|
5
|
+
CREATED = 201,
|
|
6
|
+
ACCEPTED = 202,
|
|
7
|
+
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
8
|
+
NO_CONTENT = 204,
|
|
9
|
+
RESET_CONTENT = 205,
|
|
10
|
+
PARTIAL_CONTENT = 206,
|
|
11
|
+
MULTIPLE_CHOICES = 300,
|
|
12
|
+
PERMANENT_REDIRECT = 301,
|
|
13
|
+
FOUND = 302,
|
|
14
|
+
SEE_OTHER = 303,
|
|
15
|
+
NOT_MODIFIED = 304,
|
|
16
|
+
USE_PROXY = 305,
|
|
17
|
+
TEMPORARY_REDIRECT = 307,
|
|
18
|
+
BAD_REQUEST = 400,
|
|
19
|
+
UNAUTHORIZED = 401,
|
|
20
|
+
PAYMENT_REQUIRED = 402,
|
|
21
|
+
FORBIDDEN = 403,
|
|
22
|
+
NOT_FOUND = 404,
|
|
23
|
+
METHOD_NOT_ALLOWED = 405,
|
|
24
|
+
NOT_ACCEPTABLE = 406,
|
|
25
|
+
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
26
|
+
REQUEST_TIMEOUT = 408,
|
|
27
|
+
CONFLICT = 409,
|
|
28
|
+
GONE = 410,
|
|
29
|
+
LENGTH_REQUIRED = 411,
|
|
30
|
+
PRECONDITION_FAILED = 412,
|
|
31
|
+
REQUEST_ENTITY_TOO_LARGE = 413,
|
|
32
|
+
REQUEST_URI_TOO_LONG = 414,
|
|
33
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
34
|
+
RANGE_NOT_SATISFIABLE = 416,
|
|
35
|
+
EXPECTATION_FAILED = 417,
|
|
36
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
37
|
+
NOT_IMPLEMENTED = 501,
|
|
38
|
+
BAD_GATEWAY = 502,
|
|
39
|
+
SERVICE_UNAVAILABLE = 503,
|
|
40
|
+
GATEWAY_TIMEOUT = 504,
|
|
41
|
+
HTTP_VERSION_NOT_SUPPORTED = 505,
|
|
42
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function isObject(item: unknown): item is Record<string, unknown> {
|
|
2
|
+
return (
|
|
3
|
+
item !== null && typeof item === 'object' && Array.isArray(item) === false
|
|
4
|
+
);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function isString(item: unknown): item is string {
|
|
8
|
+
return typeof item === 'string';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isError(item: unknown): item is Error {
|
|
12
|
+
return item instanceof Error;
|
|
13
|
+
}
|