1.0.0 • Published 5 years ago

@darkkenergy/is-type v1.0.0

Weekly downloads
1
License
SEE LICENSE IN LI...
Repository
bitbucket
Last release
5 years ago

IsType

Returns the type name of the value given.

Install

npm i @darkkenergy/is-type -S

Inclusion

// CommonJS
var IsType = require('@darkkenergy/is-type');

// ES6
import IsType from '@darkkenergy/is-type';

Usage

/**
 * Returns the type name of the value given.
 * 
 * @param val {mixed} :[Optional] A value to extract its type.
 * 
 * @return {string} :The type, lowercased, of the given value.
 */

// IsType([any])

/**
 * Convenience method that returns whether the given value is an array.
 * 
 * @param val {mixed} :[Optional] The value to test against type, "array".
 * 
 * @return {boolean} :TRUE if given value is of type, "array", FALSE otherwise.
 */

// IsType.array([any])

/**
 * Convenience method that returns whether the given value is an object.
 * 
 * @param val {mixed} :[Optional] The value to test against type, "object".
 * 
 * @return {boolean} :TRUE if given value is of type, "object", FALSE otherwise.
 */

// IsType.object([any])

import IsType from '@darkkenergy/is-type';

Example:

IsType('');
// Outputs: 'string'

IsType(1);
// Outputs: 'number'

IsType(true);
// Outputs: 'boolean'

IsType(() => {});
// Outputs: 'function

IsType({});
// Outputs: 'object'

IsType([]);
// Outputs: 'array'

Convenience methods:

IsType.array('string');
// Outputs: false

IsType.array([]);
// Outputs: true

Istype.object([]);
// Outputs: false

IsType.object({});
// Outputs: true
1.0.0

5 years ago