- Spec files
npm-lodash
Describes: pkg:npm/lodash@4.6.x
- Description
- A modern JavaScript utility library delivering modularity, performance & extras
- Author
- tessl
- Last updated
lang.md docs/
1# Type Checking23Comprehensive type checking utilities for JavaScript values and objects. These methods provide reliable type detection across different JavaScript environments.45## Capabilities67### Basic Type Checking89Check for fundamental JavaScript types.1011```javascript { .api }12/**13* Checks if `value` is classified as an `Array` object.14*15* @param {*} value The value to check16* @returns {boolean} Returns `true` if `value` is an array, else `false`17*/18function isArray(value: any): boolean;1920/**21* Checks if `value` is classified as a boolean primitive or object.22*23* @param {*} value The value to check24* @returns {boolean} Returns `true` if `value` is a boolean, else `false`25*/26function isBoolean(value: any): boolean;2728/**29* Checks if `value` is classified as a `Function` object.30*31* @param {*} value The value to check32* @returns {boolean} Returns `true` if `value` is a function, else `false`33*/34function isFunction(value: any): boolean;3536/**37* Checks if `value` is classified as a `Number` primitive or object.38*39* @param {*} value The value to check40* @returns {boolean} Returns `true` if `value` is a number, else `false`41*/42function isNumber(value: any): boolean;4344/**45* Checks if `value` is the language type `Object`.46*47* @param {*} value The value to check48* @returns {boolean} Returns `true` if `value` is an object, else `false`49*/50function isObject(value: any): boolean;5152/**53* Checks if `value` is classified as a `String` primitive or object.54*55* @param {*} value The value to check56* @returns {boolean} Returns `true` if `value` is a string, else `false`57*/58function isString(value: any): boolean;5960/**61* Checks if `value` is classified as a `Symbol` primitive or object.62*63* @param {*} value The value to check64* @returns {boolean} Returns `true` if `value` is a symbol, else `false`65*/66function isSymbol(value: any): boolean;67```6869**Usage Examples:**7071```javascript72import { isArray, isString, isNumber, isFunction } from "lodash";7374isArray([1, 2, 3]); // true75isArray('abc'); // false7677isString('abc'); // true78isString(1); // false7980isNumber(3); // true81isNumber('3'); // false8283isFunction(function() {}); // true84isFunction({}); // false85```8687### Null and Undefined Checking8889Check for null, undefined, and related values.9091```javascript { .api }92/**93* Checks if `value` is `null` or `undefined`.94*95* @param {*} value The value to check96* @returns {boolean} Returns `true` if `value` is nullish, else `false`97*/98function isNil(value: any): boolean;99100/**101* Checks if `value` is `null`.102*103* @param {*} value The value to check104* @returns {boolean} Returns `true` if `value` is `null`, else `false`105*/106function isNull(value: any): boolean;107108/**109* Checks if `value` is `undefined`.110*111* @param {*} value The value to check112* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`113*/114function isUndefined(value: any): boolean;115```116117### Number Type Checking118119Check for specific number types and properties.120121```javascript { .api }122/**123* Checks if `value` is a finite primitive number.124*125* @param {*} value The value to check126* @returns {boolean} Returns `true` if `value` is a finite number, else `false`127*/128function isFinite(value: any): boolean;129130/**131* Checks if `value` is an integer.132*133* @param {*} value The value to check134* @returns {boolean} Returns `true` if `value` is an integer, else `false`135*/136function isInteger(value: any): boolean;137138/**139* Checks if `value` is `NaN`.140*141* @param {*} value The value to check142* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`143*/144function isNaN(value: any): boolean;145146/**147* Checks if `value` is a safe integer.148*149* @param {*} value The value to check150* @returns {boolean} Returns `true` if `value` is a safe integer, else `false`151*/152function isSafeInteger(value: any): boolean;153```154155### Object Type Checking156157Check for specific object types.158159```javascript { .api }160/**161* Checks if `value` is object-like. A value is object-like if it's not `null`162* and has a `typeof` result of "object".163*164* @param {*} value The value to check165* @returns {boolean} Returns `true` if `value` is object-like, else `false`166*/167function isObjectLike(value: any): boolean;168169/**170* Checks if `value` is a plain object, that is, an object created by the171* `Object` constructor or one with a `[[Prototype]]` of `null`.172*173* @param {*} value The value to check174* @returns {boolean} Returns `true` if `value` is a plain object, else `false`175*/176function isPlainObject(value: any): boolean;177178/**179* Checks if `value` is classified as a `Date` object.180*181* @param {*} value The value to check182* @returns {boolean} Returns `true` if `value` is a date object, else `false`183*/184function isDate(value: any): boolean;185186/**187* Checks if `value` is classified as a `RegExp` object.188*189* @param {*} value The value to check190* @returns {boolean} Returns `true` if `value` is a regexp, else `false`191*/192function isRegExp(value: any): boolean;193194/**195* Checks if `value` is classified as an `Error`, `EvalError`, `RangeError`,196* `ReferenceError`, `SyntaxError`, `TypeError`, or `URIError` object.197*198* @param {*} value The value to check199* @returns {boolean} Returns `true` if `value` is an error object, else `false`200*/201function isError(value: any): boolean;202```203204### Collection Type Checking205206Check for array-like and collection types.207208```javascript { .api }209/**210* Checks if `value` is array-like. A value is considered array-like if it's211* not a function and has a `value.length` that's an integer greater than or212* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.213*214* @param {*} value The value to check215* @returns {boolean} Returns `true` if `value` is array-like, else `false`216*/217function isArrayLike(value: any): boolean;218219/**220* This method is like `isArrayLike` except that it also checks if `value`221* is an object.222*223* @param {*} value The value to check224* @returns {boolean} Returns `true` if `value` is an array-like object, else `false`225*/226function isArrayLikeObject(value: any): boolean;227228/**229* Checks if `value` is likely an `arguments` object.230*231* @param {*} value The value to check232* @returns {boolean} Returns `true` if `value` is an `arguments` object, else `false`233*/234function isArguments(value: any): boolean;235236/**237* Checks if `value` is a valid array-like length.238*239* @param {*} value The value to check240* @returns {boolean} Returns `true` if `value` is a valid length, else `false`241*/242function isLength(value: any): boolean;243```244245### Built-in Type Checking246247Check for built-in JavaScript objects.248249```javascript { .api }250/**251* Checks if `value` is classified as an `ArrayBuffer` object.252*253* @param {*} value The value to check254* @returns {boolean} Returns `true` if `value` is an array buffer, else `false`255*/256function isArrayBuffer(value: any): boolean;257258/**259* Checks if `value` is a buffer.260*261* @param {*} value The value to check262* @returns {boolean} Returns `true` if `value` is a buffer, else `false`263*/264function isBuffer(value: any): boolean;265266/**267* Checks if `value` is classified as a `Map` object.268*269* @param {*} value The value to check270* @returns {boolean} Returns `true` if `value` is a map, else `false`271*/272function isMap(value: any): boolean;273274/**275* Checks if `value` is classified as a `Set` object.276*277* @param {*} value The value to check278* @returns {boolean} Returns `true` if `value` is a set, else `false`279*/280function isSet(value: any): boolean;281282/**283* Checks if `value` is classified as a `WeakMap` object.284*285* @param {*} value The value to check286* @returns {boolean} Returns `true` if `value` is a weak map, else `false`287*/288function isWeakMap(value: any): boolean;289290/**291* Checks if `value` is classified as a `WeakSet` object.292*293* @param {*} value The value to check294* @returns {boolean} Returns `true` if `value` is a weak set, else `false`295*/296function isWeakSet(value: any): boolean;297298/**299* Checks if `value` is classified as a typed array.300*301* @param {*} value The value to check302* @returns {boolean} Returns `true` if `value` is a typed array, else `false`303*/304function isTypedArray(value: any): boolean;305```306307### DOM Type Checking308309Check for DOM-related objects.310311```javascript { .api }312/**313* Checks if `value` is likely a DOM element.314*315* @param {*} value The value to check316* @returns {boolean} Returns `true` if `value` is a DOM element, else `false`317*/318function isElement(value: any): boolean;319```320321### Emptiness Checking322323Check if values are empty.324325```javascript { .api }326/**327* Checks if `value` is an empty object, collection, map, or set.328* Objects are considered empty if they have no own enumerable string keyed properties.329* Array-like values such as `arguments` objects, arrays, buffers, strings, or330* jQuery-like collections are considered empty if they have a `length` of `0`.331* Similarly, maps and sets are considered empty if they have a `size` of `0`.332*333* @param {*} value The value to check334* @returns {boolean} Returns `true` if `value` is empty, else `false`335*/336function isEmpty(value: any): boolean;337```338339**Usage Examples:**340341```javascript342import { isEmpty } from "lodash";343344isEmpty(null); // true345isEmpty(true); // true346isEmpty(1); // true347isEmpty([1, 2, 3]); // false348isEmpty({ 'a': 1 }); // false349isEmpty('abc'); // false350isEmpty(''); // true351```352353### Equality Checking354355Check for equality between values.356357```javascript { .api }358/**359* Performs a SameValueZero comparison between two values to determine if360* they are equivalent.361*362* @param {*} value The value to compare363* @param {*} other The other value to compare364* @returns {boolean} Returns `true` if the values are equivalent, else `false`365*/366function eq(value: any, other: any): boolean;367368/**369* Performs a deep comparison between two values to determine if they are370* equivalent.371*372* @param {*} value The value to compare373* @param {*} other The other value to compare374* @returns {boolean} Returns `true` if the values are equivalent, else `false`375*/376function isEqual(value: any, other: any): boolean;377378/**379* This method is like `isEqual` except that it accepts `customizer` which380* is invoked to compare values.381*382* @param {*} value The value to compare383* @param {*} other The other value to compare384* @param {Function} [customizer] The function to customize comparisons385* @returns {boolean} Returns `true` if the values are equivalent, else `false`386*/387function isEqualWith(value: any, other: any, customizer?: Function): boolean;388```389390### Pattern Matching391392Check if objects match patterns.393394```javascript { .api }395/**396* Performs a partial deep comparison between `object` and `source` to397* determine if `object` contains equivalent property values.398*399* @param {Object} object The object to inspect400* @param {Object} source The object of property values to match401* @returns {boolean} Returns `true` if `object` is a match, else `false`402*/403function isMatch(object: Object, source: Object): boolean;404405/**406* This method is like `isMatch` except that it accepts `customizer` which407* is invoked to compare values.408*409* @param {Object} object The object to inspect410* @param {Object} source The object of property values to match411* @param {Function} [customizer] The function to customize comparisons412* @returns {boolean} Returns `true` if `object` is a match, else `false`413*/414function isMatchWith(object: Object, source: Object, customizer?: Function): boolean;415```416417### Value Conversion418419Convert values to specific types.420421```javascript { .api }422/**423* Converts `value` to an array.424*425* @param {*} value The value to convert426* @returns {Array} Returns the converted array427*/428function toArray(value: any): Array;429430/**431* Converts `value` to an integer.432*433* @param {*} value The value to convert434* @returns {number} Returns the converted integer435*/436function toInteger(value: any): number;437438/**439* Converts `value` to an integer suitable for use as the length of an440* array-like object.441*442* @param {*} value The value to convert443* @returns {number} Returns the converted integer444*/445function toLength(value: any): number;446447/**448* Converts `value` to a number.449*450* @param {*} value The value to process451* @returns {number} Returns the number452*/453function toNumber(value: any): number;454455/**456* Converts `value` to a safe integer.457*458* @param {*} value The value to convert459* @returns {number} Returns the converted integer460*/461function toSafeInteger(value: any): number;462463/**464* Converts `value` to a string. An empty string is returned for `null`465* and `undefined` values.466*467* @param {*} value The value to convert468* @returns {string} Returns the converted string469*/470function toString(value: any): string;471472/**473* Converts `value` to a plain object flattening inherited enumerable string474* keyed properties of `value` to own properties of the plain object.475*476* @param {*} value The value to convert477* @returns {Object} Returns the converted plain object478*/479function toPlainObject(value: any): Object;480```481482### Cloning483484Create copies of values.485486```javascript { .api }487/**488* Creates a shallow clone of `value`.489*490* @param {*} value The value to clone491* @returns {*} Returns the cloned value492*/493function clone(value: any): any;494495/**496* This method is like `clone` except that it accepts `customizer` which497* is invoked to produce the cloned value.498*499* @param {*} value The value to clone500* @param {Function} [customizer] The function to customize cloning501* @returns {*} Returns the cloned value502*/503function cloneWith(value: any, customizer?: Function): any;504505/**506* This method is like `clone` except that it recursively clones `value`.507*508* @param {*} value The value to recursively clone509* @returns {*} Returns the deep cloned value510*/511function cloneDeep(value: any): any;512513/**514* This method is like `cloneWith` except that it recursively clones `value`.515*516* @param {*} value The value to recursively clone517* @param {Function} [customizer] The function to customize cloning518* @returns {*} Returns the deep cloned value519*/520function cloneDeepWith(value: any, customizer?: Function): any;521```522523### Comparison524525Compare values numerically.526527```javascript { .api }528/**529* Checks if `value` is greater than `other`.530*531* @param {*} value The value to compare532* @param {*} other The other value to compare533* @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`534*/535function gt(value: any, other: any): boolean;536537/**538* Checks if `value` is greater than or equal to `other`.539*540* @param {*} value The value to compare541* @param {*} other The other value to compare542* @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`543*/544function gte(value: any, other: any): boolean;545546/**547* Checks if `value` is less than `other`.548*549* @param {*} value The value to compare550* @param {*} other The other value to compare551* @returns {boolean} Returns `true` if `value` is less than `other`, else `false`552*/553function lt(value: any, other: any): boolean;554555/**556* Checks if `value` is less than or equal to `other`.557*558* @param {*} value The value to compare559* @param {*} other The other value to compare560* @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`561*/562function lte(value: any, other: any): boolean;563```564565### Native Function Checking566567Check for native JavaScript functions.568569```javascript { .api }570/**571* Checks if `value` is a pristine native function.572*573* @param {*} value The value to check574* @returns {boolean} Returns `true` if `value` is a native function, else `false`575*/576function isNative(value: any): boolean;577```578579### Array Casting580581Cast values as arrays.582583```javascript { .api }584/**585* Casts `value` as an array if it's not one.586*587* @param {*} value The value to inspect588* @returns {Array} Returns the cast array589*/590function castArray(value: any): Array;591```