GithubHelp home page GithubHelp logo

nirth / formation-engine Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 94 KB

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

License: MIT License

JavaScript 100.00%

formation-engine's Introduction

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

formation-engine's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.