🚀 DAY 4 OF LAUNCH WEEK: Introducing GitHub Actions Scanning Support.Learn more
Socket
Book a DemoInstallSign in
Socket

formation-engine

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formation-engine

formation-engine is a simple validation engine that follows the rule - Rules plus Values equals Results

latest
Source
npmnpm
Version
0.3.1
Version published
Maintainers
1
Created
Source

formation-engine

Rules plus Values equals Results

Formation.js is a simple validation engine that exposes validate(rules: Rules, values: Values): Results function. See type definitions below.

Type Definitions

Value

export type Value = boolean | number | string | Object | null

Value is something that we might want to validate, it can be one of following types: boolean, number, string, Object or null. By convention null is used for to denote empty or default values. When input field has nothing in it, or radio button is neither selected nor deselected - it‘s empty.

Message

type Message = string Message is a string, In real life application message should be an id pointing to i18n/l10n bundle.

Validation

type Validation = (value: Value) => ?Message

Validation is a function that accepts Value and returns Message or null (Maybe Message).

Result

type Result {value: Value, messages: Message[]}

Result structure contains value and list of messages, empty list of messages means that result is valid.

Rule

export type Rule = {validations: Validation[], defaultValue: Value, required: boolean}

Rule structure contains list of validation functions, default value if any and required flag. Rule can be executed against Value to produce Result.

Rules

type Rules = {[string]: Rule}

Rules structure is a map of keys and rules.

Values

type Values = {[string]: Value}

Values structure is a map of keys and values.

Results

type Results = {[string]: Result}

Results structure is a map of keys and results

Keywords

validation

FAQs

Package last updated on 01 Aug 2017

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