Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@altiore/form

Package Overview
Dependencies
Maintainers
1
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@altiore/form - npm Package Compare versions

Comparing version 0.3.55 to 0.3.56

dist/validators/@common/get-error-message.d.ts

6

dist/@common/types.d.ts

@@ -55,5 +55,3 @@ import { MouseEventHandler, MutableRefObject } from 'react';

}
export declare type ValidateFuncType = (value: any, getFieldValueByName?: ((name: string) => any) | any) => {
error: Error;
value: any;
} | undefined | any;
export declare type ValidateFuncType = (value: any, fieldName?: string, getFieldValueByName?: (name: string) => any) => string | undefined;
export declare type ReusableValidator<T> = (getMessage: null | undefined | string | ((value: any, forCheck: T) => string), forCheck?: T) => ValidateFuncType;
import { MutableRefObject } from 'react';
import { ValidateFuncType } from '../../../../@common/types';
export declare const useValidateList: (inputRef: MutableRefObject<HTMLElement>, validators: Array<ValidateFuncType>, items: Array<number>) => string[];
export declare const useValidateList: (inputRef: MutableRefObject<HTMLElement>, validators: Array<ValidateFuncType>, items: Array<number>, name?: string) => string[];

@@ -5,3 +5,3 @@ import { useMemo } from 'react';

};
export var useValidateList = function (inputRef, validators, items) {
export var useValidateList = function (inputRef, validators, items, name) {
return useMemo(function () {

@@ -12,5 +12,7 @@ var hasValidation = Boolean(validators === null || validators === void 0 ? void 0 : validators.length);

validators.forEach(function (validate) {
var result = validate(items, DEF_GET_VALUE);
if (result === null || result === void 0 ? void 0 : result.error) {
ers.push(result.error.message);
// TODO: вместо того, чтоб передавать в эту функцию для валидации items,
// возможно, целесообразнее найти все значения массива
var result = validate(items, name, DEF_GET_VALUE);
if (result) {
ers.push(result);
}

@@ -20,3 +22,3 @@ });

return ers;
}, [validators, items]);
}, [validators, items, name]);
};

@@ -19,5 +19,5 @@ var __assign = (this && this.__assign) || function () {

var _b = useList(name, fieldMeta, setItems), list = _b[0], items = _b[1];
var errors = useValidateList(listRef, validators, items);
var errors = useValidateList(listRef, validators, items, fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.name);
return React.createElement(component, __assign(__assign({}, componentProps), { error: errors === null || errors === void 0 ? void 0 : errors[0], errors: errors, isInvalid: Boolean(errors.length), list: list, listRef: listRef, name: name }));
};
export var ValidatedFieldArray = React.memo(ValidatedFieldArrayComponent);

@@ -74,5 +74,5 @@ import { useCallback, useEffect, useMemo, useState, } from 'react';

validators.forEach(function (validate) {
var result = validate(value_1, getFormValueByName);
if (result === null || result === void 0 ? void 0 : result.error) {
errors.push(result.error.message);
var result = validate(value_1, field === null || field === void 0 ? void 0 : field.name, getFormValueByName);
if (result) {
errors.push(result);
}

@@ -92,3 +92,10 @@ });

}
}, [getFormValueByName, field === null || field === void 0 ? void 0 : field.setErrors, setErrors, type, validators]);
}, [
getFormValueByName,
field === null || field === void 0 ? void 0 : field.setErrors,
field === null || field === void 0 ? void 0 : field.name,
setErrors,
type,
validators,
]);
var debounceHandle = useCallback(_debounce(handleDebounceFn, 200), []);

@@ -95,0 +102,0 @@ var handleBlur = useCallback(function (e) {

@@ -1,2 +0,2 @@

import { ValidateFuncType } from '../../@common/types';
export declare const maxLength: (length: number) => ValidateFuncType;
import { ReusableValidator } from '../../@common/types';
export declare const maxLength: ReusableValidator<number>;

@@ -1,12 +0,13 @@

export var maxLength = function (length) {
import { getErrorMessage } from '../@common/get-error-message';
export var maxLength = function (getMessage, length) {
return function (value) {
var stringedValue = value.toString();
if (typeof (value === null || value === void 0 ? void 0 : value.length) !== 'number') {
throw new Error("\u041D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0442\u0438\u043F \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u044F \u0434\u043B\u044F \u0432\u0430\u043B\u0438\u0434\u0430\u0446\u0438\u0438 \"" + typeof value + "\" \u043F\u0435\u0440\u0435\u0434\u0430\u043D \u0444\u0443\u043D\u043A\u0446\u0438\u0438 \u0434\u043B\u044F \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u0434\u0430\u043D\u043D\u044B\u0445 \"minLength\"");
}
if (length < 0) {
throw new Error("Param 'length' cannot be less than 0");
throw new Error("\u0417\u0430\u0434\u0430\u043D\u043D\u0430\u044F \u0434\u043B\u0438\u043D\u0430 \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0431\u044B\u0442\u044C \u043C\u0435\u043D\u044C\u0448\u0435 \u043D\u0443\u043B\u044F");
}
if (stringedValue.length > length) {
return {
error: new Error("\u041C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u0430\u044F \u0434\u043B\u0438\u043D\u0430 \u0432\u0432\u0435\u0434\u0435\u043D\u043D\u043E\u0433\u043E \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u044F - " + length),
value: value,
};
if (value.length > length) {
var defError = "\u041C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u0430\u044F \u0434\u043B\u0438\u043D\u0430 \u0432\u0432\u0435\u0434\u0435\u043D\u043D\u043E\u0433\u043E \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u044F - " + length;
return getErrorMessage(value, length, defError, getMessage);
}

@@ -13,0 +14,0 @@ return undefined;

@@ -1,2 +0,2 @@

import { ValidateFuncType } from '../../@common/types';
export declare const minLength: (length: number) => ValidateFuncType;
import { ReusableValidator } from '../../@common/types';
export declare const minLength: ReusableValidator<number>;

@@ -1,15 +0,14 @@

export var minLength = function (length) {
import { getErrorMessage } from '../@common/get-error-message';
export var minLength = function (getMessage, length) {
return function (value) {
if (value === void 0) { value = ''; }
if (typeof (value === null || value === void 0 ? void 0 : value.length) !== 'number') {
throw new Error("Not supported type \"" + typeof value + "\" provided to validate function \"minLength\"");
throw new Error("\u041D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0442\u0438\u043F \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u044F \u0434\u043B\u044F \u0432\u0430\u043B\u0438\u0434\u0430\u0446\u0438\u0438 \"" + typeof value + "\" \u043F\u0435\u0440\u0435\u0434\u0430\u043D \u0444\u0443\u043D\u043A\u0446\u0438\u0438 \u0434\u043B\u044F \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u0434\u0430\u043D\u043D\u044B\u0445 \"minLength\"");
}
if (length < 0) {
throw new Error("Param 'length' cannot be less than 0");
throw new Error("\u0417\u0430\u0434\u0430\u043D\u043D\u0430\u044F \u0434\u043B\u0438\u043D\u0430 \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0431\u044B\u0442\u044C \u043C\u0435\u043D\u044C\u0448\u0435 \u043D\u0443\u043B\u044F");
}
if (value.length < length) {
return {
error: new Error("\u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u0430\u044F \u0434\u043B\u0438\u043D\u0430 \u0432\u0432\u0435\u0434\u0435\u043D\u043D\u043E\u0433\u043E \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u044F - " + length),
value: value,
};
var defError = "\u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u0430\u044F \u0434\u043B\u0438\u043D\u0430 \u0432\u0432\u0435\u0434\u0435\u043D\u043D\u043E\u0433\u043E \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u044F - " + length;
return getErrorMessage(value, length, defError, getMessage);
}

@@ -16,0 +15,0 @@ return undefined;

@@ -1,2 +0,2 @@

import { ValidateFuncType } from '../../@common/types';
export declare const regexp: (regex: RegExp) => ValidateFuncType;
import { ReusableValidator } from '../../@common/types';
export declare const regexp: ReusableValidator<RegExp>;

@@ -1,9 +0,8 @@

export var regexp = function (regex) {
import { getErrorMessage } from '../@common/get-error-message';
export var regexp = function (getMessage, regex) {
return function (value) {
var stringedValue = value.toString();
if (!regex.test(stringedValue)) {
return {
error: new Error(stringedValue + " does not fit the regular expression " + regex),
value: value,
};
var defError = "\"" + stringedValue + "\" \u043D\u0435 \u0441\u043E\u043E\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u0435\u0442 \u0440\u0435\u0433\u0443\u043B\u044F\u0440\u043D\u043E\u043C\u0443 \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u044E " + regex;
return getErrorMessage(value, regex, defError, getMessage);
}

@@ -10,0 +9,0 @@ return undefined;

{
"name": "@altiore/form",
"version": "0.3.55",
"version": "0.3.56",
"description": "Form helper for building powerful forms",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc