npm-lodash

Description
A modern JavaScript utility library delivering modularity, performance & extras
Author
tessl
Last updated

How to use

npx @tessl/cli registry install tessl/npm-lodash@4.6.0

lang.md docs/

1
# Type Checking
2
3
Comprehensive type checking utilities for JavaScript values and objects. These methods provide reliable type detection across different JavaScript environments.
4
5
## Capabilities
6
7
### Basic Type Checking
8
9
Check for fundamental JavaScript types.
10
11
```javascript { .api }
12
/**
13
* Checks if `value` is classified as an `Array` object.
14
*
15
* @param {*} value The value to check
16
* @returns {boolean} Returns `true` if `value` is an array, else `false`
17
*/
18
function isArray(value: any): boolean;
19
20
/**
21
* Checks if `value` is classified as a boolean primitive or object.
22
*
23
* @param {*} value The value to check
24
* @returns {boolean} Returns `true` if `value` is a boolean, else `false`
25
*/
26
function isBoolean(value: any): boolean;
27
28
/**
29
* Checks if `value` is classified as a `Function` object.
30
*
31
* @param {*} value The value to check
32
* @returns {boolean} Returns `true` if `value` is a function, else `false`
33
*/
34
function isFunction(value: any): boolean;
35
36
/**
37
* Checks if `value` is classified as a `Number` primitive or object.
38
*
39
* @param {*} value The value to check
40
* @returns {boolean} Returns `true` if `value` is a number, else `false`
41
*/
42
function isNumber(value: any): boolean;
43
44
/**
45
* Checks if `value` is the language type `Object`.
46
*
47
* @param {*} value The value to check
48
* @returns {boolean} Returns `true` if `value` is an object, else `false`
49
*/
50
function isObject(value: any): boolean;
51
52
/**
53
* Checks if `value` is classified as a `String` primitive or object.
54
*
55
* @param {*} value The value to check
56
* @returns {boolean} Returns `true` if `value` is a string, else `false`
57
*/
58
function isString(value: any): boolean;
59
60
/**
61
* Checks if `value` is classified as a `Symbol` primitive or object.
62
*
63
* @param {*} value The value to check
64
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`
65
*/
66
function isSymbol(value: any): boolean;
67
```
68
69
**Usage Examples:**
70
71
```javascript
72
import { isArray, isString, isNumber, isFunction } from "lodash";
73
74
isArray([1, 2, 3]); // true
75
isArray('abc'); // false
76
77
isString('abc'); // true
78
isString(1); // false
79
80
isNumber(3); // true
81
isNumber('3'); // false
82
83
isFunction(function() {}); // true
84
isFunction({}); // false
85
```
86
87
### Null and Undefined Checking
88
89
Check for null, undefined, and related values.
90
91
```javascript { .api }
92
/**
93
* Checks if `value` is `null` or `undefined`.
94
*
95
* @param {*} value The value to check
96
* @returns {boolean} Returns `true` if `value` is nullish, else `false`
97
*/
98
function isNil(value: any): boolean;
99
100
/**
101
* Checks if `value` is `null`.
102
*
103
* @param {*} value The value to check
104
* @returns {boolean} Returns `true` if `value` is `null`, else `false`
105
*/
106
function isNull(value: any): boolean;
107
108
/**
109
* Checks if `value` is `undefined`.
110
*
111
* @param {*} value The value to check
112
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`
113
*/
114
function isUndefined(value: any): boolean;
115
```
116
117
### Number Type Checking
118
119
Check for specific number types and properties.
120
121
```javascript { .api }
122
/**
123
* Checks if `value` is a finite primitive number.
124
*
125
* @param {*} value The value to check
126
* @returns {boolean} Returns `true` if `value` is a finite number, else `false`
127
*/
128
function isFinite(value: any): boolean;
129
130
/**
131
* Checks if `value` is an integer.
132
*
133
* @param {*} value The value to check
134
* @returns {boolean} Returns `true` if `value` is an integer, else `false`
135
*/
136
function isInteger(value: any): boolean;
137
138
/**
139
* Checks if `value` is `NaN`.
140
*
141
* @param {*} value The value to check
142
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`
143
*/
144
function isNaN(value: any): boolean;
145
146
/**
147
* Checks if `value` is a safe integer.
148
*
149
* @param {*} value The value to check
150
* @returns {boolean} Returns `true` if `value` is a safe integer, else `false`
151
*/
152
function isSafeInteger(value: any): boolean;
153
```
154
155
### Object Type Checking
156
157
Check for specific object types.
158
159
```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 check
165
* @returns {boolean} Returns `true` if `value` is object-like, else `false`
166
*/
167
function isObjectLike(value: any): boolean;
168
169
/**
170
* Checks if `value` is a plain object, that is, an object created by the
171
* `Object` constructor or one with a `[[Prototype]]` of `null`.
172
*
173
* @param {*} value The value to check
174
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`
175
*/
176
function isPlainObject(value: any): boolean;
177
178
/**
179
* Checks if `value` is classified as a `Date` object.
180
*
181
* @param {*} value The value to check
182
* @returns {boolean} Returns `true` if `value` is a date object, else `false`
183
*/
184
function isDate(value: any): boolean;
185
186
/**
187
* Checks if `value` is classified as a `RegExp` object.
188
*
189
* @param {*} value The value to check
190
* @returns {boolean} Returns `true` if `value` is a regexp, else `false`
191
*/
192
function isRegExp(value: any): boolean;
193
194
/**
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 check
199
* @returns {boolean} Returns `true` if `value` is an error object, else `false`
200
*/
201
function isError(value: any): boolean;
202
```
203
204
### Collection Type Checking
205
206
Check for array-like and collection types.
207
208
```javascript { .api }
209
/**
210
* Checks if `value` is array-like. A value is considered array-like if it's
211
* not a function and has a `value.length` that's an integer greater than or
212
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
213
*
214
* @param {*} value The value to check
215
* @returns {boolean} Returns `true` if `value` is array-like, else `false`
216
*/
217
function isArrayLike(value: any): boolean;
218
219
/**
220
* This method is like `isArrayLike` except that it also checks if `value`
221
* is an object.
222
*
223
* @param {*} value The value to check
224
* @returns {boolean} Returns `true` if `value` is an array-like object, else `false`
225
*/
226
function isArrayLikeObject(value: any): boolean;
227
228
/**
229
* Checks if `value` is likely an `arguments` object.
230
*
231
* @param {*} value The value to check
232
* @returns {boolean} Returns `true` if `value` is an `arguments` object, else `false`
233
*/
234
function isArguments(value: any): boolean;
235
236
/**
237
* Checks if `value` is a valid array-like length.
238
*
239
* @param {*} value The value to check
240
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`
241
*/
242
function isLength(value: any): boolean;
243
```
244
245
### Built-in Type Checking
246
247
Check for built-in JavaScript objects.
248
249
```javascript { .api }
250
/**
251
* Checks if `value` is classified as an `ArrayBuffer` object.
252
*
253
* @param {*} value The value to check
254
* @returns {boolean} Returns `true` if `value` is an array buffer, else `false`
255
*/
256
function isArrayBuffer(value: any): boolean;
257
258
/**
259
* Checks if `value` is a buffer.
260
*
261
* @param {*} value The value to check
262
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`
263
*/
264
function isBuffer(value: any): boolean;
265
266
/**
267
* Checks if `value` is classified as a `Map` object.
268
*
269
* @param {*} value The value to check
270
* @returns {boolean} Returns `true` if `value` is a map, else `false`
271
*/
272
function isMap(value: any): boolean;
273
274
/**
275
* Checks if `value` is classified as a `Set` object.
276
*
277
* @param {*} value The value to check
278
* @returns {boolean} Returns `true` if `value` is a set, else `false`
279
*/
280
function isSet(value: any): boolean;
281
282
/**
283
* Checks if `value` is classified as a `WeakMap` object.
284
*
285
* @param {*} value The value to check
286
* @returns {boolean} Returns `true` if `value` is a weak map, else `false`
287
*/
288
function isWeakMap(value: any): boolean;
289
290
/**
291
* Checks if `value` is classified as a `WeakSet` object.
292
*
293
* @param {*} value The value to check
294
* @returns {boolean} Returns `true` if `value` is a weak set, else `false`
295
*/
296
function isWeakSet(value: any): boolean;
297
298
/**
299
* Checks if `value` is classified as a typed array.
300
*
301
* @param {*} value The value to check
302
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`
303
*/
304
function isTypedArray(value: any): boolean;
305
```
306
307
### DOM Type Checking
308
309
Check for DOM-related objects.
310
311
```javascript { .api }
312
/**
313
* Checks if `value` is likely a DOM element.
314
*
315
* @param {*} value The value to check
316
* @returns {boolean} Returns `true` if `value` is a DOM element, else `false`
317
*/
318
function isElement(value: any): boolean;
319
```
320
321
### Emptiness Checking
322
323
Check if values are empty.
324
325
```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, or
330
* 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 check
334
* @returns {boolean} Returns `true` if `value` is empty, else `false`
335
*/
336
function isEmpty(value: any): boolean;
337
```
338
339
**Usage Examples:**
340
341
```javascript
342
import { isEmpty } from "lodash";
343
344
isEmpty(null); // true
345
isEmpty(true); // true
346
isEmpty(1); // true
347
isEmpty([1, 2, 3]); // false
348
isEmpty({ 'a': 1 }); // false
349
isEmpty('abc'); // false
350
isEmpty(''); // true
351
```
352
353
### Equality Checking
354
355
Check for equality between values.
356
357
```javascript { .api }
358
/**
359
* Performs a SameValueZero comparison between two values to determine if
360
* they are equivalent.
361
*
362
* @param {*} value The value to compare
363
* @param {*} other The other value to compare
364
* @returns {boolean} Returns `true` if the values are equivalent, else `false`
365
*/
366
function eq(value: any, other: any): boolean;
367
368
/**
369
* Performs a deep comparison between two values to determine if they are
370
* equivalent.
371
*
372
* @param {*} value The value to compare
373
* @param {*} other The other value to compare
374
* @returns {boolean} Returns `true` if the values are equivalent, else `false`
375
*/
376
function isEqual(value: any, other: any): boolean;
377
378
/**
379
* This method is like `isEqual` except that it accepts `customizer` which
380
* is invoked to compare values.
381
*
382
* @param {*} value The value to compare
383
* @param {*} other The other value to compare
384
* @param {Function} [customizer] The function to customize comparisons
385
* @returns {boolean} Returns `true` if the values are equivalent, else `false`
386
*/
387
function isEqualWith(value: any, other: any, customizer?: Function): boolean;
388
```
389
390
### Pattern Matching
391
392
Check if objects match patterns.
393
394
```javascript { .api }
395
/**
396
* Performs a partial deep comparison between `object` and `source` to
397
* determine if `object` contains equivalent property values.
398
*
399
* @param {Object} object The object to inspect
400
* @param {Object} source The object of property values to match
401
* @returns {boolean} Returns `true` if `object` is a match, else `false`
402
*/
403
function isMatch(object: Object, source: Object): boolean;
404
405
/**
406
* This method is like `isMatch` except that it accepts `customizer` which
407
* is invoked to compare values.
408
*
409
* @param {Object} object The object to inspect
410
* @param {Object} source The object of property values to match
411
* @param {Function} [customizer] The function to customize comparisons
412
* @returns {boolean} Returns `true` if `object` is a match, else `false`
413
*/
414
function isMatchWith(object: Object, source: Object, customizer?: Function): boolean;
415
```
416
417
### Value Conversion
418
419
Convert values to specific types.
420
421
```javascript { .api }
422
/**
423
* Converts `value` to an array.
424
*
425
* @param {*} value The value to convert
426
* @returns {Array} Returns the converted array
427
*/
428
function toArray(value: any): Array;
429
430
/**
431
* Converts `value` to an integer.
432
*
433
* @param {*} value The value to convert
434
* @returns {number} Returns the converted integer
435
*/
436
function toInteger(value: any): number;
437
438
/**
439
* Converts `value` to an integer suitable for use as the length of an
440
* array-like object.
441
*
442
* @param {*} value The value to convert
443
* @returns {number} Returns the converted integer
444
*/
445
function toLength(value: any): number;
446
447
/**
448
* Converts `value` to a number.
449
*
450
* @param {*} value The value to process
451
* @returns {number} Returns the number
452
*/
453
function toNumber(value: any): number;
454
455
/**
456
* Converts `value` to a safe integer.
457
*
458
* @param {*} value The value to convert
459
* @returns {number} Returns the converted integer
460
*/
461
function toSafeInteger(value: any): number;
462
463
/**
464
* Converts `value` to a string. An empty string is returned for `null`
465
* and `undefined` values.
466
*
467
* @param {*} value The value to convert
468
* @returns {string} Returns the converted string
469
*/
470
function toString(value: any): string;
471
472
/**
473
* Converts `value` to a plain object flattening inherited enumerable string
474
* keyed properties of `value` to own properties of the plain object.
475
*
476
* @param {*} value The value to convert
477
* @returns {Object} Returns the converted plain object
478
*/
479
function toPlainObject(value: any): Object;
480
```
481
482
### Cloning
483
484
Create copies of values.
485
486
```javascript { .api }
487
/**
488
* Creates a shallow clone of `value`.
489
*
490
* @param {*} value The value to clone
491
* @returns {*} Returns the cloned value
492
*/
493
function clone(value: any): any;
494
495
/**
496
* This method is like `clone` except that it accepts `customizer` which
497
* is invoked to produce the cloned value.
498
*
499
* @param {*} value The value to clone
500
* @param {Function} [customizer] The function to customize cloning
501
* @returns {*} Returns the cloned value
502
*/
503
function cloneWith(value: any, customizer?: Function): any;
504
505
/**
506
* This method is like `clone` except that it recursively clones `value`.
507
*
508
* @param {*} value The value to recursively clone
509
* @returns {*} Returns the deep cloned value
510
*/
511
function cloneDeep(value: any): any;
512
513
/**
514
* This method is like `cloneWith` except that it recursively clones `value`.
515
*
516
* @param {*} value The value to recursively clone
517
* @param {Function} [customizer] The function to customize cloning
518
* @returns {*} Returns the deep cloned value
519
*/
520
function cloneDeepWith(value: any, customizer?: Function): any;
521
```
522
523
### Comparison
524
525
Compare values numerically.
526
527
```javascript { .api }
528
/**
529
* Checks if `value` is greater than `other`.
530
*
531
* @param {*} value The value to compare
532
* @param {*} other The other value to compare
533
* @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`
534
*/
535
function gt(value: any, other: any): boolean;
536
537
/**
538
* Checks if `value` is greater than or equal to `other`.
539
*
540
* @param {*} value The value to compare
541
* @param {*} other The other value to compare
542
* @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`
543
*/
544
function gte(value: any, other: any): boolean;
545
546
/**
547
* Checks if `value` is less than `other`.
548
*
549
* @param {*} value The value to compare
550
* @param {*} other The other value to compare
551
* @returns {boolean} Returns `true` if `value` is less than `other`, else `false`
552
*/
553
function lt(value: any, other: any): boolean;
554
555
/**
556
* Checks if `value` is less than or equal to `other`.
557
*
558
* @param {*} value The value to compare
559
* @param {*} other The other value to compare
560
* @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`
561
*/
562
function lte(value: any, other: any): boolean;
563
```
564
565
### Native Function Checking
566
567
Check for native JavaScript functions.
568
569
```javascript { .api }
570
/**
571
* Checks if `value` is a pristine native function.
572
*
573
* @param {*} value The value to check
574
* @returns {boolean} Returns `true` if `value` is a native function, else `false`
575
*/
576
function isNative(value: any): boolean;
577
```
578
579
### Array Casting
580
581
Cast values as arrays.
582
583
```javascript { .api }
584
/**
585
* Casts `value` as an array if it's not one.
586
*
587
* @param {*} value The value to inspect
588
* @returns {Array} Returns the cast array
589
*/
590
function castArray(value: any): Array;
591
```