Lang methods
Explore the list of utility methods for working with data types and values.
This documentation provides an overview of the langUtils
methods, a collection of utility functions designed to work with various data types and values in JavaScript. langUtils
offers methods for casting, cloning, comparing, and transforming different types of data. Whether you need to convert values to different types, check data integrity, or perform comparisons, the langUtils
methods offer a versatile toolbox for handling common data-related tasks in your workflows.
langUtils
library uses Lodash's Lang methods. For full details of how to use these methods, refer to Lodash documentation.
Overview
The langUtils
library offers a diverse range of methods. Here's the list of some of the most common methods:
Type checking and comparison
isArray
: Checks if a value is an array.isBoolean
: Checks if a value is a boolean.isDate
: Checks if a value is a date.isEqual
: Performs a deep comparison between two values.isNull
: Checks if a value is null.isNumber
: Checks if a value is a number.isObject
: Checks if a value is an object.isString
: Checks if a value is a string.isSymbol
: Checks if a value is a symbol.
Value transformation
toArray
: Converts a value to an array.toNumber
: Converts a value to a number.toPlainObject
: Converts a value to a plain object.toString
: Converts a value to a string.
Object matching and validation
conformsTo
: Checks if an object conforms to a source object's properties.isMatch
: Checks if an object contains the properties of a source object.
Numeric comparison
eq
: Performs a loose equality comparison between two values.
Methods reference in langUtils library
langUtils.castArray(value)
Casts a value into an array if it's not already an array.
Parameters
value
(*): The value to cast.
Returns
- (Array): The casted array.
Example
const castedArray = langUtils.castArray('hello');
// Result: ['hello']
langUtils.clone(value)
Creates a shallow clone of a value.
Parameters
value
(*): The value to clone.
Returns
- (*): The cloned value.
Example
const originalObject = { a: 1, b: 2 };
const clonedObject = langUtils.clone(originalObject);
// Result: { a: 1, b: 2 }
langUtils.cloneDeep(value)
Creates a deep clone of a value.
Parameters
value
(*): The value to clone.
Returns
- (*): The deep cloned value.
Example
const originalObject = { a: 1, b: { c: 2 } };
const clonedObject = langUtils.cloneDeep(originalObject);
// Result: { a: 1, b: { c: 2 } }
langUtils.cloneDeepWith(value, customizer)
This method is like langUtils.cloneDeep except that it accepts a customizer which is invoked to produce the cloned value.
Parameters
value
(*): The value to clone.customizer
(Function): The customizer function.
Returns
- (*): The deep cloned value.
Example
const originalObject = { a: 1, b: { c: 2 } };
const clonedObject = langUtils.cloneDeepWith(originalObject, value => value);
// Result: { a: 1, b: { c: 2 } }
langUtils.cloneWith(value, customizer)
This method is like langUtils.clone except that it accepts a customizer which is invoked to produce the cloned value.
Parameters
value
(*): The value to clone.customizer
(Function): The customizer function.
Returns
- (*): The cloned value.
Example
const originalObject = { a: 1, b: 2 };
const clonedObject = langUtils.cloneWith(originalObject, value => value);
// Result: { a: 1, b: 2 }
langUtils.conformsTo(object, source)
Checks if an object conforms to a source object.
Parameters
object
(Object): The object to check.source
(Object): The source object.
Returns
- (boolean): true if the object conforms, false otherwise.
Example
const object = { a: 1, b: 2 };
const source = { b: val => val > 1 };
const conforms = langUtils.conformsTo(object, source);
// Result: true
langUtils.eq(value, other)
Performs a strict equality check between two values.
Parameters
value
(*): The first value.other
(*): The second value.
Returns
- (boolean): true if the values are strictly equal, false otherwise.
Example
const isEqual = langUtils.eq(5, 5);
// Result: true
langUtils.gt(value, other)
Checks if the first value is greater than the second value.
Parameters
value
(*): The first value.other
(*): The second value.
Returns
- (boolean): true if the first value is greater, false otherwise.
Example
const isGreater = langUtils.gt(10, 5);
// Result: true
langUtils.gte(value, other)
Checks if the first value is greater than or equal to the second value.
Parameters
value
(*): The first value.other
(*): The second value.
Returns
- (boolean): true if the first value is greater or equal, false otherwise.
Example
const isGreaterOrEqual = langUtils.gte(10, 10);
// Result: true
langUtils.isArguments(value)
Checks if a value is classified as an "arguments" object.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is an arguments object, false otherwise.
Example
const isArgs = langUtils.isArguments(function() { return arguments; }());
// Result: true
langUtils.isArray(value)
Checks if a value is an array.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is an array, false otherwise.
Example
const isArray = langUtils.isArray([1, 2, 3]);
// Result: true
langUtils.isArrayBuffer(value)
Checks if a value is classified as an ArrayBuffer object.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is an ArrayBuffer object, false otherwise.
Example
const isArrayBuffer = langUtils.isArrayBuffer(new ArrayBuffer(2));
// Result: true
langUtils.isArrayLike(value)
Checks if a value is array-like.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is array-like, false otherwise.
Example
const isArrayLike = langUtils.isArrayLike([1, 2, 3]);
// Result: true
langUtils.isArrayLikeObject(value)
Checks if a value is classified as an array-like object.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is an array-like object, false otherwise.
Example
const isArrayLikeObject = langUtils.isArrayLikeObject({ 'length': 3 });
// Result: true
langUtils.isBoolean(value)
Checks if a value is a boolean.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a boolean, false otherwise.
Example
const isBoolean = langUtils.isBoolean(true);
// Result: true
langUtils.isBuffer(value)
Checks if a value is a buffer.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a buffer, false otherwise.
Example
const isBuffer = langUtils.isBuffer(Buffer.from([1, 2, 3]));
// Result: true
langUtils.isDate(value)
Checks if a value is a date object.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a date object, false otherwise.
Example
const isDate = langUtils.isDate(new Date());
// Result: true
langUtils.isElement(value)
Checks if a value is a DOM element.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a DOM element, false otherwise.
Example
const isElement = langUtils.isElement(document.body);
// Result: true
langUtils.isEmpty(value)
Checks if a value is empty.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is empty, false otherwise.
Example
const isEmpty = langUtils.isEmpty([]);
// Result: true
langUtils.isEqual(value, other)
Performs a deep equality check between two values.
Parameters
value
(*): The first value.other
(*): The second value.
Returns
- (boolean): true if the values are deeply equal, false otherwise.
Example
const isEqual = langUtils.isEqual({ a: 1 }, { a: 1 });
// Result: true
langUtils.isEqualWith(value, other, customizer)
This method is like langUtils.isEqual except that it accepts a customizer which is invoked to compare values.
Parameters
value
(*): The first value.other
(*): The second value.customizer
(Function): The customizer function.
Returns
- (boolean): true if the values are equal as per the customizer, false otherwise.
Example
const isEqual = langUtils.isEqualWith(
{ a: 1, b: 2 },
{ a: 1, b: 3 },
(objValue, othValue) => objValue.a === othValue.a
);
// Result: true
langUtils.isError(value)
Checks if a value is an error object.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is an error object, false otherwise.
Example
const isError = langUtils.isError(new Error());
// Result: true
langUtils.isFinite(value)
Checks if a value is a finite number.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a finite number, false otherwise.
Example
const isFiniteValue = langUtils.isFinite(5);
// Result: true
langUtils.isFunction(value)
Checks if a value is a function.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a function, false otherwise.
Example
const isFunction = langUtils.isFunction(() => {});
// Result: true
langUtils.isInteger(value)
Checks if a value is an integer.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is an integer, false otherwise.
Example
const isInteger = langUtils.isInteger(5);
// Result: true
langUtils.isLength(value)
Checks if a value is a valid array-like length.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a valid length, false otherwise.
Example
const isLength = langUtils.isLength(3);
// Result: true
langUtils.isMap(value)
Checks if a value is a map.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a map, false otherwise.
Example
const isMap = langUtils.isMap(new Map());
// Result: true
langUtils.isMatch(object, source)
Checks if an object conforms to a source object by partial deep comparison.
Parameters
object
(Object): The object to check.source
(Object): The source object.
Returns
- (boolean): true if the object matches, false otherwise.
Example
const object = { a: 1, b: 2, c: 3 };
const source = { b: 2 };
const isMatch = langUtils.isMatch(object, source);
// Result: true
langUtils.isMatchWith(object, source, customizer)
This method is like langUtils.isMatch except that it accepts a customizer which is invoked to compare values.
Parameters
object
(Object): The object to check.source
(Object): The source object.customizer
(Function): The customizer function.
Returns
- (boolean): true if the object matches as per the customizer, false otherwise.
Example
const object = { a: 1, b: 2, c: 3 };
const source = { b: 2 };
const isMatch = langUtils.isMatchWith(object, source, (objValue, srcValue) => objValue === srcValue);
// Result: true
langUtils.isNaN(value)
Checks if a value is NaN.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is NaN, false otherwise.
Example
const isNaNValue = langUtils.isNaN(NaN);
// Result: true
langUtils.isNative(value)
Checks if a value is a native function.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a native function, false otherwise.
Example
const isNativeFunction = langUtils.isNative(Array.prototype.push);
// Result: true
langUtils.isNil(value)
Checks if a value is null or undefined.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is null or undefined, false otherwise.
Example
const isNilValue = langUtils.isNil(null);
// Result: true
langUtils.isNull(value)
Checks if a value is null.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is null, false otherwise.
Example
const isNullValue = langUtils.isNull(null);
// Result: true
langUtils.isNumber(value)
Checks if a value is a number.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a number, false otherwise.
Example
const isNumber = langUtils.isNumber(5);
// Result: true
langUtils.isObject(value)
Checks if a value is an object.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is an object, false otherwise.
Example
const isObject = langUtils.isObject({ a: 1 });
// Result: true
langUtils.isObjectLike(value)
Checks if a value is object-like (i.e., not null and an object type).
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is object-like, false otherwise.
Example
const isObjectLike = langUtils.isObjectLike({ a: 1 });
// Result: true
langUtils.isPlainObject(value)
Checks if a value is a plain object.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a plain object, false otherwise.
Example
const isPlainObject = langUtils.isPlainObject({ a: 1 });
// Result: true
langUtils.isRegExp(value)
Checks if a value is a regular expression.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a regular expression, false otherwise.
Example
const isRegExp = langUtils.isRegExp(/abc/);
// Result: true
langUtils.isSafeInteger(value)
Checks if a value is a safe integer.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a safe integer, false otherwise.
Example
const isSafeInteger = langUtils.isSafeInteger(9007199254740991);
// Result: true
langUtils.isSet(value)
Checks if a value is a set.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a set, false otherwise.
Example
const isSet = langUtils.isSet(new Set());
// Result: true
langUtils.isString(value)
Checks if a value is a string.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a string, false otherwise.
Example
const isString = langUtils.isString('hello');
// Result: true
langUtils.isSymbol(value)
Checks if a value is a symbol.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a symbol, false otherwise.
Example
const isSymbol = langUtils.isSymbol(Symbol('test'));
// Result: true
langUtils.isTypedArray(value)
Checks if a value is a typed array.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a typed array, false otherwise.
Example
const isTypedArray = langUtils.isTypedArray(new Int8Array());
// Result: true
langUtils.isUndefined(value)
Checks if a value is undefined.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is undefined, false otherwise.
Example
const isUndefined = langUtils.isUndefined(undefined);
// Result: true
langUtils.isWeakMap(value)
Checks if a value is a weak map.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a weak map, false otherwise.
Example
const isWeakMap = langUtils.isWeakMap(new WeakMap());
// Result: true
langUtils.isWeakSet(value)
Checks if a value is a weak set.
Parameters
value
(*): The value to check.
Returns
- (boolean): true if the value is a weak set, false otherwise.
Example
const isWeakSet = langUtils.isWeakSet(new WeakSet());
// Result: true
langUtils.lt(value, other)
Checks if the first value is less than the second value.
Parameters
value
(*): The first value.other
(*): The second value.
Returns
- (boolean): true if the first value is less, false otherwise.
Example
const isLess = langUtils.lt(5, 10);
// Result: true
langUtils.lte(value, other)
Checks if the first value is less than or equal to the second value.
Parameters
value
(*): The first value.other
(*): The second value.
Returns
- (boolean): true if the first value is less or equal, false otherwise.
Example
const isLessOrEqual = langUtils.lte(5, 5);
// Result: true
langUtils.toArray(value)
Converts a value to an array.
Parameters
value
(*): The value to convert.
Returns
- (Array): The converted array.
Example
const arrayValue = langUtils.toArray({ a: 1, b: 2 });
// Result: [{ a: 1, b: 2 }]
langUtils.toFinite(value)
Converts a value to a finite number.
Parameters
value
(*): The value to convert.
Returns
- (number): The converted finite number.
Example
const finiteValue = langUtils.toFinite(Infinity);
// Result: 1.7976931348623157e+308
langUtils.toInteger(value)
Converts a value to an integer.
Parameters
value
(*): The value to convert.
Returns
- (number): The converted integer.
Example
const integerValue = langUtils.toInteger(5.5);
// Result: 5
langUtils.toLength(value)
Converts a value to a valid array-like length.
Parameters
value
(*): The value to convert.
Returns
- (number): The converted length.
Example
const lengthValue = langUtils.toLength('5');
// Result: 5
langUtils.toNumber(value)
Converts a value to a number.
Parameters
value
(*): The value to convert.
Returns
- (number): The converted number.
Example
const numberValue = langUtils.toNumber('5.5');
// Result: 5.5
langUtils.toPlainObject(value)
Converts a value to a plain object. If the value is already an object, it returns a shallow clone of the value.
Parameters
value
(*): The value to convert.
Returns
- (Object): The converted plain object.
Example
const plainObjectValue = langUtils.toPlainObject({ a: 1 });
// Result: { a: 1 }
langUtils.toSafeInteger(value)
Converts a value to a safe integer.
Parameters
value
(*): The value to convert.
Returns
- (number): The converted safe integer.
Example
const safeIntegerValue = langUtils.toSafeInteger(1.5);
// Result: 1
langUtils.toString(value)
Converts a value to a string.
Parameters
value
(*): The value to convert.
Returns
- (string): The converted string.
Example
const stringValue = langUtils.toString(123);
// Result: '123'