f-utility
Version:
functional utilities
165 lines (153 loc) • 4.74 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isPOJO = exports.isDistinctObject = exports.isArray = exports.isObject = exports.isNil = exports.isString = exports.isFunction = exports.isNumber = exports.isBoolean = exports.isTypeof = exports.__isTypeof = undefined;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _katsuCurry = require("katsu-curry");
var __isTypeof = exports.__isTypeof = function __isTypeof(type, x) {
return type === (typeof x === "undefined" ? "undefined" : _typeof(x));
}; // eslint-disable-line valid-typeof
/**
* returns boolean based on type
* @method isTypeof
* @param {string} type
* @param {*} x - anything
* @returns {boolean} whether x is typeof type
* @public
* @example
* import {isTypeof} from 'f-utility'
* isTypeof(`boolean`, true) // true
* isTypeof(`boolean`, `nope`) // false
*/
var isTypeof = exports.isTypeof = (0, _katsuCurry.curry)(__isTypeof);
/**
* test whether something is a boolean
* @method isBoolean
* @param {*} x - anything
* @returns {boolean} - true if the input is a boolean
* @public
* @example
* import {isBoolean} from 'f-utility'
* isBoolean(true) // true
* isBoolean(1) // false
* isBoolean(`a`) // false
* isBoolean([`a`]) // false
*/
var isBoolean = exports.isBoolean = isTypeof("boolean");
/**
* test whether something is a number
* @method isNumber
* @param {*} x - anything
* @returns {boolean} - true if the input is a number
* @public
* @example
* import {isNumber} from 'f-utility'
* isNumber(true) // false
* isNumber(1) // true
* isNumber(`a`) // false
* isNumber([`a`]) // false
*/
var isNumber = exports.isNumber = isTypeof("number");
/**
* test whether something is a function
* @method isFunction
* @param {*} x - anything
* @returns {boolean} - true if the input is a function
* @public
* @example
* import {isFunction} from 'f-utility'
* isFunction(true) // false
* isFunction(1) // false
* isFunction(`a`) // false
* isFunction([`a`]) // false
* isFunction(() => {}) // true
*/
var isFunction = exports.isFunction = isTypeof("function");
/**
* test whether something is a string
* @method isString
* @param {*} x - anything
* @returns {boolean} - true if the input is a string
* @public
* @example
* import {isString} from 'f-utility'
* isString(true) // false
* isString(1) // false
* isString(`a`) // true
* isString([`a`]) // false
* isString(() => {}) // false
*/
var isString = exports.isString = isTypeof("string");
/**
* test whether something is null-ish
* @method isNil
* @param {*} x - anything
* @returns {boolean} - true if the input is null-ish
* @public
* @example
* import {isNil} from 'f-utility'
* isNil(true) // false
* isNil(1) // false
* isNil(`a`) // false
* isNil([`a`]) // false
* isNil({}) // false
* isNil(null) // true
* isNil(undefined) // true
*/
var isNil = exports.isNil = function isNil(x) {
return x == null;
};
/**
* test whether something is an object
* @method isObject
* @param {*} x - anything
* @returns {boolean} - true if the input is a object
* @public
* @example
* import {isObject} from 'f-utility'
* isObject(true) // false
* isObject(1) // false
* isObject(`a`) // false
* isObject([`a`]) // true
* isObject({}) // true
* isObject(null) // true
*/
var isObject = exports.isObject = isTypeof("object");
/**
* test whether something is an array
* @method isArray
* @param {*} x - anything
* @returns {boolean} - true if the input is an array
* @public
* @example
* import {isArray} from 'f-utility'
* isArray(true) // false
* isArray(1) // false
* isArray(`a`) // false
* isArray([`a`]) // true
* isArray({}) // false
* isArray(null) // false
* isArray(undefined) // false
*/
var isArray = exports.isArray = Array.isArray;
/**
* test whether something is a non-null object which isn't an array
* @method isDistinctObject
* @param {*} x - anything
* @returns {boolean} - true if the input is an object that isn't an array and isn't null
* @public
* @example
* import {isDistinctObject} from 'f-utility'
* isDistinctObject(true) // false
* isDistinctObject(1) // false
* isDistinctObject(`a`) // false
* isDistinctObject([`a`]) // false
* isDistinctObject({}) // true
* isDistinctObject(null) // false
* isDistinctObject(undefined) // false
*/
var isDistinctObject = exports.isDistinctObject = function isDistinctObject(x) {
return !isNil(x) && isObject(x) && !isArray(x);
};
var isPOJO = exports.isPOJO = isDistinctObject;
;