Options
All
  • Public
  • Public/Protected
  • All
Menu

Class OneOf

Do the same work with Some which has different unlawful message.

Hierarchy

Index

Constructors

constructor

  • new OneOf(rules: any[]): OneOf

Properties

isRequired

isRequired: boolean

The verifiable instance is required.

type

{boolean}

msg

msg: string | null | Function = null

options

options: any

rule

rule: any

Static displayName

displayName: string

Accessors

optional

  • Set the verifiable rule to be optional.

    const r = eq({
     a: string.optional,
     b: string // .required  by default
    })
    
    r.ok({ b: 'abc' }) === true
    r.ok({ a: 'abc' }) === false
    

    Returns Verifiable

required

Methods

Protected _check

check

clone

get

  • get(paths?: PropertyPath, fallBackVal?: any): any
  • get rule

    eq({ a: 'a' }).get('a') === 'a'
    eq({ a: 'a' }).ok(
     eq({ a: 'a' }).get()
    ) === true
    

    Parameters

    • Optional paths: PropertyPath
    • Optional fallBackVal: any

    Returns any

getRuleString

  • getRuleString(): string

getTypeName

  • getTypeName(): string

hasMessage

  • hasMessage(): boolean

message

  • message(msg?: null | string | Function): Verifiable

ok

  • ok(request?: any): boolean

set

  • set(paths?: PropertyPath, val?: any): Verifiable
  • set rule

    eq({ a: 'a' }).set('a', 'bbb').ok({ a: 'bbb' }) === true
    eq({ a: 'a' }).set(null, 'bbb').ok('bbb') === true
    

    Parameters

    • Optional paths: PropertyPath
    • Optional val: any

    Returns Verifiable

toString

  • toString(): string
  • Gets the verifiable instance string

    oneOf(['123', string]).getRuleString() === "oneOf(['123', string])"
    

    Returns string

toUnlawfulString

  • toUnlawfulString(request?: any, options?: object): string
  • be('2').toUnlawfulString('2') === ''
    be('2').toUnlawfulString(2) === "expected: '2', actual: 2."
    

    Parameters

    • Optional request: any
    • Optional options: object

    Returns string

Generated using TypeDoc