@twin.org/core 0.0.4-next.8 → 0.9.0-next.1
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/dist/es/encoding/base64.js +1 -1
- package/dist/es/encoding/base64.js.map +1 -1
- package/dist/es/errors/conflictError.js +1 -1
- package/dist/es/errors/conflictError.js.map +1 -1
- package/dist/es/errors/generalError.js +1 -1
- package/dist/es/errors/generalError.js.map +1 -1
- package/dist/es/errors/notImplementedError.js +1 -1
- package/dist/es/errors/notImplementedError.js.map +1 -1
- package/dist/es/errors/validationError.js +1 -1
- package/dist/es/errors/validationError.js.map +1 -1
- package/dist/es/helpers/arrayHelper.js +1 -1
- package/dist/es/helpers/arrayHelper.js.map +1 -1
- package/dist/es/helpers/errorHelper.js +1 -1
- package/dist/es/helpers/errorHelper.js.map +1 -1
- package/dist/es/helpers/jsonHelper.js +1 -1
- package/dist/es/helpers/jsonHelper.js.map +1 -1
- package/dist/es/helpers/objectHelper.js +2 -2
- package/dist/es/helpers/objectHelper.js.map +1 -1
- package/dist/es/helpers/stringHelper.js +2 -2
- package/dist/es/helpers/stringHelper.js.map +1 -1
- package/dist/es/index.js +7 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IComponent.js.map +1 -1
- package/dist/es/models/IDuration.js +4 -0
- package/dist/es/models/IDuration.js.map +1 -0
- package/dist/es/models/ILocale.js.map +1 -1
- package/dist/es/models/ISharedObjectBufferOptions.js +4 -0
- package/dist/es/models/ISharedObjectBufferOptions.js.map +1 -0
- package/dist/es/models/ISharedObjectBufferWorkerMessage.js +2 -0
- package/dist/es/models/ISharedObjectBufferWorkerMessage.js.map +1 -0
- package/dist/es/models/IValidationFailure.js.map +1 -1
- package/dist/es/models/coerceType.js +5 -1
- package/dist/es/models/coerceType.js.map +1 -1
- package/dist/es/models/sharedObjectBufferMessageTypes.js +13 -0
- package/dist/es/models/sharedObjectBufferMessageTypes.js.map +1 -0
- package/dist/es/types/duration.js +184 -0
- package/dist/es/types/duration.js.map +1 -0
- package/dist/es/types/durationRegExp.js +4 -0
- package/dist/es/types/durationRegExp.js.map +1 -0
- package/dist/es/types/url.js +1 -0
- package/dist/es/types/url.js.map +1 -1
- package/dist/es/utils/asyncCache.js +1 -1
- package/dist/es/utils/asyncCache.js.map +1 -1
- package/dist/es/utils/coerce.js +34 -20
- package/dist/es/utils/coerce.js.map +1 -1
- package/dist/es/utils/compression.js +1 -1
- package/dist/es/utils/compression.js.map +1 -1
- package/dist/es/utils/guards.js +12 -0
- package/dist/es/utils/guards.js.map +1 -1
- package/dist/es/utils/is.js +65 -16
- package/dist/es/utils/is.js.map +1 -1
- package/dist/es/utils/mutex.js +49 -8
- package/dist/es/utils/mutex.js.map +1 -1
- package/dist/es/utils/sharedObjectBuffer.js +308 -0
- package/dist/es/utils/sharedObjectBuffer.js.map +1 -0
- package/dist/es/utils/sharedStore.js +2 -2
- package/dist/es/utils/sharedStore.js.map +1 -1
- package/dist/types/errors/conflictError.d.ts +1 -1
- package/dist/types/errors/generalError.d.ts +1 -1
- package/dist/types/errors/notImplementedError.d.ts +1 -1
- package/dist/types/errors/validationError.d.ts +1 -1
- package/dist/types/helpers/arrayHelper.d.ts +1 -1
- package/dist/types/helpers/errorHelper.d.ts +1 -1
- package/dist/types/helpers/jsonHelper.d.ts +1 -1
- package/dist/types/helpers/objectHelper.d.ts +2 -2
- package/dist/types/helpers/stringHelper.d.ts +2 -2
- package/dist/types/index.d.ts +7 -0
- package/dist/types/models/IComponent.d.ts +2 -2
- package/dist/types/models/IDuration.d.ts +45 -0
- package/dist/types/models/ILocale.d.ts +1 -1
- package/dist/types/models/ISharedObjectBufferOptions.d.ts +17 -0
- package/dist/types/models/ISharedObjectBufferWorkerMessage.d.ts +29 -0
- package/dist/types/models/IValidationFailure.d.ts +1 -1
- package/dist/types/models/coerceType.d.ts +4 -0
- package/dist/types/models/sharedObjectBufferMessageTypes.d.ts +13 -0
- package/dist/types/types/duration.d.ts +29 -0
- package/dist/types/types/durationRegExp.d.ts +1 -0
- package/dist/types/types/url.d.ts +1 -0
- package/dist/types/utils/asyncCache.d.ts +1 -1
- package/dist/types/utils/coerce.d.ts +19 -20
- package/dist/types/utils/compression.d.ts +1 -1
- package/dist/types/utils/guards.d.ts +9 -0
- package/dist/types/utils/is.d.ts +16 -9
- package/dist/types/utils/mutex.d.ts +12 -1
- package/dist/types/utils/sharedObjectBuffer.d.ts +74 -0
- package/dist/types/utils/sharedStore.d.ts +2 -2
- package/docs/changelog.md +273 -0
- package/docs/reference/classes/ArrayHelper.md +1 -1
- package/docs/reference/classes/AsyncCache.md +1 -1
- package/docs/reference/classes/Coerce.md +32 -48
- package/docs/reference/classes/Compression.md +1 -1
- package/docs/reference/classes/ConflictError.md +1 -1
- package/docs/reference/classes/Duration.md +88 -0
- package/docs/reference/classes/ErrorHelper.md +1 -1
- package/docs/reference/classes/GeneralError.md +1 -1
- package/docs/reference/classes/Guards.md +36 -0
- package/docs/reference/classes/Is.md +31 -9
- package/docs/reference/classes/JsonHelper.md +1 -1
- package/docs/reference/classes/Mutex.md +39 -1
- package/docs/reference/classes/NotImplementedError.md +1 -1
- package/docs/reference/classes/ObjectHelper.md +10 -2
- package/docs/reference/classes/SharedObjectBuffer.md +192 -0
- package/docs/reference/classes/SharedStore.md +2 -2
- package/docs/reference/classes/StringHelper.md +16 -13
- package/docs/reference/classes/Url.md +4 -0
- package/docs/reference/classes/ValidationError.md +1 -1
- package/docs/reference/index.md +8 -0
- package/docs/reference/interfaces/IComponent.md +2 -2
- package/docs/reference/interfaces/IDuration.md +83 -0
- package/docs/reference/interfaces/ILocale.md +1 -1
- package/docs/reference/interfaces/ISharedObjectBufferOptions.md +33 -0
- package/docs/reference/interfaces/ISharedObjectBufferWorkerMessage.md +44 -0
- package/docs/reference/interfaces/IValidationFailure.md +1 -1
- package/docs/reference/type-aliases/SharedObjectBufferMessageTypes.md +5 -0
- package/docs/reference/variables/CoerceType.md +6 -0
- package/docs/reference/variables/DURATION_REG_EXP.md +3 -0
- package/docs/reference/variables/SharedObjectBufferMessageTypes.md +13 -0
- package/locales/en.json +9 -2
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coerce.js","sourceRoot":"","sources":["../../../src/utils/coerce.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAc;QAClC,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACpB,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;QAC5B,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAc;QAClC,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,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AAC,OAAO;gBACtB,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC9B,KAAK,UAAU,CAAC,MAAM;gBACrB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7B,KAAK,UAAU,CAAC,OAAO;gBACtB,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC9B,KAAK,UAAU,CAAC,IAAI;gBACnB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,KAAK,UAAU,CAAC,QAAQ;gBACvB,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC/B,KAAK,UAAU,CAAC,IAAI;gBACnB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,KAAK,UAAU,CAAC,MAAM;gBACrB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7B,KAAK,UAAU,CAAC,UAAU;gBACzB,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACjC;gBACC,OAAO,KAAK,CAAC;QACf,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Converter } from \"./converter.js\";\nimport { Is } from \"./is.js\";\nimport { CoerceType } from \"../models/coerceType.js\";\n\n/**\n * Coerce an object from one type to another.\n */\nexport class Coerce {\n\t/**\n\t * Coerce the value to a string.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static string(value: unknown): string | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn value.toString();\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? \"true\" : \"false\";\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value.toISOString();\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a number.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static number(value: unknown): number | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst parsed = Number.parseFloat(value);\n\t\t\tif (Is.number(parsed)) {\n\t\t\t\treturn parsed;\n\t\t\t}\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? 1 : 0;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value.getTime();\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to an integer.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static integer(value: unknown): number | undefined {\n\t\tconst num = Coerce.number(value);\n\t\tif (!Is.undefined(num)) {\n\t\t\treturn Math.trunc(num);\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a bigint.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static bigint(value: unknown): bigint | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.bigint(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn BigInt(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst parsed = Number.parseFloat(value);\n\t\t\tif (Is.integer(parsed)) {\n\t\t\t\treturn BigInt(parsed);\n\t\t\t}\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? 1n : 0n;\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a boolean.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static boolean(value: unknown): boolean | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\t// eslint-disable-next-line no-unneeded-ternary\n\t\t\treturn value ? true : false;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tif (/true/i.test(value)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (/false/i.test(value)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a date.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static date(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn new Date(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate());\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a date/time.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static dateTime(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn new Date(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(\n\t\t\t\t\tdt.getUTCFullYear(),\n\t\t\t\t\tdt.getUTCMonth(),\n\t\t\t\t\tdt.getUTCDate(),\n\t\t\t\t\tdt.getUTCHours(),\n\t\t\t\t\tdt.getUTCMinutes(),\n\t\t\t\t\tdt.getUTCSeconds(),\n\t\t\t\t\tdt.getUTCMilliseconds()\n\t\t\t\t);\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a time.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static time(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tdt.setFullYear(1970, 0, 1);\n\t\t\treturn dt;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(\n\t\t\t\t\t1970,\n\t\t\t\t\t0,\n\t\t\t\t\t1,\n\t\t\t\t\tdt.getUTCHours(),\n\t\t\t\t\tdt.getUTCMinutes(),\n\t\t\t\t\tdt.getUTCSeconds(),\n\t\t\t\t\tdt.getUTCMilliseconds()\n\t\t\t\t);\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to an object.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static object<T = unknown>(value: unknown): T | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.object<T>(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.stringValue(value)) {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(value) as T;\n\t\t\t} catch {}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a Uint8Array.\n\t * @param value The value to coerce.\n\t * @throws TypeError If the value can not be coerced.\n\t * @returns The value if it can be coerced.\n\t */\n\tpublic static uint8Array(value: unknown): Uint8Array | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tif (Is.stringHex(value.toLowerCase(), true)) {\n\t\t\t\treturn Converter.hexToBytes(value.toLowerCase());\n\t\t\t}\n\t\t\tif (Is.stringBase64(value)) {\n\t\t\t\treturn Converter.base64ToBytes(value);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerces a value based on the coercion type.\n\t * @param value The value to coerce.\n\t * @param type The coercion type to perform.\n\t * @returns The coerced value.\n\t */\n\tpublic static byType(value: unknown, type?: CoerceType): unknown {\n\t\tswitch (type) {\n\t\t\tcase CoerceType.String:\n\t\t\t\treturn Coerce.string(value);\n\t\t\tcase CoerceType.Number:\n\t\t\t\treturn Coerce.number(value);\n\t\t\tcase CoerceType.Integer:\n\t\t\t\treturn Coerce.integer(value);\n\t\t\tcase CoerceType.BigInt:\n\t\t\t\treturn Coerce.bigint(value);\n\t\t\tcase CoerceType.Boolean:\n\t\t\t\treturn Coerce.boolean(value);\n\t\t\tcase CoerceType.Date:\n\t\t\t\treturn Coerce.date(value);\n\t\t\tcase CoerceType.DateTime:\n\t\t\t\treturn Coerce.dateTime(value);\n\t\t\tcase CoerceType.Time:\n\t\t\t\treturn Coerce.time(value);\n\t\t\tcase CoerceType.Object:\n\t\t\t\treturn Coerce.object(value);\n\t\t\tcase CoerceType.Uint8Array:\n\t\t\t\treturn Coerce.uint8Array(value);\n\t\t\tdefault:\n\t\t\t\treturn value;\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"coerce.js","sourceRoot":"","sources":["../../../src/utils/coerce.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,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;YAC/B;gBACC,OAAO,KAAK,CAAC;QACf,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Converter } from \"./converter.js\";\nimport { Is } from \"./is.js\";\nimport { CoerceType } from \"../models/coerceType.js\";\nimport type { IDuration } from \"../models/IDuration.js\";\nimport { Duration } from \"../types/duration.js\";\n\n/**\n * Coerce an object from one type to another.\n */\nexport class Coerce {\n\t/**\n\t * Coerce the value to a string.\n\t * @param value The value to coerce.\n\t * @returns The coerced string, or undefined if the value cannot be coerced.\n\t */\n\tpublic static string(value: unknown): string | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn value.toString();\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? \"true\" : \"false\";\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value.toISOString();\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a number.\n\t * @param value The value to coerce.\n\t * @returns The coerced number, or undefined if the value cannot be coerced.\n\t */\n\tpublic static number(value: unknown): number | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst parsed = Number.parseFloat(value);\n\t\t\tif (Is.number(parsed)) {\n\t\t\t\treturn parsed;\n\t\t\t}\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? 1 : 0;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value.getTime();\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to an integer.\n\t * @param value The value to coerce.\n\t * @returns The coerced integer, or undefined if the value cannot be coerced.\n\t */\n\tpublic static integer(value: unknown): number | undefined {\n\t\tconst num = Coerce.number(value);\n\t\tif (!Is.undefined(num)) {\n\t\t\treturn Math.trunc(num);\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a bigint.\n\t * @param value The value to coerce.\n\t * @returns The coerced bigint, or undefined if the value cannot be coerced.\n\t */\n\tpublic static bigint(value: unknown): bigint | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.bigint(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn BigInt(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst parsed = Number.parseFloat(value);\n\t\t\tif (Is.integer(parsed)) {\n\t\t\t\treturn BigInt(parsed);\n\t\t\t}\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value ? 1n : 0n;\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a boolean.\n\t * @param value The value to coerce.\n\t * @returns The coerced boolean, or undefined if the value cannot be coerced.\n\t */\n\tpublic static boolean(value: unknown): boolean | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.boolean(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\t// eslint-disable-next-line no-unneeded-ternary\n\t\t\treturn value ? true : false;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tif (/true/i.test(value)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (/false/i.test(value)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a date.\n\t * @param value The value to coerce.\n\t * @returns The coerced date, or undefined if the value cannot be coerced.\n\t */\n\tpublic static date(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn new Date(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate());\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a date/time.\n\t * @param value The value to coerce.\n\t * @returns The coerced date/time, or undefined if the value cannot be coerced.\n\t */\n\tpublic static dateTime(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn new Date(value);\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(\n\t\t\t\t\tdt.getUTCFullYear(),\n\t\t\t\t\tdt.getUTCMonth(),\n\t\t\t\t\tdt.getUTCDate(),\n\t\t\t\t\tdt.getUTCHours(),\n\t\t\t\t\tdt.getUTCMinutes(),\n\t\t\t\t\tdt.getUTCSeconds(),\n\t\t\t\t\tdt.getUTCMilliseconds()\n\t\t\t\t);\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a time.\n\t * @param value The value to coerce.\n\t * @returns The coerced time, or undefined if the value cannot be coerced.\n\t */\n\tpublic static time(value: unknown): Date | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.date(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tdt.setFullYear(1970, 0, 1);\n\t\t\treturn dt;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tconst dt = new Date(value);\n\t\t\tif (!Number.isNaN(dt.getTime())) {\n\t\t\t\tconst utc = Date.UTC(\n\t\t\t\t\t1970,\n\t\t\t\t\t0,\n\t\t\t\t\t1,\n\t\t\t\t\tdt.getUTCHours(),\n\t\t\t\t\tdt.getUTCMinutes(),\n\t\t\t\t\tdt.getUTCSeconds(),\n\t\t\t\t\tdt.getUTCMilliseconds()\n\t\t\t\t);\n\t\t\t\treturn new Date(utc);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a duration object.\n\t * Accepts an IDuration object, ISO 8601 duration strings (e.g. \"PT1H\", \"P1Y2M3DT4H5M6S\"),\n\t * or numeric values already expressed as seconds (stored in the seconds field).\n\t * @param value The value to coerce.\n\t * @returns The duration object, or undefined if the value cannot be coerced.\n\t */\n\tpublic static duration(value: unknown): IDuration | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (Is.duration(value) && !Is.string(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.number(value)) {\n\t\t\treturn { years: 0, months: 0, weeks: 0, days: 0, hours: 0, minutes: 0, seconds: value };\n\t\t}\n\t\tif (Is.stringValue(value)) {\n\t\t\treturn Duration.parse(value);\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to an object.\n\t * @param value The value to coerce.\n\t * @returns The coerced object, or undefined if the value cannot be coerced.\n\t */\n\tpublic static object<T = unknown>(value: unknown): T | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.object<T>(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.stringValue(value)) {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(value) as T;\n\t\t\t} catch {}\n\t\t}\n\t}\n\n\t/**\n\t * Coerce the value to a Uint8Array.\n\t * @param value The value to coerce.\n\t * @returns The coerced Uint8Array, or undefined if the value cannot be coerced.\n\t */\n\tpublic static uint8Array(value: unknown): Uint8Array | undefined {\n\t\tif (Is.undefined(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Is.string(value)) {\n\t\t\tif (Is.stringHex(value.toLowerCase(), true)) {\n\t\t\t\treturn Converter.hexToBytes(value.toLowerCase());\n\t\t\t}\n\t\t\tif (Is.stringBase64(value)) {\n\t\t\t\treturn Converter.base64ToBytes(value);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Coerces a value based on the coercion type.\n\t * @param value The value to coerce.\n\t * @param type The coercion type to perform.\n\t * @returns The coerced value.\n\t */\n\tpublic static byType(value: unknown, type?: CoerceType): unknown {\n\t\tswitch (type) {\n\t\t\tcase CoerceType.String:\n\t\t\t\treturn Coerce.string(value);\n\t\t\tcase CoerceType.Number:\n\t\t\t\treturn Coerce.number(value);\n\t\t\tcase CoerceType.Integer:\n\t\t\t\treturn Coerce.integer(value);\n\t\t\tcase CoerceType.BigInt:\n\t\t\t\treturn Coerce.bigint(value);\n\t\t\tcase CoerceType.Boolean:\n\t\t\t\treturn Coerce.boolean(value);\n\t\t\tcase CoerceType.Date:\n\t\t\t\treturn Coerce.date(value);\n\t\t\tcase CoerceType.DateTime:\n\t\t\t\treturn Coerce.dateTime(value);\n\t\t\tcase CoerceType.Time:\n\t\t\t\treturn Coerce.time(value);\n\t\t\tcase CoerceType.Object:\n\t\t\t\treturn Coerce.object(value);\n\t\t\tcase CoerceType.Uint8Array:\n\t\t\t\treturn Coerce.uint8Array(value);\n\t\t\tcase CoerceType.Duration:\n\t\t\t\treturn Coerce.duration(value);\n\t\t\tdefault:\n\t\t\t\treturn value;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -9,7 +9,7 @@ export class Compression {
|
|
|
9
9
|
*/
|
|
10
10
|
static CLASS_NAME = "Compression";
|
|
11
11
|
/**
|
|
12
|
-
* Compress bytes using
|
|
12
|
+
* Compress bytes using the specified compression type.
|
|
13
13
|
* @param bytes The bytes to compress.
|
|
14
14
|
* @param type The type of compression to use.
|
|
15
15
|
* @returns The compressed bytes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compression.js","sourceRoot":"","sources":["../../../src/utils/compression.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MA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QACpF,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,UAAgB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;QAE9F,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACzD,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;QACzE,MAAM,gBAAgB,GAAG,MAAM,IAAI,QAAQ,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC;QAEtE,OAAO,IAAI,UAAU,CAAC,MAAM,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;IACvD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@twin.org/nameof\";\nimport { Guards } from \"./guards.js\";\nimport { CompressionType } from \"../models/compressionType.js\";\n\n/**\n * A class to handle compression.\n */\nexport class Compression {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Compression>();\n\n\t/**\n\t * Compress bytes using
|
|
1
|
+
{"version":3,"file":"compression.js","sourceRoot":"","sources":["../../../src/utils/compression.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;GAEG;AACH,MAAM,OAAO,WAAW;IACvB;;OAEG;IACI,MAAM,CAAU,UAAU,iBAAiC;IAElE;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAiB,EAAE,IAAqB;QACpE,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAChE,M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AM,EAAE,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;QACzE,MAAM,gBAAgB,GAAG,MAAM,IAAI,QAAQ,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC;QAEtE,OAAO,IAAI,UAAU,CAAC,MAAM,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;IACvD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { nameof } from \"@twin.org/nameof\";\nimport { Guards } from \"./guards.js\";\nimport { CompressionType } from \"../models/compressionType.js\";\n\n/**\n * A class to handle compression.\n */\nexport class Compression {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Compression>();\n\n\t/**\n\t * Compress bytes using the specified compression type.\n\t * @param bytes The bytes to compress.\n\t * @param type The type of compression to use.\n\t * @returns The compressed bytes.\n\t */\n\tpublic static async compress(bytes: Uint8Array, type: CompressionType): Promise<Uint8Array> {\n\t\tGuards.uint8Array(Compression.CLASS_NAME, nameof(bytes), bytes);\n\t\tGuards.arrayOneOf(Compression.CLASS_NAME, nameof(type), type, Object.values(CompressionType));\n\n\t\tconst blob = new Blob([new Uint8Array(bytes)]);\n\t\tconst compressionStream = new CompressionStream(type);\n\t\tconst compressionPipe = blob.stream().pipeThrough(compressionStream);\n\t\tconst compressedBlob = await new Response(compressionPipe).blob();\n\n\t\tconst compressedBytes = new Uint8Array(await compressedBlob.arrayBuffer());\n\n\t\t// GZIP header contains a byte which specifies the OS the\n\t\t// compression was performed on. We set this to 3 (Unix) to ensure\n\t\t// that we produce consistent results.\n\t\tif (type === CompressionType.Gzip && compressedBytes.length >= 10) {\n\t\t\tcompressedBytes[9] = 3;\n\t\t}\n\n\t\treturn compressedBytes;\n\t}\n\n\t/**\n\t * Decompress a gzipped compressed byte array.\n\t * @param compressedBytes The compressed bytes.\n\t * @param type The type of compression to use.\n\t * @returns The decompressed bytes.\n\t */\n\tpublic static async decompress(\n\t\tcompressedBytes: Uint8Array,\n\t\ttype: CompressionType\n\t): Promise<Uint8Array> {\n\t\tGuards.uint8Array(Compression.CLASS_NAME, nameof(compressedBytes), compressedBytes);\n\t\tGuards.arrayOneOf(Compression.CLASS_NAME, nameof(type), type, Object.values(CompressionType));\n\n\t\tconst blob = new Blob([new Uint8Array(compressedBytes)]);\n\t\tconst decompressionStream = new DecompressionStream(type);\n\t\tconst decompressionPipe = blob.stream().pipeThrough(decompressionStream);\n\t\tconst decompressedBlob = await new Response(decompressionPipe).blob();\n\n\t\treturn new Uint8Array(await decompressedBlob.bytes());\n\t}\n}\n"]}
|
package/dist/es/utils/guards.js
CHANGED
|
@@ -417,5 +417,17 @@ export class Guards {
|
|
|
417
417
|
throw new GuardError(source, "guard.uuidV7", property, value);
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* Is the property a valid ISO 8601 duration string or IDuration object.
|
|
422
|
+
* @param source The source of the error.
|
|
423
|
+
* @param property The name of the property.
|
|
424
|
+
* @param value The value to test.
|
|
425
|
+
* @throws GuardError If the value does not match the assertion.
|
|
426
|
+
*/
|
|
427
|
+
static duration(source, property, value) {
|
|
428
|
+
if (!Is.duration(value)) {
|
|
429
|
+
throw new GuardError(source, "guard.duration", property, value);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
420
432
|
}
|
|
421
433
|
//# sourceMappingURL=guards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD;;GAEG;AACH,MAAM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AAC,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CACnB,MAAc,EACd,QAAgB,EAChB,KAAc,EACd,MAA+B;QAE/B,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;YAC/B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,qBAAqB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;YACtE,CAAC;YACD,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"./is.js\";\nimport { GuardError } from \"../errors/guardError.js\";\nimport { ArrayHelper } from \"../helpers/arrayHelper.js\";\nimport { HexHelper } from \"../helpers/hexHelper.js\";\nimport type { ObjectOrArray } from \"../types/objectOrArray.js\";\n\n/**\n * Class to handle guard operations for parameters.\n */\nexport class Guards {\n\t/**\n\t * Is the property defined.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static defined(source: string, property: string, value: unknown): asserts value {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.undefined\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static string(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringValue(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.stringEmpty\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a JSON value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static json(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.json(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringJson\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 url string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64Url(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64Url(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64Url\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base58 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase58(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase58(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase58\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHex(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringValue(source, property, value);\n\t\tif (!HexHelper.isHex(value, allowPrefix)) {\n\t\t\tthrow new GuardError(source, \"guard.stringHex\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value with fixed length.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param length The length of the string to match.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHexLength(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tlength: number,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringHex(source, property, value, allowPrefix);\n\t\tif (HexHelper.stripPrefix(value).length !== length) {\n\t\t\tthrow new GuardError(\n\t\t\t\tsource,\n\t\t\t\t\"guard.stringHexLength\",\n\t\t\t\tproperty,\n\t\t\t\tvalue.length,\n\t\t\t\tlength.toString()\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a number.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static number(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.number(value)) {\n\t\t\tthrow new GuardError(source, \"guard.number\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an integer.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static integer(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\tthrow new GuardError(source, \"guard.integer\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a bigint.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static bigint(source: string, property: string, value: unknown): asserts value is bigint {\n\t\tif (!Is.bigint(value)) {\n\t\t\tthrow new GuardError(source, \"guard.bigint\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a boolean.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static boolean(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is boolean {\n\t\tif (!Is.boolean(value)) {\n\t\t\tthrow new GuardError(source, \"guard.boolean\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a date.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static date(source: string, property: string, value: unknown): asserts value is Date {\n\t\tif (!Is.date(value)) {\n\t\t\tthrow new GuardError(source, \"guard.date\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a date-only string (ISO 8601 date, no time component).\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static dateString(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.dateString(value)) {\n\t\t\tthrow new GuardError(source, \"guard.dateString\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a date-time string (ISO 8601 with T separator).\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static dateTimeString(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.dateTimeString(value)) {\n\t\t\tthrow new GuardError(source, \"guard.dateTimeString\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a time-only string (ISO 8601 time, no date component).\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timeString(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.timeString(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timeString\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in milliseconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampMilliseconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampMilliseconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampMilliseconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in seconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampSeconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampSeconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampSeconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an object.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static object<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an object with at least one property.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static objectValue<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t\tif (Object.keys(value || {}).length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.objectValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static array<T>(source: string, property: string, value: unknown): asserts value is T[] {\n\t\tif (!Is.array<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array with at least one item.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayValue<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T[] {\n\t\tif (!Is.array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.arrayValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property one of a list of items.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param options The options the value must be one of.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayOneOf<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: T,\n\t\toptions: T[]\n\t): asserts value is T {\n\t\tif (!Is.array<T>(options)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (!options.includes(value)) {\n\t\t\tthrow new GuardError(source, \"guard.arrayOneOf\", property, value, options.join(\", \"));\n\t\t}\n\t}\n\n\t/**\n\t * Does the array start with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param startValues The values that must start the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayStartsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tstartValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst startValuesArray = ArrayHelper.fromObjectOrArray(startValues);\n\n\t\tif (!Is.arrayValue<T>(startValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, startValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < startValuesArray.length; i++) {\n\t\t\tif (value[i] !== startValuesArray[i]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayStartsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tstartValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Does the array end with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param endValues The values that must end the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayEndsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tendValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst endValuesArray = ArrayHelper.fromObjectOrArray(endValues);\n\n\t\tif (!Is.arrayValue<T>(endValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, endValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < endValuesArray.length; i++) {\n\t\t\tif (value[value.length - i - 1] !== endValuesArray[endValuesArray.length - i - 1]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayEndsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tendValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a Uint8Array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uint8Array(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is Uint8Array {\n\t\tif (!Is.uint8Array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.uint8Array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a function.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static function<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (!Is.function<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.function\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string formatted as an email address.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static email(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.email(value)) {\n\t\t\tthrow new GuardError(source, \"guard.email\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string containing uuidV7.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param format The format of the uuidV7, either standard or compact.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uuidV7(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tformat?: \"standard\" | \"compact\"\n\t): asserts value is string {\n\t\tif (!Is.uuidV7(value, format)) {\n\t\t\tif (format === \"compact\") {\n\t\t\t\tthrow new GuardError(source, \"guard.uuidV7Compact\", property, value);\n\t\t\t}\n\t\t\tthrow new GuardError(source, \"guard.uuidV7\", property, value);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAIpD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;;;;;OAMG;IACI,MAAM,CAAC,OAAO,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAc;QACrE,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClE,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,QAAgB,EA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AAM,EAAE,qBAAqB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;YACtE,CAAC;YACD,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,QAAQ,CACrB,MAAc,EACd,QAAgB,EAChB,KAAc;QAEd,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QACjE,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is } from \"./is.js\";\nimport { GuardError } from \"../errors/guardError.js\";\nimport { ArrayHelper } from \"../helpers/arrayHelper.js\";\nimport { HexHelper } from \"../helpers/hexHelper.js\";\nimport type { IDuration } from \"../models/IDuration.js\";\nimport type { ObjectOrArray } from \"../types/objectOrArray.js\";\n\n/**\n * Class to handle guard operations for parameters.\n */\nexport class Guards {\n\t/**\n\t * Is the property defined.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static defined(source: string, property: string, value: unknown): asserts value {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.undefined\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static string(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringValue(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.string(value)) {\n\t\t\tthrow new GuardError(source, \"guard.string\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.stringEmpty\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a JSON value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static json(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.json(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringJson\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base64 url string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase64Url(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase64Url(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase64Url\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a base58 string.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringBase58(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.stringBase58(value)) {\n\t\t\tthrow new GuardError(source, \"guard.stringBase58\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHex(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringValue(source, property, value);\n\t\tif (!HexHelper.isHex(value, allowPrefix)) {\n\t\t\tthrow new GuardError(source, \"guard.stringHex\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string with a hex value with fixed length.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param length The length of the string to match.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static stringHexLength(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tlength: number,\n\t\tallowPrefix: boolean = false\n\t): asserts value is string {\n\t\tGuards.stringHex(source, property, value, allowPrefix);\n\t\tif (HexHelper.stripPrefix(value).length !== length) {\n\t\t\tthrow new GuardError(\n\t\t\t\tsource,\n\t\t\t\t\"guard.stringHexLength\",\n\t\t\t\tproperty,\n\t\t\t\tvalue.length,\n\t\t\t\tlength.toString()\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a number.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static number(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.number(value)) {\n\t\t\tthrow new GuardError(source, \"guard.number\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an integer.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static integer(source: string, property: string, value: unknown): asserts value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\tthrow new GuardError(source, \"guard.integer\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a bigint.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static bigint(source: string, property: string, value: unknown): asserts value is bigint {\n\t\tif (!Is.bigint(value)) {\n\t\t\tthrow new GuardError(source, \"guard.bigint\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a boolean.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static boolean(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is boolean {\n\t\tif (!Is.boolean(value)) {\n\t\t\tthrow new GuardError(source, \"guard.boolean\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a date.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static date(source: string, property: string, value: unknown): asserts value is Date {\n\t\tif (!Is.date(value)) {\n\t\t\tthrow new GuardError(source, \"guard.date\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a date-only string (ISO 8601 date, no time component).\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static dateString(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.dateString(value)) {\n\t\t\tthrow new GuardError(source, \"guard.dateString\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a date-time string (ISO 8601 with T separator).\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static dateTimeString(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.dateTimeString(value)) {\n\t\t\tthrow new GuardError(source, \"guard.dateTimeString\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a time-only string (ISO 8601 time, no date component).\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timeString(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string {\n\t\tif (!Is.timeString(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timeString\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in milliseconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampMilliseconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampMilliseconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampMilliseconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a timestamp in seconds.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static timestampSeconds(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is number {\n\t\tif (!Is.timestampSeconds(value)) {\n\t\t\tthrow new GuardError(source, \"guard.timestampSeconds\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property an object.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static object<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an object with at least one property.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static objectValue<T = { [id: string]: unknown }>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (Is.undefined(value)) {\n\t\t\tthrow new GuardError(source, \"guard.objectUndefined\", property, value);\n\t\t}\n\t\tif (!Is.object<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.object\", property, value);\n\t\t}\n\t\tif (Object.keys(value || {}).length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.objectValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static array<T>(source: string, property: string, value: unknown): asserts value is T[] {\n\t\tif (!Is.array<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property is an array with at least one item.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayValue<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T[] {\n\t\tif (!Is.array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (value.length === 0) {\n\t\t\tthrow new GuardError(source, \"guard.arrayValue\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property one of a list of items.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param options The options the value must be one of.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayOneOf<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: T,\n\t\toptions: T[]\n\t): asserts value is T {\n\t\tif (!Is.array<T>(options)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\t\tif (!options.includes(value)) {\n\t\t\tthrow new GuardError(source, \"guard.arrayOneOf\", property, value, options.join(\", \"));\n\t\t}\n\t}\n\n\t/**\n\t * Does the array start with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param startValues The values that must start the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayStartsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tstartValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst startValuesArray = ArrayHelper.fromObjectOrArray(startValues);\n\n\t\tif (!Is.arrayValue<T>(startValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, startValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < startValuesArray.length; i++) {\n\t\t\tif (value[i] !== startValuesArray[i]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayStartsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tstartValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Does the array end with the specified data.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param endValues The values that must end the array.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static arrayEndsWith<T>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tendValues: ObjectOrArray<T>\n\t): asserts value is T[] {\n\t\tif (!Is.arrayValue<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, value);\n\t\t}\n\n\t\tconst endValuesArray = ArrayHelper.fromObjectOrArray(endValues);\n\n\t\tif (!Is.arrayValue<T>(endValuesArray)) {\n\t\t\tthrow new GuardError(source, \"guard.array\", property, endValuesArray);\n\t\t}\n\n\t\tfor (let i = 0; i < endValuesArray.length; i++) {\n\t\t\tif (value[value.length - i - 1] !== endValuesArray[endValuesArray.length - i - 1]) {\n\t\t\t\tthrow new GuardError(\n\t\t\t\t\tsource,\n\t\t\t\t\t\"guard.arrayEndsWith\",\n\t\t\t\t\tproperty,\n\t\t\t\t\tvalue,\n\t\t\t\t\tendValuesArray.join(\", \")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a Uint8Array.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uint8Array(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is Uint8Array {\n\t\tif (!Is.uint8Array(value)) {\n\t\t\tthrow new GuardError(source, \"guard.uint8Array\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a function.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static function<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is T {\n\t\tif (!Is.function<T>(value)) {\n\t\t\tthrow new GuardError(source, \"guard.function\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string formatted as an email address.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static email(source: string, property: string, value: unknown): asserts value is string {\n\t\tif (!Is.email(value)) {\n\t\t\tthrow new GuardError(source, \"guard.email\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a string containing uuidV7.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @param format The format of the uuidV7, either standard or compact.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static uuidV7(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown,\n\t\tformat?: \"standard\" | \"compact\"\n\t): asserts value is string {\n\t\tif (!Is.uuidV7(value, format)) {\n\t\t\tif (format === \"compact\") {\n\t\t\t\tthrow new GuardError(source, \"guard.uuidV7Compact\", property, value);\n\t\t\t}\n\t\t\tthrow new GuardError(source, \"guard.uuidV7\", property, value);\n\t\t}\n\t}\n\n\t/**\n\t * Is the property a valid ISO 8601 duration string or IDuration object.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The value to test.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static duration(\n\t\tsource: string,\n\t\tproperty: string,\n\t\tvalue: unknown\n\t): asserts value is string | IDuration {\n\t\tif (!Is.duration(value)) {\n\t\t\tthrow new GuardError(source, \"guard.duration\", property, value);\n\t\t}\n\t}\n}\n"]}
|
package/dist/es/utils/is.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2024 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { HexHelper } from "../helpers/hexHelper.js";
|
|
4
|
+
import { DURATION_REG_EXP } from "../types/durationRegExp.js";
|
|
4
5
|
/**
|
|
5
6
|
* Class to check types of objects.
|
|
6
7
|
*/
|
|
@@ -8,7 +9,7 @@ export class Is {
|
|
|
8
9
|
/**
|
|
9
10
|
* Is the property undefined.
|
|
10
11
|
* @param value The value to test.
|
|
11
|
-
* @returns True if the value is
|
|
12
|
+
* @returns True if the value is undefined.
|
|
12
13
|
*/
|
|
13
14
|
static undefined(value) {
|
|
14
15
|
return value === undefined;
|
|
@@ -16,7 +17,7 @@ export class Is {
|
|
|
16
17
|
/**
|
|
17
18
|
* Is the property null.
|
|
18
19
|
* @param value The value to test.
|
|
19
|
-
* @returns True if the value is
|
|
20
|
+
* @returns True if the value is null.
|
|
20
21
|
*/
|
|
21
22
|
static null(value) {
|
|
22
23
|
return value === null;
|
|
@@ -24,15 +25,15 @@ export class Is {
|
|
|
24
25
|
/**
|
|
25
26
|
* Is the property null or undefined.
|
|
26
27
|
* @param value The value to test.
|
|
27
|
-
* @returns True if the value is
|
|
28
|
+
* @returns True if the value is null or undefined.
|
|
28
29
|
*/
|
|
29
30
|
static empty(value) {
|
|
30
31
|
return value === null || value === undefined;
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
|
-
* Is the property
|
|
34
|
+
* Is the property not null or undefined.
|
|
34
35
|
* @param value The value to test.
|
|
35
|
-
* @returns True if the value is
|
|
36
|
+
* @returns True if the value is not null or undefined.
|
|
36
37
|
*/
|
|
37
38
|
static notEmpty(value) {
|
|
38
39
|
return value !== null && value !== undefined;
|
|
@@ -46,9 +47,9 @@ export class Is {
|
|
|
46
47
|
return typeof value === "string";
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
|
-
* Is the value a string.
|
|
50
|
+
* Is the value a non-empty string.
|
|
50
51
|
* @param value The value to test.
|
|
51
|
-
* @returns True if the value is a string.
|
|
52
|
+
* @returns True if the value is a non-empty string.
|
|
52
53
|
*/
|
|
53
54
|
static stringValue(value) {
|
|
54
55
|
return Is.string(value) && value.trim().length > 0;
|
|
@@ -82,7 +83,6 @@ export class Is {
|
|
|
82
83
|
*/
|
|
83
84
|
static stringBase64(value) {
|
|
84
85
|
return (Is.stringValue(value) &&
|
|
85
|
-
// eslint-disable-next-line unicorn/better-regex
|
|
86
86
|
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value));
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
@@ -91,9 +91,7 @@ export class Is {
|
|
|
91
91
|
* @returns True if the value is a base64 string.
|
|
92
92
|
*/
|
|
93
93
|
static stringBase64Url(value) {
|
|
94
|
-
return
|
|
95
|
-
// eslint-disable-next-line unicorn/better-regex
|
|
96
|
-
/^([A-Za-z0-9-_])*$/.test(value));
|
|
94
|
+
return Is.stringValue(value) && /^([A-Za-z0-9-_])*$/.test(value);
|
|
97
95
|
}
|
|
98
96
|
/**
|
|
99
97
|
* Is the value a base58 string.
|
|
@@ -101,9 +99,7 @@ export class Is {
|
|
|
101
99
|
* @returns True if the value is a base58 string.
|
|
102
100
|
*/
|
|
103
101
|
static stringBase58(value) {
|
|
104
|
-
return
|
|
105
|
-
// eslint-disable-next-line unicorn/better-regex
|
|
106
|
-
/^[A-HJ-NP-Za-km-z1-9]*$/.test(value));
|
|
102
|
+
return Is.stringValue(value) && /^[A-HJ-NP-Za-km-z1-9]*$/.test(value);
|
|
107
103
|
}
|
|
108
104
|
/**
|
|
109
105
|
* Is the value a hex string.
|
|
@@ -210,7 +206,7 @@ export class Is {
|
|
|
210
206
|
/**
|
|
211
207
|
* Is the value a timestamp in seconds.
|
|
212
208
|
* @param value The value to test.
|
|
213
|
-
* @returns True if the value is a
|
|
209
|
+
* @returns True if the value is a timestamp in seconds.
|
|
214
210
|
*/
|
|
215
211
|
static timestampSeconds(value) {
|
|
216
212
|
if (!Is.integer(value)) {
|
|
@@ -221,7 +217,7 @@ export class Is {
|
|
|
221
217
|
/**
|
|
222
218
|
* Is the value a timestamp in milliseconds.
|
|
223
219
|
* @param value The value to test.
|
|
224
|
-
* @returns True if the value is a
|
|
220
|
+
* @returns True if the value is a timestamp in milliseconds.
|
|
225
221
|
*/
|
|
226
222
|
static timestampMilliseconds(value) {
|
|
227
223
|
if (!Is.integer(value)) {
|
|
@@ -363,5 +359,58 @@ export class Is {
|
|
|
363
359
|
return (Is.stringValue(value) &&
|
|
364
360
|
/^[\da-f]{8}-[\da-f]{4}-7[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(value));
|
|
365
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Is the value a valid ISO 8601 duration string or an IDuration object.
|
|
364
|
+
* @param value The value to test.
|
|
365
|
+
* @returns True if the value is a valid ISO 8601 duration string or an IDuration object.
|
|
366
|
+
*/
|
|
367
|
+
static duration(value) {
|
|
368
|
+
if (Is.object(value)) {
|
|
369
|
+
if (!Is.number(value.years) ||
|
|
370
|
+
!Is.number(value.months) ||
|
|
371
|
+
!Is.number(value.weeks) ||
|
|
372
|
+
!Is.number(value.days) ||
|
|
373
|
+
!Is.number(value.hours) ||
|
|
374
|
+
!Is.number(value.minutes) ||
|
|
375
|
+
!Is.number(value.seconds) ||
|
|
376
|
+
(!Is.undefined(value.milliseconds) &&
|
|
377
|
+
(!Is.integer(value.milliseconds) || Math.abs(value.milliseconds) > 999)) ||
|
|
378
|
+
(!Is.undefined(value.microseconds) &&
|
|
379
|
+
(!Is.integer(value.microseconds) || Math.abs(value.microseconds) > 999)) ||
|
|
380
|
+
(!Is.undefined(value.nanoseconds) &&
|
|
381
|
+
(!Is.integer(value.nanoseconds) || Math.abs(value.nanoseconds) > 999))) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
let sign = 0;
|
|
385
|
+
for (const component of [
|
|
386
|
+
value.years,
|
|
387
|
+
value.months,
|
|
388
|
+
value.weeks,
|
|
389
|
+
value.days,
|
|
390
|
+
value.hours,
|
|
391
|
+
value.minutes,
|
|
392
|
+
value.seconds,
|
|
393
|
+
value.milliseconds ?? 0,
|
|
394
|
+
value.microseconds ?? 0,
|
|
395
|
+
value.nanoseconds ?? 0
|
|
396
|
+
]) {
|
|
397
|
+
if (component !== 0) {
|
|
398
|
+
const componentSign = component < 0 ? -1 : 1;
|
|
399
|
+
if (sign === 0) {
|
|
400
|
+
sign = componentSign;
|
|
401
|
+
}
|
|
402
|
+
else if (sign !== componentSign) {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
if (!Is.stringValue(value)) {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
const match = DURATION_REG_EXP.exec(value);
|
|
413
|
+
return Boolean(match?.slice(2).some(Boolean));
|
|
414
|
+
}
|
|
366
415
|
}
|
|
367
416
|
//# sourceMappingURL=is.js.map
|
package/dist/es/utils/is.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is.js","sourceRoot":"","sources":["../../../src/utils/is.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,EAAE;IACd;;;;OAIG;IACI,MAAM,CAAC,SAAS,CAAC,KAAc;QACrC,OAAO,KAAK,KAAK,SAAS,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAC,KAAc;QAChC,OAAO,KAAK,KAAK,IAAI,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,KAAc;QACjC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,KAAc;QACpC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,KAAc;QAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAC,KAAc;QACvC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GA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,CAAC,KAAc,EAAE,MAA+B;QACnE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,uBAAuB;YACvB,kDAAkD;YAClD,2DAA2D;YAC3D,OAAO,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,4CAA4C,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1F,CAAC;QAED,OAAO,CACN,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC;YACrB,mEAAmE,CAAC,IAAI,CAAC,KAAK,CAAC,CAC/E,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { HexHelper } from \"../helpers/hexHelper.js\";\n\n/**\n * Class to check types of objects.\n */\nexport class Is {\n\t/**\n\t * Is the property undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is a empty.\n\t */\n\tpublic static undefined(value: unknown): value is undefined {\n\t\treturn value === undefined;\n\t}\n\n\t/**\n\t * Is the property null.\n\t * @param value The value to test.\n\t * @returns True if the value is a empty.\n\t */\n\tpublic static null(value: unknown): value is null {\n\t\treturn value === null;\n\t}\n\n\t/**\n\t * Is the property null or undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is a empty.\n\t */\n\tpublic static empty(value: unknown): value is undefined | null {\n\t\treturn value === null || value === undefined;\n\t}\n\n\t/**\n\t * Is the property is not null or undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is a not empty.\n\t */\n\tpublic static notEmpty(value: unknown): boolean {\n\t\treturn value !== null && value !== undefined;\n\t}\n\n\t/**\n\t * Is the value a string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static string(value: unknown): value is string {\n\t\treturn typeof value === \"string\";\n\t}\n\n\t/**\n\t * Is the value a string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static stringValue(value: unknown): value is string {\n\t\treturn Is.string(value) && value.trim().length > 0;\n\t}\n\n\t/**\n\t * Is the value a JSON string.\n\t * @param value The value to test.\n\t * @returns True if the value is a JSON string.\n\t */\n\tpublic static json(value: unknown): value is string {\n\t\tif (!Is.stringValue(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\ttry {\n\t\t\tconst json = JSON.parse(value);\n\t\t\treturn (\n\t\t\t\tIs.object(json) ||\n\t\t\t\tIs.array(json) ||\n\t\t\t\tIs.string(json) ||\n\t\t\t\tIs.number(json) ||\n\t\t\t\tIs.boolean(json) ||\n\t\t\t\tIs.null(json)\n\t\t\t);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Is the value a base64 string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base64 string.\n\t */\n\tpublic static stringBase64(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t// eslint-disable-next-line unicorn/better-regex\n\t\t\t/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a base64 url string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base64 string.\n\t */\n\tpublic static stringBase64Url(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t// eslint-disable-next-line unicorn/better-regex\n\t\t\t/^([A-Za-z0-9-_])*$/.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a base58 string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base58 string.\n\t */\n\tpublic static stringBase58(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t// eslint-disable-next-line unicorn/better-regex\n\t\t\t/^[A-HJ-NP-Za-km-z1-9]*$/.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a hex string.\n\t * @param value The value to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @returns True if the value is a hex string.\n\t */\n\tpublic static stringHex(value: unknown, allowPrefix: boolean = false): value is string {\n\t\treturn Is.string(value) && HexHelper.isHex(value, allowPrefix);\n\t}\n\n\t/**\n\t * Is the value a hex string of fixed length.\n\t * @param value The value to test.\n\t * @param length The length to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @returns True if the value is a hex string of required length.\n\t */\n\tpublic static stringHexLength(\n\t\tvalue: unknown,\n\t\tlength: number,\n\t\tallowPrefix: boolean = false\n\t): value is string {\n\t\treturn Is.stringHex(value, allowPrefix) && value.length === length;\n\t}\n\n\t/**\n\t * Is the value a number.\n\t * @param value The value to test.\n\t * @returns True if the value is a number.\n\t */\n\tpublic static number(value: unknown): value is number {\n\t\treturn typeof value === \"number\" && Number.isFinite(value) && !Number.isNaN(value);\n\t}\n\n\t/**\n\t * Is the value an integer.\n\t * @param value The value to test.\n\t * @returns True if the value is an integer.\n\t */\n\tpublic static integer(value: unknown): value is number {\n\t\treturn Is.number(value) && Number.isInteger(value);\n\t}\n\n\t/**\n\t * Is the value a big integer.\n\t * @param value The value to test.\n\t * @returns True if the value is a big integer.\n\t */\n\tpublic static bigint(value: unknown): value is bigint {\n\t\treturn typeof value === \"bigint\";\n\t}\n\n\t/**\n\t * Is the value a boolean.\n\t * @param value The value to test.\n\t * @returns True if the value is a boolean.\n\t */\n\tpublic static boolean(value: unknown): value is boolean {\n\t\treturn typeof value === \"boolean\";\n\t}\n\n\t/**\n\t * Is the value a date.\n\t * @param value The value to test.\n\t * @returns True if the value is a date.\n\t */\n\tpublic static date(value: unknown): value is Date {\n\t\treturn (\n\t\t\tObject.prototype.toString.call(value) === \"[object Date]\" &&\n\t\t\t!Number.isNaN((value as Date).getTime())\n\t\t);\n\t}\n\n\t/**\n\t * Is the value an empty date.\n\t * @param value The value to test.\n\t * @returns True if the value is an empty date.\n\t */\n\tpublic static dateEmpty(value: unknown): boolean {\n\t\treturn (\n\t\t\tObject.prototype.toString.call(value) === \"[object Date]\" &&\n\t\t\tNumber.isNaN((value as Date).getTime())\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a date string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 date format.\n\t */\n\tpublic static dateString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(value));\n\t}\n\n\t/**\n\t * Is the value a date string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 date/time format.\n\t */\n\tpublic static dateTimeString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || !value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(value));\n\t}\n\n\t/**\n\t * Is the value a time string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 time format.\n\t */\n\tpublic static timeString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(`1970-01-01T${value}`));\n\t}\n\n\t/**\n\t * Is the value a timestamp in seconds.\n\t * @param value The value to test.\n\t * @returns True if the value is a date.\n\t */\n\tpublic static timestampSeconds(value: unknown): value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn value.toString().length < 12;\n\t}\n\n\t/**\n\t * Is the value a timestamp in milliseconds.\n\t * @param value The value to test.\n\t * @returns True if the value is a date.\n\t */\n\tpublic static timestampMilliseconds(value: unknown): value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn value.toString().length >= 12;\n\t}\n\n\t/**\n\t * Is the value an object.\n\t * @param value The value to test.\n\t * @returns True if the value is a object.\n\t */\n\tpublic static object<T = { [id: string]: unknown }>(value: unknown): value is T {\n\t\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n\t}\n\n\t/**\n\t * Is the value an object with at least one property.\n\t * @param value The value to test.\n\t * @returns True if the value is a object.\n\t */\n\tpublic static objectValue<T = { [id: string]: unknown }>(value: unknown): value is T {\n\t\treturn (\n\t\t\ttypeof value === \"object\" &&\n\t\t\tvalue !== null &&\n\t\t\t!Array.isArray(value) &&\n\t\t\tObject.keys(value).length > 0\n\t\t);\n\t}\n\n\t/**\n\t * Is the value an array.\n\t * @param value The value to test.\n\t * @returns True if the value is an array.\n\t */\n\tpublic static array<T>(value: unknown): value is T[] {\n\t\treturn Array.isArray(value);\n\t}\n\n\t/**\n\t * Is the value an array with at least one element.\n\t * @param value The value to test.\n\t * @returns True if the value is an array with at least one element.\n\t */\n\tpublic static arrayValue<T>(value: unknown): value is T[] {\n\t\treturn Array.isArray(value) && value.length > 0;\n\t}\n\n\t/**\n\t * Is the value an array with at least one element.\n\t * @param value The value to test.\n\t * @param options The options the value must be one of.\n\t * @returns True if the value is an element from the options array.\n\t */\n\tpublic static arrayOneOf<T>(value: T, options: T[]): value is T {\n\t\tif (Is.empty(value) || !Is.array<T>(options) || !options.includes(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Is the value a Uint8Array.\n\t * @param value The value to test.\n\t * @returns True if the value is a Uint8Array.\n\t */\n\tpublic static uint8Array(value: unknown): value is Uint8Array {\n\t\t// This is the only way we can reliably check for Uint8Array\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Uint8Array;\n\t}\n\n\t/**\n\t * Is the value a TypedArray.\n\t * @param value The value to test.\n\t * @returns True if the value is a TypedArray.\n\t */\n\tpublic static typedArray(\n\t\tvalue: unknown\n\t): value is\n\t\t| Uint8Array\n\t\t| Int8Array\n\t\t| Uint16Array\n\t\t| Int16Array\n\t\t| Uint32Array\n\t\t| Int32Array\n\t\t| Float32Array\n\t\t| Float64Array {\n\t\t// This is the only way we can reliably check for TypedArray\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Object.getPrototypeOf(Uint8Array);\n\t}\n\n\t/**\n\t * Is the property a function.\n\t * @param value The value to test.\n\t * @returns True if the value is a function.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static function<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tvalue: unknown\n\t): value is T {\n\t\treturn typeof value === \"function\";\n\t}\n\n\t/**\n\t * Is the value a string formatted as an email address.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static email(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t/^[\\w!#$%&'*+./=?^`{|}~-]+@[\\dA-Za-z](?:[\\dA-Za-z-]{0,61}[\\dA-Za-z])?(?:\\.[\\dA-Za-z](?:[\\dA-Za-z-]{0,61}[\\dA-Za-z])?)*$/.test(\n\t\t\t\tvalue\n\t\t\t)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a promise.\n\t * @param value The value to test.\n\t * @returns True if the value is a promise.\n\t */\n\tpublic static promise<T = unknown>(value: unknown): value is Promise<T> {\n\t\t// This is the only way we can reliably check for Promise\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Promise;\n\t}\n\n\t/**\n\t * Is the value a regexp.\n\t * @param value The value to test.\n\t * @returns True if the value is a regexp.\n\t */\n\tpublic static regexp(value: unknown): value is RegExp {\n\t\t// This is the only way we can reliably check for RegExp\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof RegExp;\n\t}\n\n\t/**\n\t * Is the provided object a class constructor.\n\t * @param obj The object to check.\n\t * @returns True if the object is a class, false otherwise.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static class<T = unknown>(obj: unknown): obj is new (...args: any[]) => T {\n\t\tif (typeof obj !== \"function\") {\n\t\t\treturn false;\n\t\t}\n\t\tconst str = Function.prototype.toString.call(obj);\n\t\treturn /^class\\s/.test(str);\n\t}\n\n\t/**\n\t * Is the value a uuidV7 string.\n\t * @param value The value to test.\n\t * @param format The format of the UUIDv7 string.\n\t * @returns True if the value is a uuidV7 string.\n\t */\n\tpublic static uuidV7(value: unknown, format?: \"standard\" | \"compact\"): value is string {\n\t\tif (format === \"compact\") {\n\t\t\t// 32 hex chars, where:\n\t\t\t// - char 13 (0-based index 12) is the version (7)\n\t\t\t// - char 17 (0-based index 16) is the variant (8, 9, a, b)\n\t\t\treturn Is.stringValue(value) && /^[\\da-f]{12}7[\\da-f]{3}[89ab][\\da-f]{15}$/i.test(value);\n\t\t}\n\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t/^[\\da-f]{8}-[\\da-f]{4}-7[\\da-f]{3}-[89ab][\\da-f]{3}-[\\da-f]{12}$/i.test(value)\n\t\t);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"is.js","sourceRoot":"","sources":["../../../src/utils/is.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;GAEG;AACH,MAAM,OAAO,EAAE;IACd;;;;OAIG;IACI,MAAM,CAAC,SAAS,CAAC,KAAc;QACrC,OAAO,KAAK,KAAK,SAAS,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAC,KAAc;QAChC,OAAO,KAAK,KAAK,IAAI,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,KAAc;QACjC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,KAAc;QACpC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,KAAc;QAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAA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CAAC;YAC5B,OAAO,KAAK,CAAC;QACd,CAAC;QACD,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3C,OAAO,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC/C,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { HexHelper } from \"../helpers/hexHelper.js\";\nimport type { IDuration } from \"../models/IDuration.js\";\nimport { DURATION_REG_EXP } from \"../types/durationRegExp.js\";\n\n/**\n * Class to check types of objects.\n */\nexport class Is {\n\t/**\n\t * Is the property undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is undefined.\n\t */\n\tpublic static undefined(value: unknown): value is undefined {\n\t\treturn value === undefined;\n\t}\n\n\t/**\n\t * Is the property null.\n\t * @param value The value to test.\n\t * @returns True if the value is null.\n\t */\n\tpublic static null(value: unknown): value is null {\n\t\treturn value === null;\n\t}\n\n\t/**\n\t * Is the property null or undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is null or undefined.\n\t */\n\tpublic static empty(value: unknown): value is undefined | null {\n\t\treturn value === null || value === undefined;\n\t}\n\n\t/**\n\t * Is the property not null or undefined.\n\t * @param value The value to test.\n\t * @returns True if the value is not null or undefined.\n\t */\n\tpublic static notEmpty(value: unknown): boolean {\n\t\treturn value !== null && value !== undefined;\n\t}\n\n\t/**\n\t * Is the value a string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static string(value: unknown): value is string {\n\t\treturn typeof value === \"string\";\n\t}\n\n\t/**\n\t * Is the value a non-empty string.\n\t * @param value The value to test.\n\t * @returns True if the value is a non-empty string.\n\t */\n\tpublic static stringValue(value: unknown): value is string {\n\t\treturn Is.string(value) && value.trim().length > 0;\n\t}\n\n\t/**\n\t * Is the value a JSON string.\n\t * @param value The value to test.\n\t * @returns True if the value is a JSON string.\n\t */\n\tpublic static json(value: unknown): value is string {\n\t\tif (!Is.stringValue(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\ttry {\n\t\t\tconst json = JSON.parse(value);\n\t\t\treturn (\n\t\t\t\tIs.object(json) ||\n\t\t\t\tIs.array(json) ||\n\t\t\t\tIs.string(json) ||\n\t\t\t\tIs.number(json) ||\n\t\t\t\tIs.boolean(json) ||\n\t\t\t\tIs.null(json)\n\t\t\t);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Is the value a base64 string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base64 string.\n\t */\n\tpublic static stringBase64(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a base64 url string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base64 string.\n\t */\n\tpublic static stringBase64Url(value: unknown): value is string {\n\t\treturn Is.stringValue(value) && /^([A-Za-z0-9-_])*$/.test(value);\n\t}\n\n\t/**\n\t * Is the value a base58 string.\n\t * @param value The value to test.\n\t * @returns True if the value is a base58 string.\n\t */\n\tpublic static stringBase58(value: unknown): value is string {\n\t\treturn Is.stringValue(value) && /^[A-HJ-NP-Za-km-z1-9]*$/.test(value);\n\t}\n\n\t/**\n\t * Is the value a hex string.\n\t * @param value The value to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @returns True if the value is a hex string.\n\t */\n\tpublic static stringHex(value: unknown, allowPrefix: boolean = false): value is string {\n\t\treturn Is.string(value) && HexHelper.isHex(value, allowPrefix);\n\t}\n\n\t/**\n\t * Is the value a hex string of fixed length.\n\t * @param value The value to test.\n\t * @param length The length to test.\n\t * @param allowPrefix Allow the hex to have the 0x prefix.\n\t * @returns True if the value is a hex string of required length.\n\t */\n\tpublic static stringHexLength(\n\t\tvalue: unknown,\n\t\tlength: number,\n\t\tallowPrefix: boolean = false\n\t): value is string {\n\t\treturn Is.stringHex(value, allowPrefix) && value.length === length;\n\t}\n\n\t/**\n\t * Is the value a number.\n\t * @param value The value to test.\n\t * @returns True if the value is a number.\n\t */\n\tpublic static number(value: unknown): value is number {\n\t\treturn typeof value === \"number\" && Number.isFinite(value) && !Number.isNaN(value);\n\t}\n\n\t/**\n\t * Is the value an integer.\n\t * @param value The value to test.\n\t * @returns True if the value is an integer.\n\t */\n\tpublic static integer(value: unknown): value is number {\n\t\treturn Is.number(value) && Number.isInteger(value);\n\t}\n\n\t/**\n\t * Is the value a big integer.\n\t * @param value The value to test.\n\t * @returns True if the value is a big integer.\n\t */\n\tpublic static bigint(value: unknown): value is bigint {\n\t\treturn typeof value === \"bigint\";\n\t}\n\n\t/**\n\t * Is the value a boolean.\n\t * @param value The value to test.\n\t * @returns True if the value is a boolean.\n\t */\n\tpublic static boolean(value: unknown): value is boolean {\n\t\treturn typeof value === \"boolean\";\n\t}\n\n\t/**\n\t * Is the value a date.\n\t * @param value The value to test.\n\t * @returns True if the value is a date.\n\t */\n\tpublic static date(value: unknown): value is Date {\n\t\treturn (\n\t\t\tObject.prototype.toString.call(value) === \"[object Date]\" &&\n\t\t\t!Number.isNaN((value as Date).getTime())\n\t\t);\n\t}\n\n\t/**\n\t * Is the value an empty date.\n\t * @param value The value to test.\n\t * @returns True if the value is an empty date.\n\t */\n\tpublic static dateEmpty(value: unknown): boolean {\n\t\treturn (\n\t\t\tObject.prototype.toString.call(value) === \"[object Date]\" &&\n\t\t\tNumber.isNaN((value as Date).getTime())\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a date string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 date format.\n\t */\n\tpublic static dateString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(value));\n\t}\n\n\t/**\n\t * Is the value a date string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 date/time format.\n\t */\n\tpublic static dateTimeString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || !value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(value));\n\t}\n\n\t/**\n\t * Is the value a time string.\n\t * @param value The value to test.\n\t * @returns True if the value is a string in ISO 8601 time format.\n\t */\n\tpublic static timeString(value: unknown): boolean {\n\t\tif (typeof value !== \"string\" || value.length === 0 || value.includes(\"T\")) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !Number.isNaN(Date.parse(`1970-01-01T${value}`));\n\t}\n\n\t/**\n\t * Is the value a timestamp in seconds.\n\t * @param value The value to test.\n\t * @returns True if the value is a timestamp in seconds.\n\t */\n\tpublic static timestampSeconds(value: unknown): value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn value.toString().length < 12;\n\t}\n\n\t/**\n\t * Is the value a timestamp in milliseconds.\n\t * @param value The value to test.\n\t * @returns True if the value is a timestamp in milliseconds.\n\t */\n\tpublic static timestampMilliseconds(value: unknown): value is number {\n\t\tif (!Is.integer(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn value.toString().length >= 12;\n\t}\n\n\t/**\n\t * Is the value an object.\n\t * @param value The value to test.\n\t * @returns True if the value is a object.\n\t */\n\tpublic static object<T = { [id: string]: unknown }>(value: unknown): value is T {\n\t\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n\t}\n\n\t/**\n\t * Is the value an object with at least one property.\n\t * @param value The value to test.\n\t * @returns True if the value is a object.\n\t */\n\tpublic static objectValue<T = { [id: string]: unknown }>(value: unknown): value is T {\n\t\treturn (\n\t\t\ttypeof value === \"object\" &&\n\t\t\tvalue !== null &&\n\t\t\t!Array.isArray(value) &&\n\t\t\tObject.keys(value).length > 0\n\t\t);\n\t}\n\n\t/**\n\t * Is the value an array.\n\t * @param value The value to test.\n\t * @returns True if the value is an array.\n\t */\n\tpublic static array<T>(value: unknown): value is T[] {\n\t\treturn Array.isArray(value);\n\t}\n\n\t/**\n\t * Is the value an array with at least one element.\n\t * @param value The value to test.\n\t * @returns True if the value is an array with at least one element.\n\t */\n\tpublic static arrayValue<T>(value: unknown): value is T[] {\n\t\treturn Array.isArray(value) && value.length > 0;\n\t}\n\n\t/**\n\t * Is the value an array with at least one element.\n\t * @param value The value to test.\n\t * @param options The options the value must be one of.\n\t * @returns True if the value is an element from the options array.\n\t */\n\tpublic static arrayOneOf<T>(value: T, options: T[]): value is T {\n\t\tif (Is.empty(value) || !Is.array<T>(options) || !options.includes(value)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Is the value a Uint8Array.\n\t * @param value The value to test.\n\t * @returns True if the value is a Uint8Array.\n\t */\n\tpublic static uint8Array(value: unknown): value is Uint8Array {\n\t\t// This is the only way we can reliably check for Uint8Array\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Uint8Array;\n\t}\n\n\t/**\n\t * Is the value a TypedArray.\n\t * @param value The value to test.\n\t * @returns True if the value is a TypedArray.\n\t */\n\tpublic static typedArray(\n\t\tvalue: unknown\n\t): value is\n\t\t| Uint8Array\n\t\t| Int8Array\n\t\t| Uint16Array\n\t\t| Int16Array\n\t\t| Uint32Array\n\t\t| Int32Array\n\t\t| Float32Array\n\t\t| Float64Array {\n\t\t// This is the only way we can reliably check for TypedArray\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Object.getPrototypeOf(Uint8Array);\n\t}\n\n\t/**\n\t * Is the property a function.\n\t * @param value The value to test.\n\t * @returns True if the value is a function.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static function<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tvalue: unknown\n\t): value is T {\n\t\treturn typeof value === \"function\";\n\t}\n\n\t/**\n\t * Is the value a string formatted as an email address.\n\t * @param value The value to test.\n\t * @returns True if the value is a string.\n\t */\n\tpublic static email(value: unknown): value is string {\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t/^[\\w!#$%&'*+./=?^`{|}~-]+@[\\dA-Za-z](?:[\\dA-Za-z-]{0,61}[\\dA-Za-z])?(?:\\.[\\dA-Za-z](?:[\\dA-Za-z-]{0,61}[\\dA-Za-z])?)*$/.test(\n\t\t\t\tvalue\n\t\t\t)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a promise.\n\t * @param value The value to test.\n\t * @returns True if the value is a promise.\n\t */\n\tpublic static promise<T = unknown>(value: unknown): value is Promise<T> {\n\t\t// This is the only way we can reliably check for Promise\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof Promise;\n\t}\n\n\t/**\n\t * Is the value a regexp.\n\t * @param value The value to test.\n\t * @returns True if the value is a regexp.\n\t */\n\tpublic static regexp(value: unknown): value is RegExp {\n\t\t// This is the only way we can reliably check for RegExp\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn value instanceof RegExp;\n\t}\n\n\t/**\n\t * Is the provided object a class constructor.\n\t * @param obj The object to check.\n\t * @returns True if the object is a class, false otherwise.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static class<T = unknown>(obj: unknown): obj is new (...args: any[]) => T {\n\t\tif (typeof obj !== \"function\") {\n\t\t\treturn false;\n\t\t}\n\t\tconst str = Function.prototype.toString.call(obj);\n\t\treturn /^class\\s/.test(str);\n\t}\n\n\t/**\n\t * Is the value a uuidV7 string.\n\t * @param value The value to test.\n\t * @param format The format of the UUIDv7 string.\n\t * @returns True if the value is a uuidV7 string.\n\t */\n\tpublic static uuidV7(value: unknown, format?: \"standard\" | \"compact\"): value is string {\n\t\tif (format === \"compact\") {\n\t\t\t// 32 hex chars, where:\n\t\t\t// - char 13 (0-based index 12) is the version (7)\n\t\t\t// - char 17 (0-based index 16) is the variant (8, 9, a, b)\n\t\t\treturn Is.stringValue(value) && /^[\\da-f]{12}7[\\da-f]{3}[89ab][\\da-f]{15}$/i.test(value);\n\t\t}\n\n\t\treturn (\n\t\t\tIs.stringValue(value) &&\n\t\t\t/^[\\da-f]{8}-[\\da-f]{4}-7[\\da-f]{3}-[89ab][\\da-f]{3}-[\\da-f]{12}$/i.test(value)\n\t\t);\n\t}\n\n\t/**\n\t * Is the value a valid ISO 8601 duration string or an IDuration object.\n\t * @param value The value to test.\n\t * @returns True if the value is a valid ISO 8601 duration string or an IDuration object.\n\t */\n\tpublic static duration(value: unknown): value is string | IDuration {\n\t\tif (Is.object<IDuration>(value)) {\n\t\t\tif (\n\t\t\t\t!Is.number(value.years) ||\n\t\t\t\t!Is.number(value.months) ||\n\t\t\t\t!Is.number(value.weeks) ||\n\t\t\t\t!Is.number(value.days) ||\n\t\t\t\t!Is.number(value.hours) ||\n\t\t\t\t!Is.number(value.minutes) ||\n\t\t\t\t!Is.number(value.seconds) ||\n\t\t\t\t(!Is.undefined(value.milliseconds) &&\n\t\t\t\t\t(!Is.integer(value.milliseconds) || Math.abs(value.milliseconds) > 999)) ||\n\t\t\t\t(!Is.undefined(value.microseconds) &&\n\t\t\t\t\t(!Is.integer(value.microseconds) || Math.abs(value.microseconds) > 999)) ||\n\t\t\t\t(!Is.undefined(value.nanoseconds) &&\n\t\t\t\t\t(!Is.integer(value.nanoseconds) || Math.abs(value.nanoseconds) > 999))\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tlet sign = 0;\n\t\t\tfor (const component of [\n\t\t\t\tvalue.years,\n\t\t\t\tvalue.months,\n\t\t\t\tvalue.weeks,\n\t\t\t\tvalue.days,\n\t\t\t\tvalue.hours,\n\t\t\t\tvalue.minutes,\n\t\t\t\tvalue.seconds,\n\t\t\t\tvalue.milliseconds ?? 0,\n\t\t\t\tvalue.microseconds ?? 0,\n\t\t\t\tvalue.nanoseconds ?? 0\n\t\t\t]) {\n\t\t\t\tif (component !== 0) {\n\t\t\t\t\tconst componentSign = component < 0 ? -1 : 1;\n\t\t\t\t\tif (sign === 0) {\n\t\t\t\t\t\tsign = componentSign;\n\t\t\t\t\t} else if (sign !== componentSign) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tif (!Is.stringValue(value)) {\n\t\t\treturn false;\n\t\t}\n\t\tconst match = DURATION_REG_EXP.exec(value);\n\t\treturn Boolean(match?.slice(2).some(Boolean));\n\t}\n}\n"]}
|