Home Reference Source

Function

Static Public Summary
public

ajax(options: Object, translate: function, RequestType: function): Promise

Sending request

public

convertData(data: object, type: string, FileListType: function, FormDataType: function): string | FormData

Convert data object to a value for sending

public

Convert input name to path array

public

createObject(path: Array, value: string | FileList): object

Create object by path and value

public

deepmerge(first: Object | Array | *, second: Object | Array | *): Object | Array | *

Merge literal object deeply and concat arrays

public

email(value: string): boolean

Check value is an email

public

extension(value: FileList, extensions: string): boolean

Check file extensions

public

filesize(value: FileList, size: number): boolean

Check file sizes are less than max

public

getData(inputs: object): object

Get data object with values from inputs object

public

getFormOptions(form: HTMLFormElement): {ajax: {url: string, method: string, enctype: string, sendType: *}}

Get ajax options from form

public

getInputData(input: HTMLInputElement | Array): object

Get input value as an object keyed by input name

public

getInputName(input: HTMLInputElement | Array): string

Get name from input or array of inputs

public

getInputRules(input: HTMLInputElement | HTMLSelectElement): object

Get validatation options from input attribute of className

public

getInputValue(input: Element | HTMLInputElement | HTMLSelectElement | Array): string | Date | FileList | Array

Get form input value

public

Create query portion of url for serialize method

public

Get value from radio group

public

getValueByName(name: string, data: object): *

Get value from data object by name

public

Get value from data object by path

public

isCheckable(params: *, data: object): *

Check rule for dependencies

public

max(value: number, number: number): boolean

Check value is less than max number

public

maxDate(date: Date, maxdate: Date): boolean

Check date is less than max date

public

min(value: number, number: number): boolean

Check value is greater than min number

public

minDate(date: Date, mindate: Date): boolean

Check value is greater than min date

public

regexp(value: string, exp: RegExp): boolean

Test RegExp

public

required(value: string | FileList | Array): boolean

Check value is not empty

public

step(value: number, number: number): boolean

Check value is multiple of number

public

tel(value: string): boolean

Check value is phone number

public

url(value: string): boolean

Check value is url

public

validateData(rules: object, methods: object, data: object, errorMessages: object, translate: function): object<string, Array<string>>

Validate data object

public

validateField(rules: object, methods: object, value: string | FileList | Array, name: string, errorMessages: object, data: object, translate: function): Array<string>

Validate field

Static Private Summary
private

initErrorMessages(rules: object, messages: object, methods: object): Object<string, Object<string, string>>

Init error messages

private

markError(field: Element, message: Element, classes: object, errors: Array<string>)

Mark field as invalid

private

markField(field: Element, message: *, states: *, errors: *)

Mark field

private

markValid(field: Element, message: Element, classes: object)

Mark field as valid

Static Public

public ajax(options: Object, translate: function, RequestType: function): Promise source

import {ajax} from 'jedi-validate/src/lib/ajax.js'

Sending request

Params:

NameTypeAttributeDescription
options Object

Sending options

options.url string
options.enctype string

Sending options

options.sendType string

Sending options

options.method string

Sending options

options.data string | FormData

Sending options

translate function
RequestType function

Return:

Promise

todo rewrite to fetch

public convertData(data: object, type: string, FileListType: function, FormDataType: function): string | FormData source

import {convertData} from 'jedi-validate/src/lib/convert-data.js'

Convert data object to a value for sending

Params:

NameTypeAttributeDescription
data object

data object

type string

type of conversion

FileListType function
FormDataType function

Return:

string | FormData

output value

public convertNameToPath(name: string): Array source

import {convertNameToPath} from 'jedi-validate/src/lib/convert-data.js'

Convert input name to path array

Params:

NameTypeAttributeDescription
name string

input name

Return:

Array

path to value in data object

public createObject(path: Array, value: string | FileList): object source

import {createObject} from 'jedi-validate/src/lib/get-data.js'

Create object by path and value

Params:

NameTypeAttributeDescription
path Array

path array

value string | FileList

input value

Return:

object

data object

public deepmerge(first: Object | Array | *, second: Object | Array | *): Object | Array | * source

import deepmerge from 'jedi-validate/src/lib/deepmerge.js'

Merge literal object deeply and concat arrays

Params:

NameTypeAttributeDescription
first Object | Array | *
second Object | Array | *

Return:

Object | Array | *

public email(value: string): boolean source

import {email} from 'jedi-validate/src/lib/methods.js'

Check value is an email

Params:

NameTypeAttributeDescription
value string

email

Return:

boolean

true == valid, false == invalid

public extension(value: FileList, extensions: string): boolean source

import {extension} from 'jedi-validate/src/lib/methods.js'

Check file extensions

Params:

NameTypeAttributeDescription
value FileList

FileList

extensions string

extensions list

Return:

boolean

true == valid, false == invalid

public filesize(value: FileList, size: number): boolean source

import {filesize} from 'jedi-validate/src/lib/methods.js'

Check file sizes are less than max

Params:

NameTypeAttributeDescription
value FileList

FileList

size number

max file size

Return:

boolean

true == valid, false == invalid

public getData(inputs: object): object source

import {getData} from 'jedi-validate/src/lib/get-data.js'

Get data object with values from inputs object

Params:

NameTypeAttributeDescription
inputs object

inputs object

Return:

object

data object

public getFormOptions(form: HTMLFormElement): {ajax: {url: string, method: string, enctype: string, sendType: *}} source

import {getFormOptions} from 'jedi-validate/src/lib/get-options.js'

Get ajax options from form

Params:

NameTypeAttributeDescription
form HTMLFormElement

form element

Return:

{ajax: {url: string, method: string, enctype: string, sendType: *}}

options

public getInputData(input: HTMLInputElement | Array): object source

import {getInputData} from 'jedi-validate/src/lib/get-data.js'

Get input value as an object keyed by input name

Params:

NameTypeAttributeDescription
input HTMLInputElement | Array

input element or Array of HTMLInputElements

Return:

object

data

public getInputName(input: HTMLInputElement | Array): string source

import {getInputName} from 'jedi-validate/src/lib/get-data.js'

Get name from input or array of inputs

Params:

NameTypeAttributeDescription
input HTMLInputElement | Array

input element or Array of HTMLInputElements

Return:

string

input name

public getInputRules(input: HTMLInputElement | HTMLSelectElement): object source

import {getInputRules} from 'jedi-validate/src/lib/get-options.js'

Get validatation options from input attribute of className

Params:

NameTypeAttributeDescription
input HTMLInputElement | HTMLSelectElement

input for validation

Return:

object

rules

public getInputValue(input: Element | HTMLInputElement | HTMLSelectElement | Array): string | Date | FileList | Array source

import {getInputValue} from 'jedi-validate/src/lib/get-data.js'

Get form input value

Params:

NameTypeAttributeDescription
input Element | HTMLInputElement | HTMLSelectElement | Array

input

Return:

string | Date | FileList | Array

value of input, or array of values if input is select

public getQueryPart(name: string, data: object | Array | string): string source

import {getQueryPart} from 'jedi-validate/src/lib/convert-data.js'

Create query portion of url for serialize method

Params:

NameTypeAttributeDescription
name string
data object | Array | string

Return:

string

part of url

public getRadioGroupValue(inputs: Array): string | Array<string> source

import {getRadioGroupValue} from 'jedi-validate/src/lib/get-data.js'

Get value from radio group

Params:

NameTypeAttributeDescription
inputs Array

array of radio inputs

Return:

string | Array<string>

value of checked input

public getValueByName(name: string, data: object): * source

import {getValueByName} from 'jedi-validate/src/lib/get-data.js'

Get value from data object by name

Params:

NameTypeAttributeDescription
name string

input name

data object

data object

Return:

*

public getValueByPath(path: Array, data: object): string source

import {getValueByPath} from 'jedi-validate/src/lib/get-data.js'

Get value from data object by path

Params:

NameTypeAttributeDescription
path Array

value path

data object

data object

Return:

string

value

public isCheckable(params: *, data: object): * source

import {isCheckable} from 'jedi-validate/src/lib/validate-data.js'

Check rule for dependencies

Params:

NameTypeAttributeDescription
params *

validation params

data object

form data

Return:

*

validation params or null if rule is not checkable

public max(value: number, number: number): boolean source

Check value is less than max number

Params:

NameTypeAttributeDescription
value number

number

number number

max number

Return:

boolean

true == valid, false == invalid

public maxDate(date: Date, maxdate: Date): boolean source

import {maxDate} from 'jedi-validate/src/lib/methods.js'

Check date is less than max date

Params:

NameTypeAttributeDescription
date Date

current date

maxdate Date

max date

Return:

boolean

true == valid, false == invalid

public min(value: number, number: number): boolean source

Check value is greater than min number

Params:

NameTypeAttributeDescription
value number

number

number number

min number

Return:

boolean

true == valid, false == invalid

public minDate(date: Date, mindate: Date): boolean source

import {minDate} from 'jedi-validate/src/lib/methods.js'

Check value is greater than min date

Params:

NameTypeAttributeDescription
date Date

current date

mindate Date

max date

Return:

boolean

true == valid, false == invalid

public regexp(value: string, exp: RegExp): boolean source

import {regexp} from 'jedi-validate/src/lib/methods.js'

Test RegExp

Params:

NameTypeAttributeDescription
value string
exp RegExp

regular expression

Return:

boolean

true == valid, false == invalid

public required(value: string | FileList | Array): boolean source

import {required} from 'jedi-validate/src/lib/methods.js'

Check value is not empty

Params:

NameTypeAttributeDescription
value string | FileList | Array

Return:

boolean

true == valid, false == invalid

public step(value: number, number: number): boolean source

Check value is multiple of number

Params:

NameTypeAttributeDescription
value number

number

number number

factor

Return:

boolean

true == valid, false == invalid

public tel(value: string): boolean source

Check value is phone number

Params:

NameTypeAttributeDescription
value string

phone number

Return:

boolean

true == valid, false == invalid

public url(value: string): boolean source

Check value is url

Params:

NameTypeAttributeDescription
value string

url

Return:

boolean

true == valid, false == invalid

public validateData(rules: object, methods: object, data: object, errorMessages: object, translate: function): object<string, Array<string>> source

import {validateData} from 'jedi-validate/src/lib/validate-data.js'

Validate data object

Params:

NameTypeAttributeDescription
rules object

object with rules for validation

methods object

validation methods

data object

data object

errorMessages object

object with error messages

translate function

translation function

Return:

object<string, Array<string>>

object of fields error arrays

public validateField(rules: object, methods: object, value: string | FileList | Array, name: string, errorMessages: object, data: object, translate: function): Array<string> source

import {validateField} from 'jedi-validate/src/lib/validate-data.js'

Validate field

Params:

NameTypeAttributeDescription
rules object

object with rules for validation

methods object

validation methods

value string | FileList | Array

input value

name string

input name

errorMessages object

object with error messages

data object

form data

translate function

translation function

Return:

Array<string>

array of field errors

Static Private

private initErrorMessages(rules: object, messages: object, methods: object): Object<string, Object<string, string>> source

import {initErrorMessages} from 'jedi-validate/src/lib/utils.js'

Init error messages

Params:

NameTypeAttributeDescription
rules object
messages object
methods object

private markError(field: Element, message: Element, classes: object, errors: Array<string>) source

import {markError} from 'jedi-validate/src/lib/utils.js'

Mark field as invalid

Params:

NameTypeAttributeDescription
field Element
message Element
classes object
classes.error string
classes.valid string
errors Array<string>

private markField(field: Element, message: *, states: *, errors: *) source

import {markField} from 'jedi-validate/src/lib/utils.js'

Mark field

Params:

NameTypeAttributeDescription
field Element
message *
states *
errors *

private markValid(field: Element, message: Element, classes: object) source

import {markValid} from 'jedi-validate/src/lib/utils.js'

Mark field as valid

Params:

NameTypeAttributeDescription
field Element
message Element
classes object
classes.error string
classes.valid string