Global

Methods

camelCase(str) → {string|undefined}

Converts a string to camelCase.

Parameters:
Name Type Description
str string

The input string.

Source:
Returns:

The camelCased string or undefined if input is invalid.

Type
string | undefined
Example
camelCase("hello world"); // "helloWorld"

capitalize(str) → {string|undefined}

Capitalizes the first letter of a string.

Parameters:
Name Type Description
str string

The input string.

Source:
Returns:

The capitalized string, or undefined if input is invalid.

Type
string | undefined
Example
capitalize("hello world"); // "Hello world"

countOccurrences(str, sub) → {number|undefined}

Counts the occurrences of a substring within a string.

Parameters:
Name Type Description
str string

The main string.

sub string

The substring to count.

Source:
Returns:

The number of occurrences or undefiend if any or both inputs are not valid strings.

Type
number | undefined
Example
countOccurrences("hello hello", "hello"); // 2

deepClone(obj) → {Object|null}

Creates a deep clone of an object.

Parameters:
Name Type Description
obj Object

The object to clone.

Source:
Returns:

The deep-cloned object or null if the argument is not a valid object

Type
Object | null
Example
const original = { a: 1, b: { c: 2 } };
const clone = deepClone(original);
clone.b.c = 3;
console.log(original.b.c); // 2

diffInDays(date1, date2) → {number|undefined}

Calculates the difference in days between two dates.

Parameters:
Name Type Description
date1 Date

The first date.

date2 Date

The second date.

Source:
Returns:

The difference in days, or undefined if the inputs are invalid.

Type
number | undefined

diffInMonths(date1, date2) → {number|undefined}

Calculates the difference in months between two dates.

Parameters:
Name Type Description
date1 Date

The first date.

date2 Date

The second date.

Source:
Returns:

The difference in months, or undefined if the inputs are invalid.

Type
number | undefined

diffInYears(date1, date2) → {number|undefined}

Calculates the difference in years between two dates.

Parameters:
Name Type Description
date1 Date

The first date.

date2 Date

The second date.

Source:
Returns:

The difference in years, or undefined if the inputs are invalid.

Type
number | undefined

endsWith(str, suffix) → {boolean|undefined}

Checks if a string ends with a given substring.

Parameters:
Name Type Description
str string

The main string.

suffix string

The suffix to check.

Source:
Returns:

True if the string ends with the suffix, false otherwise and undefined if one or both argument inputs are not valid.

Type
boolean | undefined
Example
endsWith("hello world", "world"); // true

get(obj, path, defaultValueopt) → {*}

Retrieves the value at a given path within an object.

Parameters:
Name Type Attributes Description
obj Object

The object to query.

path string

The path of the property to get.

defaultValue * <optional>

The value returned if the path doesn't exist.

Source:
Returns:

The value at the specified path or the default value.

Type
*
Example
const obj = { a: { b: { c: 3 } } };
get(obj, 'a.b.c'); // 3
get(obj, 'a.b.d', 'default'); // 'default'

getDayOfTheWeek(date) → {string|undefined}

Gets the day of the week for a given date.

Parameters:
Name Type Description
date Date

The date to check.

Source:
Returns:

The name of the day (e.g., "Monday"), or undefined if the input is invalid.

Type
string | undefined

getRandomInt(min, max) → {number|NaN}

Generates a random integer within a specified range (inclusive)

Parameters:
Name Type Description
min number

The minimum value of the range.

max number

The maximum value of the range.

Source:
Returns:

A random integer between min and max (inclusive), or NaN if min or max are not valid numbers.

Type
number | NaN

hasKey(obj, key) → {boolean|null}

Checks if an object has a specific property as its own (not inherited).

Parameters:
Name Type Description
obj Object

The object to check.

key string

The property name to check for.

Source:
Returns:

True if the property exists, false otherwise, null if one or both arguments are not valid

Type
boolean | null
Example
hasKey({ a: 1, b: 2 }, 'b'); // true
hasKey({ a: 1, b: 2 }, 'c'); // false

isAnagram(str1, str2) → {boolean|undefined}

Checks if two strings are anagrams (contain the same characters in any order).

Parameters:
Name Type Description
str1 string

First string to check

str2 string

Second string to compare with

Source:
Returns:

True if the strings have the same characters, or false if otherwise and undefined if one or both input strings are not valid strings.

Type
boolean | undefined
Example
isAnagram("listen", "silent"); // true
isAnagram("hello", "world"); // false

isEmpty(obj) → {boolean|null}

Checks if an object is empty (has no enumerable properties).

Parameters:
Name Type Description
obj Object

The object to check.

Source:
Returns:

True if the object is empty, false otherwise, null if object is null or not an object

Type
boolean | null
Example
isEmpty({}); // true
isEmpty({ key: 'value' }); // false

isEven(number) → {boolean|undefined}

Checks if a number is even

Parameters:
Name Type Description
number number

The number to check.

Source:
Returns:

True if the number is even, false otherwise. Returns undefined if the input is not a valid number.

Type
boolean | undefined

isLeapYear(year) → {boolean|undefined}

Checks if a given year is a leap year.

Parameters:
Name Type Description
year number

The year to check.

Source:
Returns:

True if the year is a leap year, false otherwise, or undefined if the input is invalid.

Type
boolean | undefined

isOdd(number) → {boolean|undefined}

Checks if a number is odd

Parameters:
Name Type Description
number number

The number to check.

Source:
Returns:

True if the number is odd, false otherwise. Returns undefined if the input is not a valid number.

Type
boolean | undefined

kebabCase(str) → {string|undefined}

Converts a string to kebab-case.

Parameters:
Name Type Description
str string

The input string.

Source:
Returns:

The kebab-cased string or undefined if input is not a valid string.

Type
string | undefined
Example
kebabCase("hello world"); // "hello-world"

merge(target, source) → {Object|null}

Merges two objects, with properties from the second object overwriting those in the first.

Parameters:
Name Type Description
target Object

The target object to merge into.

source Object

The source object to merge from.

Source:
Returns:

The merged object, or null if one or both arguments are not valid objects.

Type
Object | null
Example
merge({ a: 1, b: 2 }, { b: 3, c: 4 }); // { a: 1, b: 3, c: 4 }

removeWhitespace(str) → {string|undefined}

Removes all whitespace from a string.

Parameters:
Name Type Description
str string

The input string.

Source:
Returns:

The string without whitespace or undefined if input is invalid.

Type
string | undefined
Example
removeWhitespace("  hello world  "); // "helloworld"

reverseString(str) → {string|undefined}

Reverses a string.

Parameters:
Name Type Description
str string

The input string.

Source:
Returns:

The reversed string or undefined if input is not a valid string.

Type
string | undefined
Example
reverseString("hello"); // "olleh"

roundTo(number, decimalPlaces) → {number|NaN}

Rounds a number to a specified number of decimal places

Parameters:
Name Type Description
number number

The number to round.

decimalPlaces number

The number of decimal places to round to. Defaults to 0.

Source:
Returns:

The rounded number.Returns NaN if the inputs are not valid numbers.

Type
number | NaN

set(obj, path, value) → {Object}

Sets the value at a given path within an object.

Parameters:
Name Type Description
obj Object

The object to modify.

path string

The path of the property to set.

value *

The value to set.

Source:
Returns:

The updated object.

Type
Object
Example
const obj = { a: { b: { c: 3 } } };
set(obj, 'a.b.c', 4);
console.log(obj.a.b.c); // 4
set(obj, 'a.b.d.e', 5);
console.log(obj.a.b.d.e); // 5

snakeCase(str) → {string|undefined}

Converts a string to snake_case.

Parameters:
Name Type Description
str string

The input string.

Source:
Returns:

The snake_cased string or undefined if input is not a valid string.

Type
string | undefined
Example
snakeCase("hello world"); // "hello_world"

startsWith(str, prefix) → {boolean}

Checks if a string starts with a given substring.

Parameters:
Name Type Description
str string

The main string.

prefix string

The prefix to check.

Source:
Returns:

True if the string starts with the prefix, false otherwise. Returns undefined if one or both inputs are not valid strings.

Type
boolean
Example
startsWith("hello world", "hello"); // true

sum(numbers) → {number|NaN}

Returns the sum of all numbers in an array

Parameters:
Name Type Description
numbers Array.<numbers>

An array of numbers.

Source:
Returns:

An integer value representing the sum of all numbers in the array, or NaN if not a valid array or if any element of the array is not a number.

Type
number | NaN

truncate(str, length) → {string|undefined}

Truncates a string to a specified length, adding "..." if truncated.

Parameters:
Name Type Description
str string

The input string.

length number

The maximum length.

Source:
Returns:

The truncated string, undefined if input is not a valid string or return the origin string if Length is not a positive number.

Type
string | undefined
Example
truncate("Hello world", 5); // "Hello..."