Module: legio/type

legio/type

(require("legio/type"))(inheritsopt, definition) → {type}

Parameters:
Name Type Attributes Description
inherits type <optional>
definition Object.<String, (constructor|type)> | constructor
Source:
Returns:
A function which (when called) chcecks if the given object corresponds with the definition.
Type
type
Example
var
A = type({ b: String, c: Number }),
B = type(A, { a: Function });

var
a = {
  a: function () {},
  b: "hello",
  c: 42
},
b = {
  a: "error",
  b: "hello",
  c: 42
};

console.log(A(a), A(b)); // true, true
console.log(B(a), B(b)); // true, false

var
C = type({ d: type.UNDEFINED, a: type.OR(String, Function) });

console.log(C(a), C(b)); // true, true
Source:

Members

(static) DEFINED

value !== undefined
Source:

(static) EMPTY

value === undefined || value === null
Source:

(static) FULL

value !== undefined && value !== null
Source:

(static) NULL

value === null
Source:

(static) UNDEFINED

value === undefined
Source:

Methods

(static) is(value)

It checks whether the given value is a type or not
Parameters:
Name Type Description
value *
Source:

(static) OR(…types)

Returns a custom type which can equal to any of the given types
Parameters:
Name Type Attributes Description
types * <repeatable>
Source:

Type Definitions

type(value)

Parameters:
Name Type Description
value *
Source:

„Nikdy se nesměji nejlépe. Bojím se, že by to mohlo být naposledy.“ Jan Werich