(require("legio/type"))(inheritsopt, definition) → {type}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
inherits |
type |
<optional> |
|
definition |
Object.<String, (constructor|type)> | constructor |
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
Members
-
(static) DEFINED
-
value !== undefined
-
(static) EMPTY
-
value === undefined || value === null
-
(static) FULL
-
value !== undefined && value !== null
-
(static) NULL
-
value === null
-
(static) UNDEFINED
-
value === undefined
Methods
-
(static) is(value)
-
It checks whether the given value is a type or not
Parameters:
Name Type Description value
* -
(static) OR(…types)
-
Returns a custom type which can equal to any of the given types
Parameters:
Name Type Attributes Description types
* <repeatable>