🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@mihanizm56/validators

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mihanizm56/validators

simple and regexp validation service

latest
npmnpm
Version
1.2.1
Version published
Maintainers
1
Created
Source

@wildberries/validators

Sollution for validations

Benefits:

  • Works isomorphic (node and browser environments)
  • Provides validators for simple values and simple pattern based
  • Provides functions for validations for react-final-form
  • Provides function to validate values with custom patterns

Examples of usage

installation

npm install @wildberries/validators

SimpleValidator usage

import { SimpleValidator } from "@wildberries/validators";

const minValidatedValue: ValidatorReturnsType = new SimpleValidator().minLenghtValidate(1,'test error message')('12313')
const maxValidatedValue: ValidatorReturnsType = new SimpleValidator().maxLenghtValidate(1,'test error message')('12313')
const requiredValidatedValue: ValidatorReturnsType = new SimpleValidator().requiredValidator('test error message')('')

PatternValidator usage

import { PatternValidator } from "@wildberries/validators";

const numberValidatedValue: ValidatorReturnsType = new PatternValidator().numbersOnly('test error message')('12313')
const cyrillicValidatedValue: ValidatorReturnsType = new PatternValidator().cyrillicsOnly('test error message')('12313')
const decimalValidatedValue: ValidatorReturnsType = new PatternValidator().decimalNumbers('test error message')('12313')
const emailValidatedValue: ValidatorReturnsType = new PatternValidator().email('test error message')('12313')
const phoneValidatedValue: ValidatorReturnsType = new PatternValidator().phoneNumber('test error message')('12313')
const dateValidatedValue: ValidatorReturnsType = new PatternValidator().dateOnly('test error message')('12313')

const customValidatedValue: ValidatorReturnsType = new PatternValidator().customPatternValidate(
    {
        pattern:/^[foo]$/,
        errorTextValue:'not'
    }
)('foo')

Custom validation usage

import { getIsValueMatchPattern } from "@wildberries/validators";

const isValueMatch: boolean = getIsValueMatchPattern(
    {
        value:'foo',
        pattern:/^[foo]$/
    }
)

Validators with React-Final-Form usage

import { Form } from 'react-final-form';
import { FormTextInput } from '@/components/form-text-input'
import { PatternValidator, composeValidators, SimpleValidator } from "@wildberries/validators";

const simpleValidator = new SimpleValidator()
const patternValidator = new PatternValidator()

const fieldValidations: string = composeValidators(
    [
        simpleValidator.requiredValidator('test error message'),
        simpleValidator.maxLenghtValidate(13, 'test error message'),
        patternValidator.phoneNumber('test error message'),
    ]
),

<Form
    onSubmit={onSubmit}
    initialValues={initialValues}
    render={({ handleSubmit }) => (
        <form onSubmit={handleSubmit} className={cn('Example-form')}>
            <div className={cn('Example-form__button-container')}>
                <Field
                    name={name}
                    component={FormTextInput}
                    validate={fieldValidations}
                />
            </div>
        </form>
    )}
/>

FAQs

Package last updated on 12 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts