describe-type
The describe-type package contains a variety of package-level functions for timing code execution, retrieving information about object data type.
Installation
npm
Usingnpm i describe-type -S
bower
Usingbower i describe-type -S
Links to CDN
Use this URL for dev/testing
Use this URL in production
describe-type/is
Evaluates whether an object is compatible or not with a specific data type.
Evaluates whether an object is compatible or not with a specific data type.
❗️ Use the is.a, is.an or is.type function instead of the instanceof or toString.call function for type comparisons.
Arguments
- datatype:Function — The data type used to evaluate the expression argument.
- expression:any — The value to check against the data type specified.
Result
- Boolean — A value of true if datatype is compatible with the data type specified in expression, and false otherwise.
Example
The following example creates an instance of the Sprite class named mySprite and uses the is.type function to test whether mySprite is an instance of the Sprite.
{}var mySprite = ;console; // trueconsole; // falseconsole; // false
API
Common
- a(expected :Function, value :any) :boolean
- an(expected :Function, value :any)
- type(expected :Function, value :any) :boolean
- instanceOf(expected :Function, value :any) :boolean
- defined(value :any) :boolean
- undef(value :any) :boolean
- nil(value :any) :boolean
- unfilled(value :any) :boolean
- filled(value :any) :boolean
- empty(value :any) :boolean
- equal(valueA :any, valueB :any) :boolean
- primitive(value :any) :boolean
- exotic(value :any) :boolean
- enumerable(value :any) :boolean
- hosted(key :string | number, host :object) :boolean
- within(value :number, start :number, finish :number) :boolean
Arguments
- args(value :any) :boolean
- args.empty(value :any) :boolean
Array
- arraylike(value :any) :boolean
- arraylike.empty(value :any) :boolean
- array(value :any) :boolean
- array.of(expected :Function, value :any) :boolean
- array.empty(value :any) :boolean
Object
- object(value :any) :boolean
- object.empty(value :any) :boolean
RegExp
- regexp(value :any) :boolean
- regexp.string(value :any) :boolean
- regexp.flags(value :any) :boolean
Stream
- stream(value :any) :boolean
- stream.duplex(value :any) :boolean
- stream.transform(value :any) :boolean
- stream.readable(value :any) :boolean
- stream.writable(value :any) :boolean
String
- string(value :any) :boolean
- string.empty(value :any) :boolean
Function
- fn(value :any) :boolean
- fn.native(value :any) :boolean
- fn.callable(value :any) :boolean
- fn.caste(value :any) :boolean
Boolean
- bool(value :any) :boolean
Date
- date(value :any) :boolean
Number
- number(value :any) :boolean
- numeric(value :any) :boolean
- int(value :any) :boolean
- uint(value :any) :boolean
- infinity(value :any) :boolean
- nan(value :any) :boolean
- odd(value :any) :boolean
- even(value :any) :boolean
- decimal(value :any) :boolean
- min(value: any, others: any[]) :boolean
- max(value: any, others: any[]) :boolean
Error
- error(value :any) :boolean
Symbol
- symbol(value :any) :boolean
Element
- element(value :any) :boolean
Buffer
- buffer(value :any) :boolean
JSON
- jsonlike(value :any) :boolean
Encoded binary
Colors
- hexadecimal(value :any) :boolean
- rgb(value :any) :boolean
- rgba(value :any) :boolean
Common
:umbrella: | ▴is: A, An or Type |
---|---|
| |
| |
|
:umbrella: | ▴is: Instance of |
---|---|
| |
| |
|
:umbrella: | ▴is: Defined |
---|---|
| |
| |
|
:umbrella: | ▴is: undefined |
---|---|
| |
| |
|
:umbrella: | ▴is: null |
---|---|
| |
| |
|
:umbrella: | ▴is: Unfilled |
---|---|
| |
| |
|
:umbrella: | ▴is: Filled |
---|---|
| |
| |
|
:umbrella: | ▴is: Empty |
---|---|
| |
| |
|
:umbrella: | ▴is: Equal |
---|---|
| |
| |
|
:umbrella: | ▴is: Primitive |
---|---|
| |
| |
|
:umbrella: | ▴is: Exotic |
---|---|
| |
| |
|
:umbrella: | ▴is: Enumerable |
---|---|
| |
| |
|
:umbrella: | ▴is: Hosted |
---|---|
| |
| |
|
:umbrella: | ▴is: Within |
---|---|
| |
| |
|
Arguments
:umbrella: | ▴is: Arguments |
---|---|
| |
| |
|
:umbrella: | ▴is: Arguments empty |
---|---|
| |
| |
|
Array
:umbrella: | ▴is: Arraylike |
---|---|
| |
| |
|
:umbrella: | ▴is: Arraylike empty |
---|---|
| |
| |
|
:umbrella: | ▴is: Array |
---|---|
| |
| |
|
:umbrella: | ▴is: Array empty |
---|---|
| |
| |
|
:umbrella: | ▴is: Array of |
---|---|
| |
| |
|
Object
:umbrella: | ▴is: Object |
---|---|
| |
| |
|
:umbrella: | ▴is: Object empty |
---|---|
| |
| |
|
RegExp
:umbrella: | ▴is: RegExp |
---|---|
| |
| |
|
:umbrella: | ▴is: RegExp String |
---|---|
| |
| |
|
:umbrella: | ▴is: RegExp Flags |
---|---|
| |
| |
|
Stream
:umbrella: | ▴is: Stream |
---|---|
| |
| |
|
:umbrella: | ▴is: Stream duplex |
---|---|
| |
| |
|
:umbrella: | ▴is: Stream transform |
---|---|
| |
| |
|
:umbrella: | ▴is: Stream readable |
---|---|
| |
| |
|
:umbrella: | ▴is: Stream writable |
---|---|
| |
| |
|
String
:umbrella: | ▴is: String |
---|---|
| |
| |
|
:umbrella: | ▴is: String empty |
---|---|
| |
| |
|
Function
:umbrella: | ▴is: Function |
---|---|
| |
| |
|
:umbrella: | ▴is: Function Native |
---|---|
| |
| |
|
:umbrella: | ▴is: Function Callable |
---|---|
| |
| |
|
:umbrella: | ▴is: Class |
---|---|
| |
| |
|
Boolean
:umbrella: | ▴is: Boolean |
---|---|
| |
| |
|
Date
:umbrella: | ▴is: Date |
---|---|
| |
| |
|
Number
:umbrella: | ▴is: Number |
---|---|
| |
| |
|
:umbrella: | ▴is: Numeric |
---|---|
| |
| |
|
:umbrella: | ▴is: Integer |
---|---|
| |
| |
|
:umbrella: | ▴is: Unsigned integer |
---|---|
| |
| |
|
:umbrella: | ▴is: Infinity |
---|---|
| |
| |
|
:umbrella: | ▴is: NaN |
---|---|
| |
| |
|
:umbrella: | ▴is: Odd |
---|---|
| |
| |
|
:umbrella: | ▴is: Even |
---|---|
| |
| |
|
:umbrella: | ▴is: Decimal |
---|---|
| |
| |
|
:umbrella: | ▴is: Minimum |
---|---|
| |
| |
|
:umbrella: | ▴is: Maximum |
---|---|
| |
| |
|
Error
:umbrella: | ▴is: Error |
---|---|
| |
| |
|
Symbol
:umbrella: | ▴is: Symbol |
---|---|
| |
| |
|
Element
:umbrella: | ▴is: Element |
---|---|
| |
| |
|
Buffer
:umbrella: | ▴is: Buffer |
---|---|
| |
| |
|
JSON
:umbrella: | ▴is: Jsonlike |
---|---|
| |
| |
|
Encoded binary
:umbrella: | ▴is: Base64 |
---|---|
| |
| |
|
:umbrella: | ▴is: Hex |
---|---|
| |
| |
|
Colors
:umbrella: | ▴is: Hexadecimal |
---|---|
| |
| |
|
:umbrella: | ▴is: RGB |
---|---|
| |
| |
|
:umbrella: | ▴is: RGBA |
---|---|
| |
| |
|
describe-type/as
Evaluates whether an expression specified by the first argument is a member of the data type specified by the second argument. If the first argument is a member of the data type, the result is the first argument. Otherwise, the result is the value null unless the third value is set as default.
The expression used for the second argument must evaluate to a data type.
Evaluates whether an expression specified by the first argument is a member of the data type specified by the second argument. If the first argument is a member of the data type, the result is the first argument. Otherwise, the result is the value null unless the third value is set as default.
The expression used for the second argument must evaluate to a data type.
Arguments
- datatype:Function — The data type used to evaluate the expression argument.
- expression:* — The value to check against the data type specified.
- defaultValue:* — The fallback value.
Result
- Object — The result is expression if expression is a member of the data type specified in datatype.
Otherwise, the result is the value null or the defaultValue.
Example
The following example creates a simple array named myArray and uses the as function with various data types.
var myArray = 'foo' 'bar' 'baz';console; // foo,bar,bazconsole; // nullconsole; // undefined
Variants
- as.any(datatype :Array<Function>, expression :*, defaultValue :*) :any
- as.arrayOf(datatype :Function, expression :*, defaultValue :*) :any
Shortcuts
- as.a(datatype :Function, expression :*, defaultValue :*) :any
- as.an(datatype :Function, expression :*, defaultValue :*) :any
- as.type(datatype :Function, expression :*, defaultValue :*) :any
Variants
:umbrella: | ▴as: Any |
---|---|
| |
| |
|
:umbrella: | ▴as: Array of |
---|---|
| |
| |
|
Shortcuts
:umbrella: | ▴as: A |
---|---|
| |
| |
|
:umbrella: | ▴as: An |
---|---|
| |
| |
|
:umbrella: | ▴as: Type |
---|---|
| |
| |
|
Authors
- Adrian Miranda - Initial work - adriancmiranda
See also the list of contributors who participated in this project.