1.0.1 • Published 6 years ago

walli-decorator v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

walli-decorator

build status Test coverage NPM version NPM Downloads

The semantic walli definition by decorator.

API

walliDecorator

src/index.js:31-60

The decorator about walli.

Parameters

  • walliInstance

Examples

import walliDecorator, { check } from 'walli-decorator'
import * as w from 'walli'
class A {
  @walliDecorator(w.string)
  abc = 123
}

check(new A()) // { abc: 'expected type: string, actual type: number.' }

// The usage of options.recursive
class B {
  a = new A()
}

check(new B()) // null
check(new B(), { recursive: true }) // { a: { abc: 'expected type: string, actual type: number.' } }

check

src/index.js:97-174

Check the target

Parameters

  • target {any}
  • options Object {{}}
    • options.abortWhenFail {boolean} - Whether aborting the check flow when illegal value has been found. (optional, default false)
    • options.excludes {string[]} - The excluding field name list. (optional, default [])
    • options.includes {string[]} - The including field name list. (optional, default [])
    • options.order {string[]} - The order of field name list. (optional, default [])
    • options.ignoreValIsUndefined Whether ignoring the check flow when value is undefined. (optional, default true)
    • options.ignoreNotHasVal Whether ignoring the check flow when the target has not value. (optional, default true)
    • options.recursive Whether checking the target recursively. (optional, default false)
    • options.returnWalliResult Whether returning walli check's result. (optional, default false)

Returns (null | object)