@typia/utils 12.0.0-dev.20260309 → 12.0.0-dev.20260311
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/lib/converters/LlmSchemaConverter.d.ts +0 -1
- package/lib/converters/LlmSchemaConverter.js +4 -31
- package/lib/converters/LlmSchemaConverter.js.map +1 -1
- package/lib/converters/LlmSchemaConverter.mjs +2 -32
- package/lib/converters/LlmSchemaConverter.mjs.map +1 -1
- package/lib/http/HttpLlm.js +4 -5
- package/lib/http/HttpLlm.js.map +1 -1
- package/lib/http/HttpLlm.mjs +0 -1
- package/lib/http/HttpLlm.mjs.map +1 -1
- package/lib/http/internal/HttpLlmApplicationComposer.js +3 -4
- package/lib/http/internal/HttpLlmApplicationComposer.js.map +1 -1
- package/lib/http/internal/HttpLlmApplicationComposer.mjs +5 -2
- package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
- package/lib/index.mjs +9 -9
- package/lib/utils/LlmJson.mjs +9 -2
- package/lib/utils/LlmJson.mjs.map +1 -1
- package/lib/utils/internal/stringifyValidationFailure.js +17 -15
- package/lib/utils/internal/stringifyValidationFailure.js.map +1 -1
- package/lib/utils/internal/stringifyValidationFailure.mjs +17 -15
- package/lib/utils/internal/stringifyValidationFailure.mjs.map +1 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs +5 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -1
- package/package.json +2 -2
- package/src/converters/LlmSchemaConverter.ts +617 -647
- package/src/converters/OpenApiConverter.ts +285 -285
- package/src/converters/index.ts +5 -5
- package/src/converters/internal/LlmDescriptionInverter.ts +178 -178
- package/src/converters/internal/LlmParametersComposer.ts +52 -52
- package/src/converters/internal/OpenApiConstraintShifter.ts +154 -154
- package/src/converters/internal/OpenApiExclusiveEmender.ts +46 -46
- package/src/converters/internal/OpenApiV3Downgrader.ts +355 -355
- package/src/converters/internal/OpenApiV3Upgrader.ts +470 -470
- package/src/converters/internal/OpenApiV3_1Upgrader.ts +685 -685
- package/src/converters/internal/SwaggerV2Downgrader.ts +424 -424
- package/src/converters/internal/SwaggerV2Upgrader.ts +523 -523
- package/src/http/HttpError.ts +107 -107
- package/src/http/HttpLlm.ts +166 -167
- package/src/http/HttpMigration.ts +92 -92
- package/src/http/index.ts +3 -3
- package/src/http/internal/HttpLlmApplicationComposer.ts +360 -361
- package/src/http/internal/HttpLlmFunctionFetcher.ts +37 -37
- package/src/http/internal/HttpMigrateApplicationComposer.ts +56 -56
- package/src/http/internal/HttpMigrateRouteAccessor.ts +135 -135
- package/src/http/internal/HttpMigrateRouteComposer.ts +505 -505
- package/src/http/internal/HttpMigrateRouteFetcher.ts +203 -203
- package/src/index.ts +4 -4
- package/src/utils/ArrayUtil.ts +42 -42
- package/src/utils/LlmJson.ts +141 -141
- package/src/utils/MapUtil.ts +15 -15
- package/src/utils/NamingConvention.ts +205 -205
- package/src/utils/Singleton.ts +17 -17
- package/src/utils/StringUtil.ts +14 -14
- package/src/utils/dedent.ts +57 -57
- package/src/utils/index.ts +8 -8
- package/src/utils/internal/EndpointUtil.ts +44 -44
- package/src/utils/internal/JsonDescriptor.ts +70 -70
- package/src/utils/internal/OpenApiTypeCheckerBase.ts +822 -822
- package/src/utils/internal/coerceLlmArguments.ts +314 -314
- package/src/utils/internal/parseLenientJson.ts +894 -894
- package/src/utils/internal/stringifyValidationFailure.ts +415 -411
- package/src/validators/LlmTypeChecker.ts +402 -402
- package/src/validators/OpenApiTypeChecker.ts +297 -297
- package/src/validators/OpenApiV3TypeChecker.ts +70 -70
- package/src/validators/OpenApiV3_1TypeChecker.ts +86 -86
- package/src/validators/OpenApiValidator.ts +94 -94
- package/src/validators/SwaggerV2TypeChecker.ts +71 -71
- package/src/validators/functional/_isBigintString.ts +8 -8
- package/src/validators/functional/_isFormatByte.ts +7 -7
- package/src/validators/functional/_isFormatDate.ts +3 -3
- package/src/validators/functional/_isFormatDateTime.ts +4 -4
- package/src/validators/functional/_isFormatDuration.ts +4 -4
- package/src/validators/functional/_isFormatEmail.ts +4 -4
- package/src/validators/functional/_isFormatHostname.ts +4 -4
- package/src/validators/functional/_isFormatIdnEmail.ts +4 -4
- package/src/validators/functional/_isFormatIdnHostname.ts +4 -4
- package/src/validators/functional/_isFormatIpv4.ts +4 -4
- package/src/validators/functional/_isFormatIpv6.ts +4 -4
- package/src/validators/functional/_isFormatIri.ts +3 -3
- package/src/validators/functional/_isFormatIriReference.ts +4 -4
- package/src/validators/functional/_isFormatJsonPointer.ts +3 -3
- package/src/validators/functional/_isFormatPassword.ts +1 -1
- package/src/validators/functional/_isFormatRegex.ts +8 -8
- package/src/validators/functional/_isFormatRelativeJsonPointer.ts +4 -4
- package/src/validators/functional/_isFormatTime.ts +4 -4
- package/src/validators/functional/_isFormatUri.ts +6 -6
- package/src/validators/functional/_isFormatUriReference.ts +5 -5
- package/src/validators/functional/_isFormatUriTemplate.ts +4 -4
- package/src/validators/functional/_isFormatUrl.ts +4 -4
- package/src/validators/functional/_isFormatUuid.ts +3 -3
- package/src/validators/functional/_isUniqueItems.ts +159 -159
- package/src/validators/index.ts +14 -14
- package/src/validators/internal/IOpenApiValidatorContext.ts +17 -17
- package/src/validators/internal/OpenApiArrayValidator.ts +49 -49
- package/src/validators/internal/OpenApiBooleanValidator.ts +11 -11
- package/src/validators/internal/OpenApiConstantValidator.ts +11 -11
- package/src/validators/internal/OpenApiIntegerValidator.ts +49 -49
- package/src/validators/internal/OpenApiNumberValidator.ts +48 -48
- package/src/validators/internal/OpenApiObjectValidator.ts +83 -83
- package/src/validators/internal/OpenApiOneOfValidator.ts +309 -309
- package/src/validators/internal/OpenApiSchemaNamingRule.ts +124 -124
- package/src/validators/internal/OpenApiStationValidator.ts +115 -115
- package/src/validators/internal/OpenApiStringValidator.ts +88 -88
- package/src/validators/internal/OpenApiTupleValidator.ts +55 -55
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export const _isFormatByte = (str: string): boolean => {
|
|
2
|
-
PATTERN.lastIndex = 0;
|
|
3
|
-
return PATTERN.test(str);
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
const PATTERN =
|
|
7
|
-
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
|
|
1
|
+
export const _isFormatByte = (str: string): boolean => {
|
|
2
|
+
PATTERN.lastIndex = 0;
|
|
3
|
+
return PATTERN.test(str);
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const PATTERN =
|
|
7
|
+
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const _isFormatDate = (str: string): boolean => FORMAT.test(str);
|
|
2
|
-
|
|
3
|
-
const FORMAT = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
|
|
1
|
+
export const _isFormatDate = (str: string): boolean => FORMAT.test(str);
|
|
2
|
+
|
|
3
|
+
const FORMAT = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatDateTime = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i;
|
|
1
|
+
export const _isFormatDateTime = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatDuration = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/;
|
|
1
|
+
export const _isFormatDuration = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatEmail = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;
|
|
1
|
+
export const _isFormatEmail = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatHostname = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i;
|
|
1
|
+
export const _isFormatHostname = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatIdnEmail = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
|
1
|
+
export const _isFormatIdnEmail = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatIdnHostname = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^([a-z0-9\u00a1-\uffff0-9]+(-[a-z0-9\u00a1-\uffff0-9]+)*\.)+[a-z\u00a1-\uffff]{2,}$/i;
|
|
1
|
+
export const _isFormatIdnHostname = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^([a-z0-9\u00a1-\uffff0-9]+(-[a-z0-9\u00a1-\uffff0-9]+)*\.)+[a-z\u00a1-\uffff]{2,}$/i;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatIpv4 = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
|
|
1
|
+
export const _isFormatIpv4 = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatIpv6 = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i;
|
|
1
|
+
export const _isFormatIpv6 = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const _isFormatIri = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN = /^[A-Za-z][\d+-.A-Za-z]*:[^\u0000-\u0020"<>\\^`{|}]*$/u;
|
|
1
|
+
export const _isFormatIri = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN = /^[A-Za-z][\d+-.A-Za-z]*:[^\u0000-\u0020"<>\\^`{|}]*$/u;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatIriReference = (str: string): boolean =>
|
|
2
|
-
PATTERN.test(str);
|
|
3
|
-
|
|
4
|
-
const PATTERN = /^[A-Za-z][\d+-.A-Za-z]*:[^\u0000-\u0020"<>\\^`{|}]*$/u;
|
|
1
|
+
export const _isFormatIriReference = (str: string): boolean =>
|
|
2
|
+
PATTERN.test(str);
|
|
3
|
+
|
|
4
|
+
const PATTERN = /^[A-Za-z][\d+-.A-Za-z]*:[^\u0000-\u0020"<>\\^`{|}]*$/u;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const _isFormatJsonPointer = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
|
|
1
|
+
export const _isFormatJsonPointer = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const _isFormatPassword = (): boolean => true;
|
|
1
|
+
export const _isFormatPassword = (): boolean => true;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export const _isFormatRegex = (str: string): boolean => {
|
|
2
|
-
try {
|
|
3
|
-
new RegExp(str);
|
|
4
|
-
return true;
|
|
5
|
-
} catch {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
1
|
+
export const _isFormatRegex = (str: string): boolean => {
|
|
2
|
+
try {
|
|
3
|
+
new RegExp(str);
|
|
4
|
+
return true;
|
|
5
|
+
} catch {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatRelativeJsonPointer = (str: string): boolean =>
|
|
2
|
-
PATTERN.test(str);
|
|
3
|
-
|
|
4
|
-
const PATTERN = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
|
|
1
|
+
export const _isFormatRelativeJsonPointer = (str: string): boolean =>
|
|
2
|
+
PATTERN.test(str);
|
|
3
|
+
|
|
4
|
+
const PATTERN = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatTime = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i;
|
|
1
|
+
export const _isFormatTime = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const _isFormatUri = (str: string): boolean =>
|
|
2
|
-
NOT_URI_FRAGMENT.test(str) && URI.test(str);
|
|
3
|
-
|
|
4
|
-
const NOT_URI_FRAGMENT = /\/|:/;
|
|
5
|
-
const URI =
|
|
6
|
-
/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
1
|
+
export const _isFormatUri = (str: string): boolean =>
|
|
2
|
+
NOT_URI_FRAGMENT.test(str) && URI.test(str);
|
|
3
|
+
|
|
4
|
+
const NOT_URI_FRAGMENT = /\/|:/;
|
|
5
|
+
const URI =
|
|
6
|
+
/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export const _isFormatUriReference = (str: string): boolean =>
|
|
2
|
-
PATTERN.test(str);
|
|
3
|
-
|
|
4
|
-
const PATTERN =
|
|
5
|
-
/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
1
|
+
export const _isFormatUriReference = (str: string): boolean =>
|
|
2
|
+
PATTERN.test(str);
|
|
3
|
+
|
|
4
|
+
const PATTERN =
|
|
5
|
+
/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatUriTemplate = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
|
|
1
|
+
export const _isFormatUriTemplate = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const _isFormatUrl = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN =
|
|
4
|
-
/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
|
|
1
|
+
export const _isFormatUrl = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN =
|
|
4
|
+
/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const _isFormatUuid = (str: string): boolean => PATTERN.test(str);
|
|
2
|
-
|
|
3
|
-
const PATTERN = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
1
|
+
export const _isFormatUuid = (str: string): boolean => PATTERN.test(str);
|
|
2
|
+
|
|
3
|
+
const PATTERN = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
@@ -1,159 +1,159 @@
|
|
|
1
|
-
export const _isUniqueItems = (elements: any[]): boolean => {
|
|
2
|
-
// EMPTY OR ONLY ONE
|
|
3
|
-
if (elements.length < 2) return true;
|
|
4
|
-
|
|
5
|
-
// SHALLOW COMPARISON
|
|
6
|
-
if (["boolean", "bigint", "number", "string"].includes(typeof elements[0]))
|
|
7
|
-
return new Set(elements).size === elements.length;
|
|
8
|
-
|
|
9
|
-
// DEEP COMPARISON
|
|
10
|
-
for (let i = 0; i < elements.length; i++)
|
|
11
|
-
for (let j = i + 1; j < elements.length; j++)
|
|
12
|
-
if (equals(new WeakMap())(elements[i], elements[j])) return false;
|
|
13
|
-
return true;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const equals = (visited: WeakMap<object, WeakMap<object, boolean>>) => {
|
|
17
|
-
const next = (a: any, b: any): boolean => {
|
|
18
|
-
// SHALLOW EQUAL
|
|
19
|
-
if (a === b) return true;
|
|
20
|
-
else if (typeof a !== typeof b || typeof a !== "object") return false;
|
|
21
|
-
// COMPARE CONTAINERS
|
|
22
|
-
else if (Array.isArray(a))
|
|
23
|
-
return Array.isArray(b) && a.map((x, i) => next(x, b[i])).every((x) => x);
|
|
24
|
-
else if (a instanceof Set)
|
|
25
|
-
return (
|
|
26
|
-
b instanceof Set && a.size === b.size && [...a].every((x) => b.has(x))
|
|
27
|
-
);
|
|
28
|
-
else if (a instanceof Map)
|
|
29
|
-
return (
|
|
30
|
-
b instanceof Map &&
|
|
31
|
-
a.size === b.size &&
|
|
32
|
-
[...a].every(([k, v]) => b.has(k) && next(v, b.get(k)))
|
|
33
|
-
);
|
|
34
|
-
// ATOMIC CLASSES
|
|
35
|
-
else if (a instanceof Boolean)
|
|
36
|
-
return b instanceof Boolean
|
|
37
|
-
? a.valueOf() === b.valueOf()
|
|
38
|
-
: a.valueOf() === b;
|
|
39
|
-
else if (a instanceof BigInt)
|
|
40
|
-
return b instanceof BigInt ? a === b : a === BigInt(b);
|
|
41
|
-
else if (a instanceof Number)
|
|
42
|
-
return b instanceof Number
|
|
43
|
-
? a.valueOf() === b.valueOf()
|
|
44
|
-
: a.valueOf() === b;
|
|
45
|
-
else if (a instanceof String)
|
|
46
|
-
return b instanceof String
|
|
47
|
-
? a.valueOf() === b.valueOf()
|
|
48
|
-
: a.valueOf() === b;
|
|
49
|
-
else if (a instanceof Date)
|
|
50
|
-
return b instanceof Date && a.getTime() === b.getTime();
|
|
51
|
-
// BINARY DATA
|
|
52
|
-
else if (a instanceof Uint8Array)
|
|
53
|
-
return (
|
|
54
|
-
b instanceof Uint8Array &&
|
|
55
|
-
a.length === b.length &&
|
|
56
|
-
a.every((x, i) => x === b[i])
|
|
57
|
-
);
|
|
58
|
-
else if (a instanceof Uint8ClampedArray)
|
|
59
|
-
return (
|
|
60
|
-
b instanceof Uint8ClampedArray &&
|
|
61
|
-
a.length === b.length &&
|
|
62
|
-
a.every((x, i) => x === b[i])
|
|
63
|
-
);
|
|
64
|
-
else if (a instanceof Uint16Array)
|
|
65
|
-
return (
|
|
66
|
-
b instanceof Uint16Array &&
|
|
67
|
-
a.length === b.length &&
|
|
68
|
-
a.every((x, i) => x === b[i])
|
|
69
|
-
);
|
|
70
|
-
else if (a instanceof Uint32Array)
|
|
71
|
-
return (
|
|
72
|
-
b instanceof Uint32Array &&
|
|
73
|
-
a.length === b.length &&
|
|
74
|
-
a.every((x, i) => x === b[i])
|
|
75
|
-
);
|
|
76
|
-
else if (a instanceof BigUint64Array)
|
|
77
|
-
return (
|
|
78
|
-
b instanceof BigUint64Array &&
|
|
79
|
-
a.length === b.length &&
|
|
80
|
-
a.every((x, i) => x === b[i])
|
|
81
|
-
);
|
|
82
|
-
else if (a instanceof Int8Array)
|
|
83
|
-
return (
|
|
84
|
-
b instanceof Int8Array &&
|
|
85
|
-
a.length === b.length &&
|
|
86
|
-
a.every((x, i) => x === b[i])
|
|
87
|
-
);
|
|
88
|
-
else if (a instanceof Int16Array)
|
|
89
|
-
return (
|
|
90
|
-
b instanceof Int16Array &&
|
|
91
|
-
a.length === b.length &&
|
|
92
|
-
a.every((x, i) => x === b[i])
|
|
93
|
-
);
|
|
94
|
-
else if (a instanceof Int32Array)
|
|
95
|
-
return (
|
|
96
|
-
b instanceof Int32Array &&
|
|
97
|
-
a.length === b.length &&
|
|
98
|
-
a.every((x, i) => x === b[i])
|
|
99
|
-
);
|
|
100
|
-
else if (a instanceof BigInt64Array)
|
|
101
|
-
return (
|
|
102
|
-
b instanceof BigInt64Array &&
|
|
103
|
-
a.length === b.length &&
|
|
104
|
-
a.every((x, i) => x === b[i])
|
|
105
|
-
);
|
|
106
|
-
else if (a instanceof Float32Array)
|
|
107
|
-
return (
|
|
108
|
-
b instanceof Float32Array &&
|
|
109
|
-
a.length === b.length &&
|
|
110
|
-
a.every((x, i) => x === b[i])
|
|
111
|
-
);
|
|
112
|
-
else if (a instanceof Float64Array)
|
|
113
|
-
return (
|
|
114
|
-
b instanceof Float64Array &&
|
|
115
|
-
a.length === b.length &&
|
|
116
|
-
a.every((x, i) => x === b[i])
|
|
117
|
-
);
|
|
118
|
-
else if (a instanceof ArrayBuffer) {
|
|
119
|
-
if (!(b instanceof ArrayBuffer) || a.byteLength !== b.byteLength)
|
|
120
|
-
return false;
|
|
121
|
-
const x: Uint8Array = new Uint8Array(a);
|
|
122
|
-
const y: Uint8Array = new Uint8Array(b);
|
|
123
|
-
return x.every((v, i) => v === y[i]);
|
|
124
|
-
} else if (a instanceof SharedArrayBuffer) {
|
|
125
|
-
if (!(b instanceof SharedArrayBuffer) || a.byteLength !== b.byteLength)
|
|
126
|
-
return false;
|
|
127
|
-
const x: Uint8Array = new Uint8Array(a);
|
|
128
|
-
const y: Uint8Array = new Uint8Array(b);
|
|
129
|
-
return x.every((v, i) => v === y[i]);
|
|
130
|
-
} else if (a instanceof DataView) {
|
|
131
|
-
if (!(b instanceof DataView) || a.byteLength !== b.byteLength)
|
|
132
|
-
return false;
|
|
133
|
-
const x: Uint8Array = new Uint8Array(a.buffer);
|
|
134
|
-
const y: Uint8Array = new Uint8Array(b.buffer);
|
|
135
|
-
return x.every((v, i) => v === y[i]);
|
|
136
|
-
} else if (a instanceof File)
|
|
137
|
-
return (
|
|
138
|
-
b instanceof File &&
|
|
139
|
-
a.name === b.name &&
|
|
140
|
-
a.size === b.size &&
|
|
141
|
-
a.type === b.type &&
|
|
142
|
-
next(a.slice(), b.slice())
|
|
143
|
-
);
|
|
144
|
-
// JUST PLAIN OBJECTS
|
|
145
|
-
else if (a !== null && b !== null) {
|
|
146
|
-
if (visited.has(a) && visited.get(a)!.has(b))
|
|
147
|
-
return visited.get(a)!.get(b)!;
|
|
148
|
-
if (!visited.has(a)) visited.set(a, new WeakMap());
|
|
149
|
-
visited.get(a)!.set(b, true);
|
|
150
|
-
const res: boolean =
|
|
151
|
-
Object.keys(a).length === Object.keys(b).length &&
|
|
152
|
-
Object.keys(a).every((x) => next(a[x], b[x]));
|
|
153
|
-
visited.get(a)!.set(b, res);
|
|
154
|
-
return res;
|
|
155
|
-
}
|
|
156
|
-
return false;
|
|
157
|
-
};
|
|
158
|
-
return next;
|
|
159
|
-
};
|
|
1
|
+
export const _isUniqueItems = (elements: any[]): boolean => {
|
|
2
|
+
// EMPTY OR ONLY ONE
|
|
3
|
+
if (elements.length < 2) return true;
|
|
4
|
+
|
|
5
|
+
// SHALLOW COMPARISON
|
|
6
|
+
if (["boolean", "bigint", "number", "string"].includes(typeof elements[0]))
|
|
7
|
+
return new Set(elements).size === elements.length;
|
|
8
|
+
|
|
9
|
+
// DEEP COMPARISON
|
|
10
|
+
for (let i = 0; i < elements.length; i++)
|
|
11
|
+
for (let j = i + 1; j < elements.length; j++)
|
|
12
|
+
if (equals(new WeakMap())(elements[i], elements[j])) return false;
|
|
13
|
+
return true;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const equals = (visited: WeakMap<object, WeakMap<object, boolean>>) => {
|
|
17
|
+
const next = (a: any, b: any): boolean => {
|
|
18
|
+
// SHALLOW EQUAL
|
|
19
|
+
if (a === b) return true;
|
|
20
|
+
else if (typeof a !== typeof b || typeof a !== "object") return false;
|
|
21
|
+
// COMPARE CONTAINERS
|
|
22
|
+
else if (Array.isArray(a))
|
|
23
|
+
return Array.isArray(b) && a.map((x, i) => next(x, b[i])).every((x) => x);
|
|
24
|
+
else if (a instanceof Set)
|
|
25
|
+
return (
|
|
26
|
+
b instanceof Set && a.size === b.size && [...a].every((x) => b.has(x))
|
|
27
|
+
);
|
|
28
|
+
else if (a instanceof Map)
|
|
29
|
+
return (
|
|
30
|
+
b instanceof Map &&
|
|
31
|
+
a.size === b.size &&
|
|
32
|
+
[...a].every(([k, v]) => b.has(k) && next(v, b.get(k)))
|
|
33
|
+
);
|
|
34
|
+
// ATOMIC CLASSES
|
|
35
|
+
else if (a instanceof Boolean)
|
|
36
|
+
return b instanceof Boolean
|
|
37
|
+
? a.valueOf() === b.valueOf()
|
|
38
|
+
: a.valueOf() === b;
|
|
39
|
+
else if (a instanceof BigInt)
|
|
40
|
+
return b instanceof BigInt ? a === b : a === BigInt(b);
|
|
41
|
+
else if (a instanceof Number)
|
|
42
|
+
return b instanceof Number
|
|
43
|
+
? a.valueOf() === b.valueOf()
|
|
44
|
+
: a.valueOf() === b;
|
|
45
|
+
else if (a instanceof String)
|
|
46
|
+
return b instanceof String
|
|
47
|
+
? a.valueOf() === b.valueOf()
|
|
48
|
+
: a.valueOf() === b;
|
|
49
|
+
else if (a instanceof Date)
|
|
50
|
+
return b instanceof Date && a.getTime() === b.getTime();
|
|
51
|
+
// BINARY DATA
|
|
52
|
+
else if (a instanceof Uint8Array)
|
|
53
|
+
return (
|
|
54
|
+
b instanceof Uint8Array &&
|
|
55
|
+
a.length === b.length &&
|
|
56
|
+
a.every((x, i) => x === b[i])
|
|
57
|
+
);
|
|
58
|
+
else if (a instanceof Uint8ClampedArray)
|
|
59
|
+
return (
|
|
60
|
+
b instanceof Uint8ClampedArray &&
|
|
61
|
+
a.length === b.length &&
|
|
62
|
+
a.every((x, i) => x === b[i])
|
|
63
|
+
);
|
|
64
|
+
else if (a instanceof Uint16Array)
|
|
65
|
+
return (
|
|
66
|
+
b instanceof Uint16Array &&
|
|
67
|
+
a.length === b.length &&
|
|
68
|
+
a.every((x, i) => x === b[i])
|
|
69
|
+
);
|
|
70
|
+
else if (a instanceof Uint32Array)
|
|
71
|
+
return (
|
|
72
|
+
b instanceof Uint32Array &&
|
|
73
|
+
a.length === b.length &&
|
|
74
|
+
a.every((x, i) => x === b[i])
|
|
75
|
+
);
|
|
76
|
+
else if (a instanceof BigUint64Array)
|
|
77
|
+
return (
|
|
78
|
+
b instanceof BigUint64Array &&
|
|
79
|
+
a.length === b.length &&
|
|
80
|
+
a.every((x, i) => x === b[i])
|
|
81
|
+
);
|
|
82
|
+
else if (a instanceof Int8Array)
|
|
83
|
+
return (
|
|
84
|
+
b instanceof Int8Array &&
|
|
85
|
+
a.length === b.length &&
|
|
86
|
+
a.every((x, i) => x === b[i])
|
|
87
|
+
);
|
|
88
|
+
else if (a instanceof Int16Array)
|
|
89
|
+
return (
|
|
90
|
+
b instanceof Int16Array &&
|
|
91
|
+
a.length === b.length &&
|
|
92
|
+
a.every((x, i) => x === b[i])
|
|
93
|
+
);
|
|
94
|
+
else if (a instanceof Int32Array)
|
|
95
|
+
return (
|
|
96
|
+
b instanceof Int32Array &&
|
|
97
|
+
a.length === b.length &&
|
|
98
|
+
a.every((x, i) => x === b[i])
|
|
99
|
+
);
|
|
100
|
+
else if (a instanceof BigInt64Array)
|
|
101
|
+
return (
|
|
102
|
+
b instanceof BigInt64Array &&
|
|
103
|
+
a.length === b.length &&
|
|
104
|
+
a.every((x, i) => x === b[i])
|
|
105
|
+
);
|
|
106
|
+
else if (a instanceof Float32Array)
|
|
107
|
+
return (
|
|
108
|
+
b instanceof Float32Array &&
|
|
109
|
+
a.length === b.length &&
|
|
110
|
+
a.every((x, i) => x === b[i])
|
|
111
|
+
);
|
|
112
|
+
else if (a instanceof Float64Array)
|
|
113
|
+
return (
|
|
114
|
+
b instanceof Float64Array &&
|
|
115
|
+
a.length === b.length &&
|
|
116
|
+
a.every((x, i) => x === b[i])
|
|
117
|
+
);
|
|
118
|
+
else if (a instanceof ArrayBuffer) {
|
|
119
|
+
if (!(b instanceof ArrayBuffer) || a.byteLength !== b.byteLength)
|
|
120
|
+
return false;
|
|
121
|
+
const x: Uint8Array = new Uint8Array(a);
|
|
122
|
+
const y: Uint8Array = new Uint8Array(b);
|
|
123
|
+
return x.every((v, i) => v === y[i]);
|
|
124
|
+
} else if (a instanceof SharedArrayBuffer) {
|
|
125
|
+
if (!(b instanceof SharedArrayBuffer) || a.byteLength !== b.byteLength)
|
|
126
|
+
return false;
|
|
127
|
+
const x: Uint8Array = new Uint8Array(a);
|
|
128
|
+
const y: Uint8Array = new Uint8Array(b);
|
|
129
|
+
return x.every((v, i) => v === y[i]);
|
|
130
|
+
} else if (a instanceof DataView) {
|
|
131
|
+
if (!(b instanceof DataView) || a.byteLength !== b.byteLength)
|
|
132
|
+
return false;
|
|
133
|
+
const x: Uint8Array = new Uint8Array(a.buffer);
|
|
134
|
+
const y: Uint8Array = new Uint8Array(b.buffer);
|
|
135
|
+
return x.every((v, i) => v === y[i]);
|
|
136
|
+
} else if (a instanceof File)
|
|
137
|
+
return (
|
|
138
|
+
b instanceof File &&
|
|
139
|
+
a.name === b.name &&
|
|
140
|
+
a.size === b.size &&
|
|
141
|
+
a.type === b.type &&
|
|
142
|
+
next(a.slice(), b.slice())
|
|
143
|
+
);
|
|
144
|
+
// JUST PLAIN OBJECTS
|
|
145
|
+
else if (a !== null && b !== null) {
|
|
146
|
+
if (visited.has(a) && visited.get(a)!.has(b))
|
|
147
|
+
return visited.get(a)!.get(b)!;
|
|
148
|
+
if (!visited.has(a)) visited.set(a, new WeakMap());
|
|
149
|
+
visited.get(a)!.set(b, true);
|
|
150
|
+
const res: boolean =
|
|
151
|
+
Object.keys(a).length === Object.keys(b).length &&
|
|
152
|
+
Object.keys(a).every((x) => next(a[x], b[x]));
|
|
153
|
+
visited.get(a)!.set(b, res);
|
|
154
|
+
return res;
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
};
|
|
158
|
+
return next;
|
|
159
|
+
};
|
package/src/validators/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export * from "./LlmTypeChecker";
|
|
2
|
-
export * from "./OpenApiTypeChecker";
|
|
3
|
-
|
|
4
|
-
/** @internal */
|
|
5
|
-
export * from "./OpenApiV3TypeChecker";
|
|
6
|
-
|
|
7
|
-
/** @internal */
|
|
8
|
-
export * from "./OpenApiV3_1TypeChecker";
|
|
9
|
-
|
|
10
|
-
/** @internal */
|
|
11
|
-
export * from "./SwaggerV2TypeChecker";
|
|
12
|
-
|
|
13
|
-
/** @internal */
|
|
14
|
-
export * from "./OpenApiValidator";
|
|
1
|
+
export * from "./LlmTypeChecker";
|
|
2
|
+
export * from "./OpenApiTypeChecker";
|
|
3
|
+
|
|
4
|
+
/** @internal */
|
|
5
|
+
export * from "./OpenApiV3TypeChecker";
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
export * from "./OpenApiV3_1TypeChecker";
|
|
9
|
+
|
|
10
|
+
/** @internal */
|
|
11
|
+
export * from "./SwaggerV2TypeChecker";
|
|
12
|
+
|
|
13
|
+
/** @internal */
|
|
14
|
+
export * from "./OpenApiValidator";
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { IValidation, OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
export interface IOpenApiValidatorContext<Schema extends OpenApi.IJsonSchema> {
|
|
4
|
-
components: OpenApi.IComponents;
|
|
5
|
-
schema: Schema;
|
|
6
|
-
value: unknown;
|
|
7
|
-
path: string;
|
|
8
|
-
report: (
|
|
9
|
-
error: IValidation.IError & {
|
|
10
|
-
exceptionable: boolean;
|
|
11
|
-
},
|
|
12
|
-
) => false;
|
|
13
|
-
exceptionable: boolean;
|
|
14
|
-
expected: string;
|
|
15
|
-
equals: boolean;
|
|
16
|
-
required: boolean;
|
|
17
|
-
}
|
|
1
|
+
import { IValidation, OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
export interface IOpenApiValidatorContext<Schema extends OpenApi.IJsonSchema> {
|
|
4
|
+
components: OpenApi.IComponents;
|
|
5
|
+
schema: Schema;
|
|
6
|
+
value: unknown;
|
|
7
|
+
path: string;
|
|
8
|
+
report: (
|
|
9
|
+
error: IValidation.IError & {
|
|
10
|
+
exceptionable: boolean;
|
|
11
|
+
},
|
|
12
|
+
) => false;
|
|
13
|
+
exceptionable: boolean;
|
|
14
|
+
expected: string;
|
|
15
|
+
equals: boolean;
|
|
16
|
+
required: boolean;
|
|
17
|
+
}
|