@wix/form-public 0.567.0 → 0.568.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +101 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +101 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -164,10 +164,37 @@ var init_errors = __esm({
|
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
-
// ../form-validator/dist/esm/lib/
|
|
168
|
-
function
|
|
169
|
-
|
|
167
|
+
// ../form-validator/dist/esm/lib/utils/to-decimal.js
|
|
168
|
+
function toDecimal(value) {
|
|
169
|
+
const [mantissa, exponent = "0"] = String(Math.abs(value)).split("e");
|
|
170
|
+
const [integerPart, fractionPart = ""] = mantissa.split(".");
|
|
171
|
+
return {
|
|
172
|
+
unscaledValue: BigInt(integerPart + fractionPart),
|
|
173
|
+
scale: fractionPart.length - Number(exponent)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function toScaledInteger({ unscaledValue, scale }, targetScale) {
|
|
177
|
+
return unscaledValue * 10n ** BigInt(targetScale - scale);
|
|
178
|
+
}
|
|
179
|
+
var init_to_decimal = __esm({
|
|
180
|
+
"../form-validator/dist/esm/lib/utils/to-decimal.js"() {
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// ../form-validator/dist/esm/lib/utils/get-decimal-scale.js
|
|
185
|
+
function getDecimalScale(value) {
|
|
186
|
+
if (!Number.isFinite(value)) {
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
return Math.max(toDecimal(value).scale, 0);
|
|
170
190
|
}
|
|
191
|
+
var init_get_decimal_scale = __esm({
|
|
192
|
+
"../form-validator/dist/esm/lib/utils/get-decimal-scale.js"() {
|
|
193
|
+
init_to_decimal();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// ../form-validator/dist/esm/lib/error-derivation/helpers.js
|
|
171
198
|
function deserializeDate(value) {
|
|
172
199
|
if (!value) {
|
|
173
200
|
return {};
|
|
@@ -331,7 +358,7 @@ function deriveNumericValueError(validation, error) {
|
|
|
331
358
|
if (isMultipleOfValueError) {
|
|
332
359
|
const multipleOf = validation?.number?.multipleOf;
|
|
333
360
|
if (multipleOf) {
|
|
334
|
-
const decimalPlaces =
|
|
361
|
+
const decimalPlaces = getDecimalScale(multipleOf);
|
|
335
362
|
return {
|
|
336
363
|
...error,
|
|
337
364
|
errorType: ErrorType.DECIMAL_POINT_ERROR,
|
|
@@ -430,6 +457,7 @@ function deriveDateTimeFieldError(validation, error, value) {
|
|
|
430
457
|
var init_error_derivers = __esm({
|
|
431
458
|
"../form-validator/dist/esm/lib/error-derivation/error-derivers.js"() {
|
|
432
459
|
init_errors();
|
|
460
|
+
init_get_decimal_scale();
|
|
433
461
|
init_helpers();
|
|
434
462
|
init_types();
|
|
435
463
|
}
|
|
@@ -12560,6 +12588,43 @@ var init_max = __esm({
|
|
|
12560
12588
|
init_core();
|
|
12561
12589
|
}
|
|
12562
12590
|
});
|
|
12591
|
+
|
|
12592
|
+
// ../form-validator/dist/esm/lib/utils/compile-is-multiple-of.js
|
|
12593
|
+
function compileIsMultipleOf(multipleOf) {
|
|
12594
|
+
if (!Number.isFinite(multipleOf) || multipleOf <= 0) {
|
|
12595
|
+
return () => false;
|
|
12596
|
+
}
|
|
12597
|
+
const divisor = toDecimal(multipleOf);
|
|
12598
|
+
const maxTolerableNoise = multipleOf * MAX_NOISE_TO_STEP_RATIO;
|
|
12599
|
+
return (value) => {
|
|
12600
|
+
if (!Number.isFinite(value)) {
|
|
12601
|
+
return true;
|
|
12602
|
+
}
|
|
12603
|
+
const dividend = toDecimal(value);
|
|
12604
|
+
const scale = Math.max(dividend.scale, divisor.scale);
|
|
12605
|
+
const scaledDivisor = toScaledInteger(divisor, scale);
|
|
12606
|
+
const remainder = toScaledInteger(dividend, scale) % scaledDivisor;
|
|
12607
|
+
if (remainder === 0n) {
|
|
12608
|
+
return true;
|
|
12609
|
+
}
|
|
12610
|
+
const noise = FLOATING_POINT_NOISE_ULPS * Math.abs(value) * Number.EPSILON;
|
|
12611
|
+
const distanceToNearestMultiple = remainder < scaledDivisor - remainder ? remainder : scaledDivisor - remainder;
|
|
12612
|
+
return isWithinNoise(distanceToNearestMultiple, scale, Math.min(noise, maxTolerableNoise));
|
|
12613
|
+
};
|
|
12614
|
+
}
|
|
12615
|
+
function isWithinNoise(distance, distanceScale, noise) {
|
|
12616
|
+
const noiseDecimal = toDecimal(noise);
|
|
12617
|
+
const scale = Math.max(distanceScale, noiseDecimal.scale);
|
|
12618
|
+
return distance * 10n ** BigInt(scale - distanceScale) <= toScaledInteger(noiseDecimal, scale);
|
|
12619
|
+
}
|
|
12620
|
+
var FLOATING_POINT_NOISE_ULPS, MAX_NOISE_TO_STEP_RATIO;
|
|
12621
|
+
var init_compile_is_multiple_of = __esm({
|
|
12622
|
+
"../form-validator/dist/esm/lib/utils/compile-is-multiple-of.js"() {
|
|
12623
|
+
init_to_decimal();
|
|
12624
|
+
FLOATING_POINT_NOISE_ULPS = 4;
|
|
12625
|
+
MAX_NOISE_TO_STEP_RATIO = 1e-6;
|
|
12626
|
+
}
|
|
12627
|
+
});
|
|
12563
12628
|
function parseLocalDate(value) {
|
|
12564
12629
|
const match4 = LOCAL_DATE_REGEX.exec(value);
|
|
12565
12630
|
if (!match4 || isNaN(new Date(value).getTime())) {
|
|
@@ -12630,6 +12695,16 @@ var init_date_availability = __esm({
|
|
|
12630
12695
|
|
|
12631
12696
|
// ../form-validator/dist/esm/lib/submission-validation/ajv/ajv-custom-keywords.js
|
|
12632
12697
|
function addCustomKeywords(ajv, phoneValidationEnabled, lenientPhoneValidation) {
|
|
12698
|
+
ajv.removeKeyword("multipleOf");
|
|
12699
|
+
ajv.addKeyword({
|
|
12700
|
+
keyword: "multipleOf",
|
|
12701
|
+
type: "number",
|
|
12702
|
+
schemaType: "number",
|
|
12703
|
+
errors: true,
|
|
12704
|
+
compile(multipleOf) {
|
|
12705
|
+
return compileMultipleOfValidation(multipleOf);
|
|
12706
|
+
}
|
|
12707
|
+
});
|
|
12633
12708
|
ajv.addKeyword({
|
|
12634
12709
|
keyword: "dateAvailability",
|
|
12635
12710
|
type: "string",
|
|
@@ -12789,6 +12864,26 @@ function getCallingCode(phoneNumber) {
|
|
|
12789
12864
|
function onlyCallingCode(callingCode, data) {
|
|
12790
12865
|
return data.replace(/^\+/, "") === callingCode;
|
|
12791
12866
|
}
|
|
12867
|
+
function compileMultipleOfValidation(multipleOf) {
|
|
12868
|
+
const isMultipleOf = compileIsMultipleOf(multipleOf);
|
|
12869
|
+
const validate2 = (data) => {
|
|
12870
|
+
if (typeof data !== "number" || isMultipleOf(data)) {
|
|
12871
|
+
return true;
|
|
12872
|
+
}
|
|
12873
|
+
const errors = [
|
|
12874
|
+
{
|
|
12875
|
+
keyword: "multipleOf",
|
|
12876
|
+
message: `must be multiple of ${multipleOf}`,
|
|
12877
|
+
params: {
|
|
12878
|
+
multipleOf
|
|
12879
|
+
}
|
|
12880
|
+
}
|
|
12881
|
+
];
|
|
12882
|
+
validate2.errors = errors;
|
|
12883
|
+
return false;
|
|
12884
|
+
};
|
|
12885
|
+
return validate2;
|
|
12886
|
+
}
|
|
12792
12887
|
function compileDateAvailabilityValidation(availability) {
|
|
12793
12888
|
const validate2 = (data) => {
|
|
12794
12889
|
if (typeof data !== "string") {
|
|
@@ -12815,6 +12910,7 @@ var init_ajv_custom_keywords = __esm({
|
|
|
12815
12910
|
"../form-validator/dist/esm/lib/submission-validation/ajv/ajv-custom-keywords.js"() {
|
|
12816
12911
|
init_max();
|
|
12817
12912
|
init_metadata_max_json();
|
|
12913
|
+
init_compile_is_multiple_of();
|
|
12818
12914
|
init_date_availability();
|
|
12819
12915
|
}
|
|
12820
12916
|
});
|
|
@@ -12823,8 +12919,7 @@ var init_ajv_custom_keywords = __esm({
|
|
|
12823
12919
|
function createAjvSchemaValidatorFactory(formSchemaMapper, phoneValidationEnabled, lenientPhoneValidation) {
|
|
12824
12920
|
return function createAjvSchemaValidator(formsSchemas) {
|
|
12825
12921
|
const ajv = new import_ajv.default({
|
|
12826
|
-
allErrors: true
|
|
12827
|
-
multipleOfPrecision: 8
|
|
12922
|
+
allErrors: true
|
|
12828
12923
|
});
|
|
12829
12924
|
(0, import_ajv_formats.default)(ajv);
|
|
12830
12925
|
addCustomFormats(ajv, phoneValidationEnabled);
|