v9sx

v9s extensions

Usage no npm install needed!

<script type="module">
  import v9sx from 'https://cdn.skypack.dev/v9sx';
</script>

README

v9sx

This library contains a number of additional validation rules, modifiers and injections that may be useful to v9s users.

Build Status

Contents

  1. Installation
  2. Rules
    1. E-mail
    2. Float string
    3. HEX string
    4. Integer string
    5. Russian postal code
  3. Modifiers
    1. Compact
    2. Replace factory
    3. To lower case
    4. To upper case
    5. Trim end
    6. Trim start
    7. Trim
  4. Injections
  5. License

Installation

npm install v9sx

Rules

Additional rules.

E-mail

The rule checks an E-mail validness.

import { v9s, simplify } from 'v9s';
import { email } from 'v9sx';

const check = simplify(v9s(false).use(email));

console.log(check('test@example.com')); // true
console.log(check('example.com')); // false

Float string

The rule checks a float string validness.

import { v9s, simplify } from 'v9s';
import { float } from 'v9sx';

const check = simplify(v9s(false).use(float));

console.log(check('123.60')); // true
console.log(check('-123.60')); // true
console.log(check('+123.60')); // false
console.log(check('123')); // true
console.log(check('123,60')); // true
console.log(check('1 123.60')); // false

HEX string

The rule checks the validness of a lowercase HEX string.

import { v9s, simplify } from 'v9s';
import { hex } from 'v9sx';

const check = simplify(v9s(false).use(hex));

console.log(check('123abc')); // true
console.log(check('123ABC')); // false

Integer string

The rule checks an integer string validness.

import { v9s, simplify } from 'v9s';
import { integer } from 'v9sx';

const check = simplify(v9s(false).use(integer));

console.log(check('123456')); // true
console.log(check('123 456')); // false
console.log(check('-123456')); // true
console.log(check('123,456')); // false

Russian postal code

The rule checks a Russian postal code validness.

import { v9s, simplify } from 'v9s';
import { ruPostalCode } from 'v9sx';

const check = simplify(v9s(false).use(ruPostalCode));

console.log(check('123456')); // true
console.log(check('123-456')); // false

Modifiers

Data modifiers.

Compact

Removes space characters inside a value.

import { v9s, simplify } from 'v9s';
import { compact } from 'v9sx';

const check = simplify(v9s(false).use(compact));

console.log(check('1 \t 234 567')); // '1234567'

Replace factory

Returns a modifier function that replaces a substring.

import { v9s, simplify } from 'v9s';
import { replaceFactory } from 'v9sx';

To lower case

Modifies a value to lowercase.

import { v9s, simplify } from 'v9s';
import { toLowerCase } from 'v9sx';

const check = simplify(v9s(false).use(toLowerCase));

console.log(check('ABCDEFГДЕЁЖ')); // 'abcdefгдеёж'

To upper case

Modifies a value to uppercase.

import { v9s, simplify } from 'v9s';
import { toUpperCase } from 'v9sx';

const check = simplify(v9s(false).use(toUpperCase));

console.log(check('abcdefгдеёж')); // 'ABCDEFГДЕЁЖ'

Trim end

Removes spaces at the beginning of a value.

import { v9s, simplify } from 'v9s';
import { trimEnd } from 'v9sx';

const check = simplify(v9s(false).use(trimEnd));

console.log(check('  \t   hello, world!   \t ')); // '  \t   hello, world!'

Trim start

Removes spaces at the end of a value.

import { v9s, simplify } from 'v9s';
import { trimStart } from 'v9sx';

const check = simplify(v9s(false).use(trimStart));

console.log(check('  \t   hello, world!   \t ')); // 'hello, world!   \t '

Trim

Removes the leading and trailing white space and line terminator characters from a string.

import { v9s, simplify } from 'v9s';
import { trim } from 'v9sx';

const check = simplify(v9s(false).use(trim));

console.log(check(' \t hello, world!   \t')); // 'hello, world!'

Injections

Injections that extends a behavior of v9s.

LICENSE

MIT