Neverending Prototype Mode

# npm

Miss any of our Open RFC calls?Watch the recordings here! »

## alyze

0.0.6 • Public • Published

# Alyze

## What is this?

A simple, customizable data validator for javascript.

### Features

• Lots of validation methods
• Control pass or fail on missing values for most methods
• Invert boolean result for all methods (not)
• Configure custom validations for list inclusion and regex matching
• No dependencies

## Sweet! How do I get it?

### npm

``````npm install alyze --save
``````

### bower

``````bower install alyze --save
``````

## What's the Setup?

### For Node

To get a validator instance:

Configuration options (`...`) are optional in both cases above.

### For the Browser

Then you can do

## How does all this work?

### Configuration Options

All configuration options are aptional.

• `onMissingValue` { boolean }
For short-circuiting methods, the value that is immediately returned when test value is `null`, `undefined`, or included in `asMissing`. The default is `false`.

• `asMissing` { array }
Additional values to be treated as 'missing'. You might want to specify an empty string when working with web form data, for instance.

• `extend` { object }
Specify custom validation methods (`.config()` only). See the Extension Methods section for more details.

• `log` { function }
Errors caught during validation are logged. Specify the log function here (`.config()` only).

### Validation Methods

Some notes about the validation methods.

• All methods are generally designed to perform the simplest check possible (granularity).
• All methods accept a test value as the first argument.
• The test value is coerced to the proper type as necessary.
• All methods have an inverse (`not`) version.
• Many methods short-circuit for missing values by immediately returning `onMissingValue`.

#### Non Short-Circuiting

These methods will evaluate missing test values.

##### Existence/Identity Methods
• exists ( v ) - Is not `undefined` and not `null`?
• falsey ( v ) - Evaluates to `false`?
• missing ( v ) - Is `null`, `undefined`, or any `asMissing` value?
• null ( v ) - Is equal to null?
• self ( v ) - Is equal to itself?
• truthy ( v ) - Evaluates to `true`?
• undefined ( v ) - Is equal to `undefined`?
##### Type Of Methods

These methods perform `typeof` checks on the test value.

• boolean ( v )
• func ( v )
• object ( v )
• of ( v, string ) - Is type of the specified type?
• number ( v )
• same ( v, any ) - Type matches comparison value's type?
• string ( v )
• undefined ( v )
##### Instance Of Methods

These methods perform `instanceof` checks on the test value.

• array ( v )
• boolean ( v )
• date ( v )
• error ( v )
• func ( v )
• number ( v )
• object ( v )
• of ( v, class ) - Is instance of `class`?
• string ( v )
##### String Type Of Methods

These methods perform `Object.prototype.toString` checks on the test value.

• array ( v )
• boolean ( v )
• date ( v )
• error ( v )
• func ( v )
• null ( v )
• number ( v )
• object ( v )
• of ( v, string ) - String type is `string`?
• regexp ( v )
• same ( v, any ) - String type matches comparison value's string type?
• string ( v )
• undefined ( v )

#### Short-Circuiting

These methods return `onMissingValue` when they encounter a missing test value.

##### Core Methods
• after ( v, date = today ) - Comes after `date`?
• array ( v ) - Is an array?
• before ( v, date = today ) - Comes before `date`?
• between ( v, a, b ) - Is between `a` and `b` (inclusive)?
• boolean ( v ) - Is a boolean value?
• configurable ( v, prop ) - Can the object property be configured or deleted?
• cube ( v ) - Is the cube root an integer?
• date ( v ) - Is a valid date?
• dawn ( v ) - Date falls in the (average) dawn hour (6)?
• discrete ( v ) - Does adding 1 to value change it?
• divisibleBy ( v, num ) - Is divisible by `num`?
• dusk ( v ) - Date falls in the (average) dusk hour (18)?
• email ( v ) - Is a valid email address?
• empty ( v ) - Has length of zero?
• enumerable ( v, prop ) - Is the object property enumerable?
• equal ( v, any ) - Is equal to (`===`)?
• even ( v ) - Is an even number?
• extensible ( v ) - Is the object extensible?
• false ( v ) - Is equal to `false`?
• finite ( v ) - Is a finite number?
• float ( v ) - Is a floating point number?
• frozen ( v ) - Is object frozen?
• func ( v ) - Is a function?
• hasKey ( v, str ) - Has the property?
• hasOwn ( v, str ) - Directly has (own) property?
• hour ( v, num ) - Date falls in hour (0-23)?
• infinity ( v ) - Is `Infinity`?
• integer ( v ) - Is a whole number?
• itemIn ( v, array ) - Is included by `array`?
• json ( v ) - Can be parsed as JSON?
• length ( v, num ) - Is of length `num`?
• less ( v, any ) - Is less than?
• like ( v, any ) - Is similar to (`==`)?
• longer ( v, num ) - Is length greater than `num`?
• match ( v, re, flgs ) - Matched by `re` pattern?
• midnight ( v ) - Date falls in the midnight hour (0)?
• minute ( v, num ) - Date falls in minute (0-60)?
• month ( v, num ) - Date falls in month (0-11)?
• monthDay ( v, num ) - Date falls in day of month (1-31)?
• more ( v, any ) - Is more than?
• nan ( v ) - Is not a number?
• negative ( v ) - Is value less than 0?
• noon ( v ) - Date falls in the midday hour (12)?
• number ( v ) - Is a number?
• object ( v ) - Is a non-null object?
• odd ( v ) - Is an odd number?
• positive ( v ) - Is value greater than 0?
• quad ( v ) - Is the quad root an integer?
• regexp ( v ) - Is a regular expression pattern?
• reversible ( v ) - Is string the same when reversed?
• sealed ( v ) - Is object sealed?
• second ( v, num ) - Date falls in second (0-60)?
• shorter ( v, num ) - Is length smaller than `num`?
• square ( v ) - Is the square root an integer?
• string ( v ) - Is a string?
• thenable ( v ) - Has a `then` property that is a function?
• trimable ( v ) - Has whitespace at beginning or end?
• true ( v ) - Is equal to `true`?
• url ( v ) - Is a valid URL?
• weekDay ( v, num ) - Date falls in day of week (0-6)?
• writable ( v, prop ) - Can the object property value be changed?
• year ( v, num ) - Date falls within year?
• zero ( v ) - Is equal to `0`?
##### String Inclusion/Composition Methods

These methods test if a string value is composed of or includes a given set of characters.

Each of these methods can be passed an optional `count` parameter.

• if `count` is undefined or null, test value must be composed of only the implied character(s).
• if `count` is >= 0, test value must contain implied character(s) exactly `count` times.
• otherwise (`count` is < 0), test value must contain implied character(s) at least `count` (absolute value) times.

All of these methods are ASCII character based.

• alpha ( v, count ) - Has letters?
• alphanumeric ( v, count ) - Has letters or numbers?
• binary ( v, count ) - Has 1's or 0's?
• decimal ( v, count ) - Has numbers 0 through 9 (same as .numeric())?
• hexadecimal ( v, count ) - Has numbers or letters A through F?
• lowercase ( v, count ) - Has lower case characters?
• numeric ( v, count ) - Has numbers 0 through 9 (same as .decimal())?
• octal ( v, count ) - Has numbers 0 through 7?
• printable ( v, count ) - Has printable characters?
• punctuation ( v, count ) - Has special characters?
• ternary ( v, count ) - Has 2's, 1's or 0's?
• uppercase ( v, count ) - Has upper case characters?
• whitespace ( v, count ) - Has whitespace characters?
• word ( v, count ) - Has word characters (letters, numbers, underscores)?
##### Day of Week Methods

These methods test if a date falls on a specific day of the week.

• sunday ( v )
• monday ( v )
• tuesday ( v )
• wednesday ( v )
• thursday ( v )
• friday ( v )
• saturday ( v )
##### Month of Year Methods

These methods test if a date falls in a specific month.

• january ( v )
• february ( v )
• march ( v )
• april ( v )
• may ( v )
• june ( v )
• july ( v )
• august ( v )
• september ( v )
• october ( v )
• november ( v )
• december ( v )

#### Extension

These methods can be added through the `extend` config parameter. They are applied to class prototypes to make them available on all validator instances.

##### Includer Methods

These methods check if test value is included in a list of values and are short-circuited for missing values.

• daysAbbr ( v ) - In list of 3-char day abbreviations?
• daysName ( v ) - In list of day names?
• monthsAbbr ( v ) - In list of 3-char month abbreviations?
• monthsName ( v ) - In list of month names?

These methods are derived from arrays or strings found in the `extend` object passed to configuration.

The above makes the following method available:

##### Matcher Methods

These methods check if test value matches a regular expression pattern and are short-circuited for missing values.

These methods are derived from `RegExp` items found in the `extend` object passed to configuration.

The above makes the following method available:

##### Custom Methods

These methods perform a custom check on the test value and are short-circuited for missing values.

• ccNumber ( v ) - Is a valid credit card number?

These methods are derived from functions found in the `extend` object passed to configuration.

Custom methods should return a boolean value, and they may also have additional parameters.

The above makes the following method available:

#### List Element Validators

These methods deal with test values that are arrays and test every value in the array.

Note that:

• All validation methods (including Extension methods) have versions that test array elements.
• Short-circuiting and negation rules apply in the same manner as a method's non-array counterpart.
• For missing array values in short-circuited methods a result of `false` is assumed for that value.
• Each method returns the same result as the non-array version if passed a non-array value.
##### 'All' Methods

These methods return true if every value in the test array passes the given test.

Other method groups on the validator object also have `all` versions.

For instance, to use Type Of methods, do

A short-circuited `all` method will return `false` if any array value is missing.

##### 'Any' Methods

These methods return true if at least one value in the test array passes the given test.

Other method groups on the validator object also have `any` versions.

For instance, to use Instance Of methods, do

A short-circuited `any` method will skip over missing array values.

## What Else?

{ dist files } { updates } { feedback } { license } { versioning }

###### Tests
``````npm test
``````
###### Finally

Happy Validating!

## Keywords

### Install

`npm i alyze`

4

0.0.6

MIT
{"ft_lang_label":"__label__en","ft_lang_prob":0.63800925,"math_prob":0.7835341,"size":10809,"snap":"2020-24-2020-29","text_gpt3_token_len":2895,"char_repetition_ratio":0.18815364,"word_repetition_ratio":0.21748981,"special_character_ratio":0.29826996,"punctuation_ratio":0.12479914,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9526927,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-06T08:02:52Z\",\"WARC-Record-ID\":\"<urn:uuid:6ad1330e-f807-4c9a-8eea-de47521a4cea>\",\"Content-Length\":\"121760\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9747e861-f8ac-494f-901c-82bcb04faf24>\",\"WARC-Concurrent-To\":\"<urn:uuid:897bb8a6-e899-4a40-add7-f983ea15f38d>\",\"WARC-IP-Address\":\"104.16.92.83\",\"WARC-Target-URI\":\"https://www.npmjs.com/package/alyze\",\"WARC-Payload-Digest\":\"sha1:TTBHXZYBET5VJ5EZNH5NOFTKEB7KRS3O\",\"WARC-Block-Digest\":\"sha1:H54M3YBI47NOYOHPHMYMHRFAOX3T3NRT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593655890157.10_warc_CC-MAIN-20200706073443-20200706103443-00089.warc.gz\"}"}