valid

Vecta.valid

Returns an object that contains all the methods that can be used for input validations.

Methods

.arrow(end) Returns: boolean

Function to validate an arrow.

NameTypeDescription
endstring

An arrow's id

Returns:

Returns true if the arrow is found, false otherwise.

Examples:
console.log(Vecta.valid.arrow('thick')); //true
console.log(Vecta.valid.arrow('thick.end')); //true

.arrowSize(val) Returns: boolean

Function to validate an arrow size.

NameTypeDescription
valnumber

An arrow size.

Returns:

Returns true if the arrow size is valid, false otherwise. Valid arrow size must be more than 0.

Examples:
console.log(Vecta.valid.arrowSize(20)); //true

.boolean(val) Returns: boolean

Function to validate a boolean value.

NameTypeDescription
valboolean|number

A boolean value.

Valid boolean values are limited to below:

true, false, 1, 0

Returns:

Returns true if the boolean value is valid, false otherwise.

Examples:
console.log(Vecta.valid.boolean(false)); //true
console.log(Vecta.valid.boolean(0)); //true

.color(color) Returns: boolean

Function to validate a color code

NameTypeDescription
colorstring

A color code.

Color code format is limited to below:

hex3, hex6, rgb, rgba, 'none' or a defined color, e.g.: 'blue', 'red'

Returns:

Returns true if the color code is valid, false otherwise.

Examples:
console.log(Vecta.valid.color('#fff')); //true
console.log(Vecta.valid.color('rgba(255, 0, 0, 1)')); //true
console.log(Vecta.valid.color('blue')); //true

.dashArray(dash) Returns: boolean

Function to validate a stroke dash array value.

NameTypeDescription
dashstring

A dash array value.

Valid dash arrays values are:

(length)(comma or white space) Examples: "2 2", "0.1mm 0.1in"

Returns:

Returns the dash array value if the dash array value is valid, false otherwise.

Examples:
console.log(Vecta.valid.dashArray('2 2')); //2 2
console.log(Vecta.valid.dashArray('none')); //false

.email(val) Returns: boolean

Function to validate email address

NameTypeDescription
valstring

The email to be validated

Returns:

Returns true if value is a valid email address, false otherwise.

Examples:
var email = '[email protected]';

console.log(Vecta.valid.email(email)); //true

.font(font) Returns: boolean

Function to validate a font value.

NameTypeDescription
fontstring

A font value.

Returns:

Returns true if the font value is valid, false otherwise.

Examples:
console.log(Vecta.valid.font('Times New Roman')); //true

.fontSize(size) Returns: boolean

Function to validate a font size value.

NameTypeDescription
sizenumber|string

A font size value. If no value is provided, unit is default to px.

Valid font size units are limited to below:

'px', 'pt'

Returns:

Returns true if the font size value is valid, false otherwise.

Examples:
console.log(Vecta.valid.fontSize(9)); //true
console.log(Vecta.valid.fontSize('20 px')); //true

.fontStyle(style) Returns: boolean

Function to validate a font style value.

NameTypeDescription
stylestring

A font style value.

Valid font style values are limited to below:

'normal', 'italic'

Returns:

Returns true if the font style value is valid, false otherwise.

Examples:
console.log(Vecta.valid.fontStyle('italic')); //true

.fontWeight(weight) Returns: boolean

Function to validate a font weight value.

NameTypeDescription
weightstring

A font weight value.

Valid font weight values are limited to below:

'normal', 'bold'

Returns:

Returns true if the font weight value is valid, false otherwise.

Examples:
console.log(Vecta.valid.fontWeight('bold')); //true

.increment(val) Returns: boolean

Function to validate the increment value.

NameTypeDescription
valstring

An increment value or regular expression string.

Returns:

Returns true if the string is 'true', 'false' or a Regular Expression, false otherwise.

Examples:
console.log(Vecta.valid.increment('true')); //true

.json(str) Returns: boolean

Function to validate a json.

NameTypeDescription
strstring

A string value.

Returns:

Returns true if the string can be parsed to JSON, false otherwise.

Examples:
console.log(Vecta.valid.json('{"a": 1, "b": 2}')); //true

.lineCap(cap) Returns: boolean

Function to validate a line cap value.

NameTypeDescription
capstring

A line cap value.

Valid line cap values are limited to below:

'round', 'butt', 'square'

Returns:

Returns true if the line cap value is valid, false otherwise.

Examples:
console.log(Vecta.valid.lineCap('round')); //true

.lineJoin(join) Returns: boolean

Function to validate a line join value.

NameTypeDescription
joinstring

A line join value.

Valid line join values are limited to below:

'miter', 'round', 'bevel'

Returns:

Returns true if the line join value is valid, false otherwise.

Examples:
console.log(Vecta.valid.lineJoin('miter')); //true

.lineSpacing(space) Returns: boolean

Function to validate a line spacing value.

NameTypeDescription
spacenumber

A line spacing value, in digits only.

Returns:

Returns true if the line spacing value is valid, false otherwise.

Examples:
console.log(Vecta.valid.lineSpacing(1.0)); //true

Function to validate a link.

NameTypeDescription
linkstring

A link from the Internet.

Returns:

Returns true if the link is valid, false otherwise.

Examples:
console.log(Vecta.valid.link('https://vecta.io')); //true

.notEmpty(val) Returns: boolean

Function to validate if selection object is not empty

NameTypeDescription
valstring

A string value

Returns:

Returns true if string is not empty, false otherwise.

Examples:
console.log(Vecta.valid.notEmpty('')); //false
console.log(Vecta.valid.notEmpty('Test')); //true

.number(str) Returns: boolean

Function to validate a number.

NameTypeDescription
strnumber|string

A number or a number in string format.

Returns:

Returns true if the value is valid, false otherwise.

Examples:
console.log(Vecta.valid.number('50')); //true
console.log(Vecta.valid.number(30)); //true

.opacity(opacity) Returns: boolean

Function to validate an opacity value.

NameTypeDescription
opacitynumber

An opacity value. Valid opacity values are limited to the range from 0 to 1.

Returns:

Returns true if the opacity value is valid, false otherwise.

Examples:
console.log(Vecta.valid.opacity(0.2)); //true

.percent(val) Returns: boolean

Function to validate percentages

NameTypeDescription
valstring

The percentage value to be validated

Returns:

Returns true if value is a valid percentage, false otherwise.

Examples:
var percent = '90%';

console.log(Vecta.valid.percent(percent)); //true

.price(str) Returns: boolean

Function to validate whether a string is a price.

NameTypeDescription
strnumber|string

A price number or string.

Valid price format is limited to below:

Only digits, decimals are allowed, and commas are allowed between digits before decimal places.

Returns:

Returns true if the string is a price, false otherwise.

Examples:
console.log(Vecta.valid.price('50.00')); //true
console.log(Vecta.valid.price(40,000)); //true

.textAlign(align) Returns: boolean

Function to validate a text align value.

NameTypeDescription
alignstring

A text align value.

Valid text align values are limited to below:

'top', 'central', 'bottom'

Returns:

Returns true if the text align value is valid, false otherwise.

Examples:
console.log(Vecta.valid.textAlign('top')); //true

.textAnchor(anchor) Returns: boolean

Function to validate a text anchor value.

NameTypeDescription
anchorstring

A text anchor value.

Valid text anchor values are limited to below:

'start', 'middle', 'end'

Returns:

Returns true if the text anchor value is valid, false otherwise.

Examples:
console.log(Vecta.valid.textAnchor('middle')); //true

.textDecoration(decor) Returns: boolean

Function to validate a text decoration value.

NameTypeDescription
decorstring

A text decoration value.

Valid text decoration values are limited to below:

'none', 'underline'

Returns:

Returns true if the text decoration value is valid, false otherwise.

Examples:
console.log(Vecta.valid.textDecoration('underline')); //true

.textStrikeThrough(style) Returns: boolean

Function to validate a text strikethrough value.

NameTypeDescription
stylestring

A text strikethrough value.

Valid text strikethrough values are limited to below:

'none', 'line-through'

Returns:

Returns true if the text strikethrough value is valid, false otherwise.

Examples:
console.log(Vecta.valid.textStrikeThrough('line-through')); //true

.unit(length) Returns: boolean

Function to check if unit is valid

NameTypeDescription
lengthstring

The length to be validated.

If no unit is provided, it is default to px.

Valid units are limited to 'px', 'in', 'cm', 'mm'

Returns:

Returns true if value is a valid unit value, false otherwise.

Examples:
console.log(Vecta.valid.unit(9)); //true
console.log(Vecta.valid.unit('9mm')); //true
console.log(Vecta.valid.unit('9 in')); //true
vecta.io Early Access