extend-core
v1.0.0
Published
Extend Core is a TypeScript library that provides a collection of utility functions to extend and enhance the functionality of JavaScript's core objects, such as Array, String, Object, Date, Number, JSON, File, Buffer, Function, and Promise. It offers a w
Maintainers
Readme
Table of Contents
Installation
via npm
npm install --save extend-corevia yarn
yarn add extend-coreUsage
Simply import the library and start using the extended methods:
/* for load all prototypes */
import 'extend-core';
/* for load only array prototypes */
import 'extend-core/array';
/* for load only array .pull prototype */
import 'extend-core/array/pull';
// Array methods
const numbers = [1, 2, 3, 4, 5];
console.log(numbers.average()); // 3
console.log(numbers.chunk(2)); // [[1, 2], [3, 4], [5]]
// String methods
const text = 'hello world';
console.log(text.capitalize()); // 'Hello world'
// Date methods
const today = new Date();
console.log(today.isToday()); // trueCDN Usage
You can use the library directly in the browser via unpkg or jsDelivr:
via unpkg
<script src="https://unpkg.com/[email protected]/index.js"></script>
<script>
console.log(isBoolean(true)); // true
</script>via jsDelivr
<script src="https://cdn.jsdelivr.net/npm/[email protected]/index.js"></script>
<script>
console.log("abcdef".chunk(2)); // ['ab','cd','ef']
</script>After including the script, the functions will be available globally.
Categories
Array
Array manipulation and utility functions.
Functions
average() - Returns the average of all numeric elements
[1, 2, 3].average(); // 2 [1, 'a', 2].average(); // 1.5 [].average(); // NaNchunk(size) - Splits the array into chunks of specified size
const arr = [1, 2, 3, 4, 5]; console.log(arr.chunk(2)); // Output: [[1, 2], [3, 4], [5]] console.log(arr.chunk(3)); // Output: [[1, 2, 3], [4, 5]]first() - Returns the first element of the array
const arr = [1, 2, 3]; console.log(arr.first()); // Output: 1 const emptyArr: number[] = []; console.log(emptyArr.first()); // Output: undefinedclone() - Creates a shallow copy of the array
const arr = [1,2,3]; const copy = arr.clone(); console.log(copy); // [1,2,3] console.log(copy === arr); // falsedifference(values) - Returns elements that are in the first array but not in the second
[1, 2, 3, 4].difference([2, 4]); // [1, 3]drop(n) - Removes the first n elements
[1,2,3,4].drop(2); // [3,4]dropLast(n) - Removes the last n elements
[1,2,3,4].dropLast(2); // [1,2]flatten(depth?) - Flattens nested arrays up to the specified depth
[1, [2, [3]]].flatten(); // [1, 2, [3]] [1, [2, [3]]].flatten(2); // [1, 2, 3]flattenDeep() - Recursively flattens all nested arrays
[1, [2, [3, [4]]]].flattenDeep(); // [1, 2, 3, 4]intersection(otherArray) - Returns common elements between arrays
[1,2,3].intersection([2,3,4]); // [2,3] ['a','b'].intersection(['b','c']); // ['b']isEmpty() - Checks if the array is empty
[].isEmpty(); // true [1, 2, 3].isEmpty(); // falselast() - Returns the last element of the array
const arr = [1, 2, 3]; console.log(arr.last()); // Output: 3 const emptyArr: number[] = []; console.log(emptyArr.last()); // Output: undefinedmax() - Returns the maximum value
[1, 2, 3].max(); // 3 [1, 'a', 2].max(); // 2 [].max(); // -Infinitymedian() - Returns the median value
[1, 2, 3].median(); // 2 [1, 'a', 2, 4].median(); // 2 [1].median(); // 1 [].median(); // NaNmin() - Returns the minimum value
[3, 1, 4, 1, 5].min(); // 1 [1, 2, 'a', 3].min(); // 1 ['a', 'b', 'c'].min(); // Infinity [].min(); // Infinitymode() - Returns the most frequent value
[1, 2, 2, 3].mode(); // [2] [1, 1, 2, 2, 3].mode(); // [1, 2] [1].mode(); // [1] [].mode(); // []padEnd(length, value) - Pads the array to a specified length
[1,2].padEnd(4, 0); // [1,2,0,0]padStart(length, value) - Pads the array to a specified length from the start
[1,2].padStart(4, 0); // [0,0,1,2]partition(predicate) - Partitions the array based on a predicate
[1,2,3,4].partition(x => x % 2 === 0); // [[2,4],[1,3]]peek(position?) - Returns the first or last element without removing it
[1,2,3].peek(); // 3 [1,2,3].peek('first'); // 1pluck(keyOrPath) - Extracts a property from each object in the array
[{a:1}, {a:2}].pluck('a'); // [1,2] [{a:{b:1}}, {a:{b:2}}].pluck('a.b'); // [1,2]product() - Returns the product of all numeric elements
[1,2,3,4].product(); // 24pull(...values) - Removes specified values from the array
const arr = [1, 2, 3, 4, 5, 2]; arr.pull(2); // arr is now [1, 3, 4, 5] const arr2 = [1, 2, 3, 4, 5]; arr2.pull((n) => n % 2 === 0); // arr2 is now [1, 3, 5]random() - Returns a random element from the array
const arr = [1, 2, 3]; console.log(arr.random()); // Could be 1, 2, or 3 const emptyArr: number[] = []; console.log(emptyArr.random()); // Output: undefinedreverseCopy() - Returns a reversed copy of the array
[1,2,3].reverseCopy(); // [3,2,1] const arr = [1,2,3]; arr.reverseCopy(); // [3,2,1], arr remains [1,2,3]rotate(steps) - Rotates the array by a specified number of positions
[1,2,3,4].rotate(1); // [4,1,2,3] [1,2,3,4].rotate(-1); // [2,3,4,1]shuffle() - Randomly shuffles the array
const arr = [1, 2, 3, 4, 5]; arr.shuffle(); // e.g., [3, 5, 1, 4, 2]sortBy(key?, order?) - Sorts the array by a specified property or function
[3,1,2].sortBy(); // [1,2,3] [{a:2},{a:1}].sortBy('a'); // [{a:1},{a:2}] [{a:2},{a:1}].sortBy('a','desc'); // [{a:2},{a:1}] [{x:2},{x:1}].sortBy((item,i,array) => item.x + i, -1); // [{x:2},{x:1}]std() - Returns the standard deviation
[2,4,4,4,5,5,7,9].std(); // 2sum() - Returns the sum of all numeric elements
[1, 2, 3].sum(); // 6 [1, 'a', 2].sum(); // 3take(n) - Returns the first n elements
[1,2,3,4].take(2); // [1,2]takeLast(n) - Returns the last n elements
[1,2,3,4].takeLast(2); // [3,4]tap(fn) - Executes a function and returns the original array
[1,2,3].tap(arr => console.log(arr)).map(x => x*2);unique(keyFn?) - Returns unique elements from the array
[1,2,2,3,1].unique(); // [1,2,3] [{a:1},{a:1}].unique(item => item.a); // [{a:1}]variance() - Returns the variance of numeric elements
[2,4,4,4,5,5,7,9].variance(); // 4zip(...arrays) - Combines multiple arrays into an array of tuples
[1,2,3].zip(['a','b','c']); // [[1,'a'], [2,'b'], [3,'c']] [1,2].zip(['a','b','c'], ['x','y']); // [[1,'a','x'], [2,'b','y'], [undefined,'c',undefined]]
Boolean
Boolean operations and utilities.
Functions
and(other) - Performs AND operation with another boolean
(true).and(true); // true (true).and(false); // falseisTrue() - Checks if the value is exactly true
(true).isTrue(); // true (false).isTrue(); // falseisFalse() - Checks if the value is exactly false
(true).isFalse(); // false (false).isFalse(); // truenand(other) - Performs NAND operation
(true).nand(true); // false (true).nand(false); // truenor(other) - Performs NOR operation
(false).nor(false); // true (true).nor(false); // falseor(other) - Performs OR operation with another boolean
(true).or(false); // true (false).or(false); // falsetoBit() - Converts boolean to bit (0 or 1)
(true).toBit(); // "1" (false).toBit(); // "0"toggle() - Toggles the boolean value
(true).toggle(); // false (false).toggle(); // truetoNumber() - Converts boolean to number
(true).toNumber(); // 1 (false).toNumber(); // 0toString() - Converts boolean to string
(true).toString(); // "true" (false).toString(); // "false"xor(other) - Performs XOR operation with another boolean
(true).xor(false); // true (true).xor(true); // false
Buffer
Buffer utilities and conversions.
Functions
toBase64() - Converts buffer to base64 string
const buf = Buffer.from('hello'); buf.toBase64(); // "aGVsbG8="toUint8Array() - Converts buffer to Uint8Array
const buf = new ArrayBuffer(4); const arr = buf.toUint8Array(); // Uint8Array(4) [0,0,0,0]
Date
Date manipulation and utility functions.
Functions
addDays(n) - Adds n days to the date
const d = new Date(); d.addDays(5); // 5 gün eklerisToday() - Checks if the date is today
new Date().isToday(); // trueaddHours(n) - Adds hours to the date
const d = new Date('2025-09-17T12:00:00'); d.addHours(3); // 2025-09-17T15:00:00addMinutes(n) - Adds minutes to the date
const d = new Date('2025-09-17T12:00:00'); d.addMinutes(15); // 2025-09-17T12:15:00addMonths(n) - Adds months to the date
addSeconds(n) - Adds seconds to the date
const d = new Date('2025-09-17T12:00:00'); d.addSeconds(30); // 2025-09-17T12:00:30addWeeks(n) - Adds weeks to the date
addYears(n) - Adds years to the date
clone() - Creates a copy of the date
const d1 = new Date('2025-09-17'); const d2 = d1.clone(); d1 === d2; // falsedayName() - Returns the day name
dayOfYear() - Returns the day of the year
const d = new Date('2025-01-15'); d.dayOfYear(); // 15differenceInDays(otherDate) - Calculates difference in days
differenceInMonths(otherDate) - Calculates difference in months
differenceInYears(otherDate) - Calculates difference in years
diffInDays(otherDate) - Calculates difference in days
new Date('2025-09-17').diffInDays(new Date('2025-09-20')); // -3diffInHours(otherDate) - Calculates difference in hours
new Date('2025-09-17T12:00').diffInHours(new Date('2025-09-17T08:00')); // 4diffInMinutes(otherDate) - Calculates difference in minutes
new Date('2025-09-17T12:00').diffInMinutes(new Date('2025-09-17T11:30')); // 30diffInMonths(otherDate) - Calculates difference in months
new Date('2025-09-17').diffInMonths(new Date('2025-06-17')); // 3diffInSeconds(otherDate) - Calculates difference in seconds
new Date('2025-09-17T12:00:30').diffInSeconds(new Date('2025-09-17T12:00:00')); // 30diffInYears(otherDate) - Calculates difference in years
new Date('2025-09-17').diffInYears(new Date('2020-09-17')); // 5endOfDay() - Returns end of day
endOfMonth() - Returns end of month
endOfYear() - Returns end of year
format(fmt) - Formats the date according to the given format string
const d = new Date('2025-09-17T12:30:45'); d.format('YYYY-MM-DD'); // "2025-09-17" d.format('DD/MM/YYYY HH:mm'); // "17/09/2025 12:30"isAfter(otherDate) - Checks if date is after another date
const d1 = new Date('2025-09-19'); const d2 = new Date('2025-09-18'); d1.isAfter(d2); // trueisBefore(otherDate) - Checks if date is before another date
const d1 = new Date('2025-09-17'); const d2 = new Date('2025-09-18'); d1.isBefore(d2); // trueisBetween(startDate, endDate) - Checks if date is between two dates
const d = new Date('2025-09-17'); d.isBetween(new Date('2025-09-16'), new Date('2025-09-18')); // trueisFuture() - Checks if date is in the future
new Date('2030-01-01').isFuture(); // trueisLeapYear() - Checks if year is a leap year
new Date('2024-01-01').isLeapYear(); // trueisPast() - Checks if date is in the past
new Date('2020-01-01').isPast(); // trueisSameDay(otherDate) - Checks if dates are the same day
const d1 = new Date('2025-09-17'); const d2 = new Date('2025-09-17'); d1.isSameDay(d2); // trueisSameMonth(otherDate) - Checks if dates are the same month
const d1 = new Date('2025-09-17'); const d2 = new Date('2025-09-01'); d1.isSameMonth(d2); // trueisSameYear(otherDate) - Checks if dates are the same year
const d1 = new Date('2025-09-17'); const d2 = new Date('2025-01-01'); d1.isSameYear(d2); // trueisTomorrow() - Checks if date is tomorrow
const d = new Date(); d.setDate(d.getDate() + 1); d.isTomorrow(); // trueisWeekday() - Checks if date is a weekday
new Date('2025-09-17').isWeekday(); // true (Wednesday)isWeekend() - Checks if date is a weekend
new Date('2025-09-20').isWeekend(); // true (Saturday)isYesterday() - Checks if date is yesterday
const d = new Date(); d.setDate(d.getDate() - 1); d.isYesterday(); // truemonthName() - Returns the month name
quarter() - Returns the quarter
const d = new Date('2025-05-10'); d.quarter(); // 2startOfDay() - Returns start of day
startOfMonth() - Returns start of month
startOfYear() - Returns start of year
subtractDays(n) - Subtracts days from the date
subtractHours(n) - Subtracts hours from the date
const d = new Date('2025-09-17T12:00:00'); d.subtractHours(2); // 2025-09-17T10:00:00subtractMinutes(n) - Subtracts minutes from the date
const d = new Date('2025-09-17T12:00:00'); d.subtractMinutes(30); // 2025-09-17T11:30:00subtractMonths(n) - Subtracts months from the date
subtractSeconds(n) - Subtracts seconds from the date
const d = new Date('2025-09-17T12:00:00'); d.subtractSeconds(15); // 2025-09-17T11:59:45subtractWeeks(n) - Subtracts weeks from the date
subtractYears(n) - Subtracts years from the date
toArray() - Converts date to array
new Date('2025-09-17T12:34:56.789Z').toArray(); // [2025, 9, 17, 12, 34, 56, 789]toLongDate(locale?) - Returns long date format
new Date('2025-09-17').toLongDate(); // "17 September 2025" new Date('2025-09-17').toLongDate('tr-TR'); // "17 Eylül 2025"toMilliseconds() - Returns milliseconds
const d = new Date('1970-01-01T00:00:01.500Z'); d.toMilliseconds(); // 1500toObject() - Converts date to object
new Date('2025-09-17T12:34:56.789Z').toObject(); // { year: 2025, month: 9, day: 17, hour: 12, minute: 34, second: 56, millisecond: 789 }toShortDate(locale?) - Returns short date format
new Date('2025-09-17').toShortDate(); // "17/09/2025" new Date('2025-09-17').toShortDate('en-GB'); // "17/09/2025"toUnix() - Returns Unix timestamp
const d = new Date('1970-01-01T00:00:01Z'); d.toUnix(); // 1weekNumber() - Returns week number
const d = new Date('2025-01-03'); d.weekNumber(); // 1
File
File utilities and operations.
Functions
sizeInKB() - Returns file size in KB
const file = new File(["Hello"], "hello.txt"); console.log(file.sizeInKB()); // ~0.005 KBsizeInMB() - Returns file size in MB
const file = new File(["Hello"], "hello.txt"); console.log(file.sizeInMB()); // ~0.000005 MBtoBase64() - Converts file to base64
const base64 = await file.toBase64();
Function
Function utilities and higher-order functions.
Functions
debounce(ms) - Debounces the function by given milliseconds
const log = () => console.log('Hi'); const debounced = log.debounce(300);memoize() - Caches the results of the function for same arguments
const fib = (n: number): number => n <= 1 ? n : fib(n-1)+fib(n-2); const fastFib = fib.memoize();cancellable() - Makes function cancelable
const log = () => console.log('Hi'); const fn = log.cancellable(); fn(); fn.cancel();compose(...fns) - Composes multiple functions
const double = (x: number) => x*2; const increment = (x: number) => x+1; const fn = Function.compose(double, increment); fn(3); // double(increment(3)) => 8curry() - Curries the function
const add = (a: number, b: number) => a + b; const curried = add.curry(); curried(1)(2); // 3delay(ms) - Delays function execution
const sayHi = () => console.log('Hi'); sayHi.delay(1000)(); // logs "Hi" after 1 secondonce() - Ensures function runs only once
const init = () => console.log('Init'); const runOnce = init.once(); runOnce(); // "Init" runOnce(); // does nothingpipe(...fns) - Pipes functions together
const add = (a: number) => a + 1; const double = (a: number) => a * 2; const piped = add.pipe(double); piped(2); // double(add(2)) = 6safe() - Wraps function in try-catch
const risky = (x: number) => { if (x < 0) throw new Error(); return x * 2; }; const safeFn = risky.safe(); safeFn(5); // 10 safeFn(-3); // undefinedtap(fn) - Executes function and returns original value
const add = (x: number) => x + 1; const wrapped = add.tap(result => console.log(result)); wrapped(2); // logs 3, returns 3throttle(ms) - Throttles function execution
const log = () => console.log('Hi'); const throttled = log.throttle(500);
Global
Global utility functions for type checking and validation.
Functions
isArray(value) - Checks if the given value is an array
isArray([1, 2, 3]); // true isArray('hello'); // false isArray({}); // falseisBoolean(value) - Checks if value is boolean
isBoolean(true); // true isBoolean(false); // true isBoolean(0); // false isBoolean('true'); // falseisDate(value) - Checks if value is date
isDate(new Date()); // true isDate('2023-01-01'); // false isDate({}); // falseisEmpty(value) - Checks if value is empty
isEmpty(null); // true isEmpty(undefined); // true isEmpty(''); // true isEmpty([]); // true isEmpty({}); // true isEmpty(0); // false isEmpty('hello'); // false isEmpty([1, 2, 3]); // false isEmpty({ a: 1 }); // falseisFunction(value) - Checks if value is function
isFunction(function() {}); // true isFunction(() => {}); // true isFunction(class {}); // true isFunction(123); // false isFunction('hello'); // falseisNil(value) - Checks if value is null or undefined
isNil(null); // true isNil(undefined); // true isNil(0); // false isNil(''); // falseisNumber(value) - Checks if value is number
isNumber(123); // true isNumber('hello'); // false isNumber(NaN); // falseisObject(value) - Checks if value is object
isObject({}); // true isObject([]); // true isObject(null); // false isObject(123); // falseisPromise(value) - Checks if value is promise
isPromise(Promise.resolve()); // true isPromise({ then: () => {}, catch: () => {} }); // true isPromise(123); // falseisString(value) - Checks if value is string
isString('hello'); // true isString(123); // false isString({}); // falseisUndefined(value) - Checks if value is undefined
isUndefined(undefined); // true isUndefined(null); // false isUndefined(0); // false
JSON
JSON utilities and safe parsing.
Functions
safeParse(text) - Safely parses JSON string
JSON.safeParse('{"a":1}'); // { a: 1 } JSON.safeParse('invalid'); // undefined // Generic type example interface User { id: number; name: string; } const user = JSON.safeParse<User>('{"id":1,"name":"Alice"}'); if (user) { console.log(user.id); // 1 }safeStringify(value, space?) - Safely stringifies object to JSON
JSON.safeStringify({a:1}); // '{"a":1}' JSON.safeStringify(() => {}); // undefined
Math
Mathematical operations and utilities.
Functions
add(a, b) - Adds two numbers
Math.add(5, 3); // 8average() - Calculates average
clamp(value, min, max) - Clamps value between min and max
Math.clamp(10, 0, 5); // 5 Math.clamp(-2, 0, 5); // 0decrement() - Decrements number by 1
degToRad() - Converts degrees to radians
divide() - Divides two numbers
factorial(n) - Calculates factorial
Math.factorial(5); // 120gcd(a, b) - Calculates greatest common divisor
Math.gcd(12, 18); // 6geometricMean() - Calculates geometric mean
harmonicMean() - Calculates harmonic mean
increment() - Increments number by 1
isBetween() - Checks if number is between two values
isEven() - Checks if number is even
isFinite() - Checks if number is finite
isInfinity() - Checks if number is infinity
isInteger() - Checks if number is integer
isMultipleOf() - Checks if number is multiple of another
isNegative() - Checks if number is negative
isOdd() - Checks if number is odd
isPositive() - Checks if number is positive
isPrime() - Checks if number is prime
lcm() - Calculates least common multiple
lerp(a, b, t) - Linear interpolation
Math.lerp(0, 10, 0.5); // 5maxArray() - Returns maximum from array
minArray() - Returns minimum from array
mod() - Modulo operation
multiply() - Multiplies two numbers
negate() - Negates number
normalize() - Normalizes value to 0-1 range
percentage() - Calculates percentage
product() - Calculates product of array
radToDeg() - Converts radians to degrees
randomBoolean() - Returns random boolean
randomChoice() - Returns random choice from array
randomFloat() - Returns random float
randomInt(min, max) - Returns random integer
Math.randomInt(1, 6); // 4 Math.randomInt(10, 20); // 15randomSign() - Returns random sign
range() - Creates range of numbers
rootMeanSquare() - Calculates root mean square
roundTo() - Rounds to specified decimal places
scale() - Scales value to new range
signOrZero() - Returns sign or zero
subtract() - Subtracts two numbers
sum() - Calculates sum of array
toBinary() - Converts to binary
toFixed() - Formats number with fixed decimals
toHex() - Converts to hexadecimal
toInt() - Converts to integer
toRoman() - Converts to Roman numerals
zScore() - Calculates z-score
Number
Number utilities and operations.
Functions
abs() - Returns the absolute value of the number
(-5).abs(); // 5add() - Adds two numbers
average() - Calculates average
between() - Checks if number is between two values
cbrt() - Calculates cube root
ceil() - Rounds up to nearest integer
(3.01).ceil(); // 4clamp() - Clamps value between min and max
cube() - Calculates cube
(3).cube(); // 27decrement() - Decrements by 1
divide() - Divides two numbers
divisors() - Returns divisors
equals(other, tolerance?) - Checks equality
(5.01).equals(5, 0.1); // trueexp() - Calculates exponential
(1).exp(); // Math.Efactorial() - Calculates factorial
floor() - Rounds down to nearest integer
(3.99).floor(); // 3gcd() - Calculates greatest common divisor
increment() - Increments by 1
inRange(min, max, inclusive?) - Checks if in range
(5).inRange(1, 10); // trueisBetween() - Checks if between two values
isEven() - Checks if even
(4).isEven(); // true (5).isEven(); // falseisFibonacci() - Checks if Fibonacci number
(8).isFibonacci(); // trueisFinite() - Checks if finite
isFloat() - Checks if float
(5.5).isFloat(); // true (5).isFloat(); // falseisInfinity() - Checks if infinity
(Infinity).isInfinity(); // true (-Infinity).isInfinity(); // true (5).isInfinity(); // falseisInteger() - Checks if integer
(5).isInteger(); // true (5.5).isInteger(); // falseisMultipleOf(other) - Checks if multiple of
(12).isMultipleOf(3); // true (12).isMultipleOf(5); // falseisNegative() - Checks if negative
(-5).isNegative(); // true (3).isNegative(); // falseisOdd() - Checks if odd
isPerfect() - Checks if perfect number
(6).isPerfect(); // trueisPerfectSquare() - Checks if perfect square
(16).isPerfectSquare(); // true (20).isPerfectSquare(); // falseisPositive() - Checks if positive
(5).isPositive(); // true (-3).isPositive(); // falseisPrime() - Checks if prime
(7).isPrime(); // true (10).isPrime(); // falseisZero() - Checks if zero
(0).isZero(); // true (5).isZero(); // falselcm() - Calculates least common multiple
log(base?) - Calculates logarithm
(10).log(); // Math.log(10) (8).log(2); // 3median(...others) - Calculates median
(5).median(10, 15); // 10mod() - Modulo operation
multiply() - Multiplies two numbers
negate() - Negates number
nthRoot(n) - Calculates nth root
(27).nthRoot(3); // 3padEnd(length, char?) - Pads string representation
(5).padEnd(3); // "5--"padStart() - Pads string representation
pow() - Calculates power
round(decimals?) - Rounds to nearest integer
(3.14159).round(2); // 3.14 (3.14159).round(); // 3roundTo() - Rounds to specified decimals
sign() - Returns sign
sqrt() - Calculates square root
(9).sqrt(); // 3square() - Calculates square
subtract() - Subtracts two numbers
surround() - Surrounds with characters
times() - Repeats function n times
toBinary() - Converts to binary
toBinaryFileSize() - Converts to binary file size
toCurrency() - Converts to currency format
toDate() - Converts to date
toDays() - Converts to days
toDaysFromHours() - Converts hours to days
toDaysFromMinutes() - Converts minutes to days
toDaysFromMonths() - Converts months to days
toDaysFromSeconds() - Converts seconds to days
toDaysFromWeeks() - Converts weeks to days
toDaysFromYears() - Converts years to days
toDegree() - Converts to degrees
toDuration() - Converts to duration string
toFileSize() - Converts to file size
toHex() - Converts to hexadecimal
toHours() - Converts to hours
toLongDuration() - Converts to long duration
toMilliseconds() - Converts to milliseconds
toMinutes() - Converts to minutes
toMonths() - Converts to months
toOctal() - Converts to octal
toPadded() - Pads number
toPercent() - Converts to percentage
toPercentString() - Converts to percentage string
toRadian() - Converts to radians
toRoman() - Converts to Roman numerals
(9).toRoman(); // "IX"toSeconds() - Converts to seconds
toSeparated() - Adds separators
toTime() - Converts to time string
toWeeks() - Converts to weeks
toWords() - Converts to words
toYears() - Converts to years
variance() - Calculates variance
Object
Object manipulation and utility functions.
Functions
clone(obj) - Creates a shallow clone of an object
Object.clone({ a: 1, b: 2 }); // { a: 1, b: 2 }countKeys(obj) - Counts object keys
Object.countKeys({ a:1, b:2 }); // 2countValues(obj) - Counts object values
Object.countValues({ a:1, b:2 }); // 2deepClone(obj) - Creates deep clone
Object.deepClone({ a: { b: 1 } }); // { a: { b:1 } } (new nested object)defaults() - Sets default values
every() - Checks if all properties satisfy condition
filter(obj, fn) - Filters object properties
Object.filter({ a:1, b:2, c:3 }, (v) => v > 1); // { b:2, c:3 }filterKeys(obj, fn) - Filters object keys
Object.filterKeys({ a:1, b:2, c:3 }, k => k !== 'b'); // { a:1, c:3 }filterValues(obj, fn) - Filters object values
Object.filterValues({ a:1, b:2, c:3 }, v => v > 1); // { b:2, c:3 }findKey(obj, fn) - Finds key by value
Object.findKey({ a:1, b:2 }, v => v === 2); // 'b'findValue(obj, fn) - Finds value by key
Object.findValue({ a:1, b:2 }, v => v > 1); // 2fromFlat(obj, separator?) - Creates object from flat structure
Object.fromFlat({ 'a.b': 1 }); // { a: { b: 1 } }get() - Gets nested property
hasKey(obj, key) - Checks if has key
Object.hasKey({ a: 1 }, 'a'); // true Object.hasKey({ a: 1 }, 'b'); // falsehasKeys(obj, keys) - Checks if has keys
Object.hasKeys({ a: 1, b: 2 }, ['a','b']); // true Object.hasKeys({ a: 1 }, ['a','b']); // falsehasPath() - Checks if has path
hasValue() - Checks if has value
invert() - Inverts key-value pairs
isEmpty() - Checks if object is empty
isEqual() - Checks deep equality
isPlainObject() - Checks if plain object
isShallowEqual() - Checks shallow equality
mapKeys() - Maps object keys
mapValues() - Maps object values
merge(target, source) - Deep merges two objects
Object.merge({ a: { x: 1 } }, { a: { y: 2 } }); // { a: { x:1, y:2 } }omit() - Omits specified keys
pick() - Picks specified keys
reject() - Rejects properties by condition
setIfUndefined() - Sets value if undefined
size() - Returns object size
some() - Checks if any property satisfies condition
tap() - Executes function and returns object
toFlat() - Flattens object
toPairs() - Converts to key-value pairs
unset() - Removes property
update() - Updates property
Promise
Promise utilities and helpers.
Functions
delay(ms) - Delays promise resolution
Promise.resolve(42).delay(1000).then(console.log); // logs 42 after 1sretry(times, delayMs?) - Retries promise on failure
tap(fn) - Executes function and returns promise
Promise.resolve(42) .tap(value => console.log(value)) // logs 42 .then(value => console.log(value)); // 42timeout(ms, error?) - Adds timeout to promise
Promise.resolve(42).timeout(1000).then(console.log);
String
String manipulation and utility functions.
Functions
capitalize() - Capitalizes only the first letter of the string
'hello'.capitalize(); // 'Hello'chunk(n) - Splits string into chunks
'abcdef'.chunk(2); // ['ab','cd','ef']contains(substr) - Checks if string contains substring
'hello world'.contains('world'); // truecount(substr) - Counts occurrences
'ababab'.count('ab'); // 3drop(n) - Removes first n characters
'hello'.drop(2); // 'llo'dropLast(n) - Removes last n characters
'hello'.dropLast(2); // 'hel'endsWithIgnoreCase(substr) - Checks if ends with (case insensitive)
'Hello World'.endsWithIgnoreCase('WORLD'); // truefirst(n?) - Returns first character
'hello'.first(2); // 'he' 'hello'.first(); // 'h' 'hello'.first(0); // '' 'hello'.first(10); // 'hello'firstWord() - Returns first word
'Hello world!'.firstWord(); // 'Hello' ''.firstWord(); // ''includesIgnoreCase(substr) - Checks if includes (case insensitive)
'Hello World'.includesIgnoreCase('hello'); // trueindexAll(substr) - Returns all indices of substring
'ababab'.indexAll('ab'); // [0,2,4]isAlpha() - Checks if alphabetic
isAlphaNumeric() - Checks if alphanumeric
isAnagramOf() - Checks if anagram
isBase64() - Checks if base64
isBinary() - Checks if binary
isBlank() - Checks if blank
isCreditCard() - Checks if credit card number
isDate() - Checks if date string
isDomain() - Checks if domain
isEmail() - Checks if email
'[email protected]'.isEmail(); // true 'user@com'.isEmail(); // falseisEmoji() - Checks if emoji
isEmpty() - Checks if empty
isFloat() - Checks if float string
isHex() - Checks if hexadecimal
isInteger() - Checks if integer string
isIp() - Checks if IP address
isIsoDate() - Checks if ISO date
isJSON() - Checks if JSON string
isLowerCase() - Checks if lowercase
isNumeric() - Checks if numeric
isOctal() - Checks if octal
isPalindrome() - Checks if palindrome
isPhone() - Checks if phone number
isTime() - Checks if time string
isUpperCase() - Checks if uppercase
isURL() - Checks if URL
isUUID() - Checks if UUID
isWhitespace() - Checks if whitespace
last() - Returns last character
lastWord() - Returns last word
lengthStats() - Returns length statistics
normalizeSpaces() - Normalizes spaces
padBoth() - Pads both sides
remove() - Removes characters
reverse() - Reverses string
'hello'.reverse(); // 'olleh'splitLines() - Splits into lines
startsWithIgnoreCase() - Checks if starts with (case insensitive)
stripNonAlpha() - Strips non-alphabetic characters
stripNumbers() - Strips numbers
stripPunctuation() - Strips punctuation
stripSymbols() - Strips symbols
stripWhitespace() - Strips whitespace
surround() - Surrounds with characters
take() - Takes first n characters
takeLast() - Takes last n characters
tap() - Executes function and returns string
toArray() - Converts to character array
toAscii() - Converts to ASCII
toBinary() - Converts to binary
toBoolean() - Converts to boolean
toCamelCase() - Converts to camelCase
'foo_bar'.toCamelCase(); // 'fooBar' 'hello-world'.toCamelCase(); // 'helloWorld'toCharCodes() - Converts to character codes
toDate() - Converts to date
toFloat() - Converts to float
toHex() - Converts to hexadecimal
toInt() - Converts to integer
toKebabCase() - Converts to kebab-case
toMorse() - Converts to Morse code
toNumber() - Converts to number
toPascalCase() - Converts to PascalCase
toSlug() - Converts to slug
toSnakeCase() - Converts to snake_case
toSwapCase() - Converts to swap case
toTitleCase() - Converts to Title Case
toUnicode() - Converts to Unicode
truncate() - Truncates string
words() - Splits into words
License
MIT
