Gathering detailed insights and metrics for @sandstreamdev/std
Gathering detailed insights and metrics for @sandstreamdev/std
npm install @sandstreamdev/std
Typescript
Module System
Node Version
NPM Version
TypeScript (73.32%)
JavaScript (26.68%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
17,211
Last Day
1
Last Week
7
Last Month
45
Last Year
1,650
MIT License
9 Stars
535 Commits
4 Watchers
2 Branches
5 Contributors
Updated on Feb 24, 2025
Minified
Minified + Gzipped
Latest Version
0.15.0
Package Id
@sandstreamdev/std@0.15.0
Unpacked Size
311.00 kB
Size
77.44 kB
File Count
649
NPM Version
10.7.0
Node Version
20.15.0
Published on
Jun 24, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-72%
7
Compared to previous week
Last Month
-58.3%
45
Compared to previous month
Last Year
-21.4%
1,650
Compared to previous year
1npm install @sandstreamdev/std
Checks if the given array is present and it is not empty (contains at least one element).
1<T>(xs?: T[]) => boolean
1any([]); 2// ⇒ false
1any([1, 2, 3]); 2// ⇒ true
Checks if the given arguments are all Arrays
.
1<T>(...xs: T[]) => boolean
1are([2, 3]); 2// ⇒ true
1are([1, 2, 3], []); 2// ⇒ true
1are([1, 2, 3], 8, [1, 3], "test"); 2// ⇒ false
Splits the given array into an array of chunks of up to the given length.
1(count: number) => <T>(xs: T[]) => T[] | T[][]
1chunk(2)(['a', 'b', 'c', 'd']); 2// ⇒ [['a', 'b'], ['c', 'd']]
1chunk(3)(['a', 'b', 'c', 'd']); 2// ⇒ [['a', 'b', 'c'], ['d']]
Computes a set difference between the two given arrays.
1<T>(xs: T[], ys: T[]) => T[]
1difference([1, 2, 3, 4, 5, 6], [2, 4]); 2// ⇒ [1, 3, 5, 6]
Checks if two arrays are not equal.
1<T>(xs?: T[], ys?: T[]) => boolean
1differs([1, 2, 3], [1, 2]); 2// ⇒ true
1differs([1, 2, 3], [1, 2, 3]); 2// ⇒ false
Lists all the duplicated values in the given array.
1<T>(xs: T[]) => T[]
1duplicates([1, 2, 3, 4, 3, 4, 3, 6]); 2// ⇒ [3, 4, 3]
Empty array.
1unknown[]
1empty; 2// ⇒ []
Takes exactly the given count of elements.
1(count: number) => <T>(xs: T[]) => T[]
1exact(5)([1, 2, 3]); 2// ⇒ [1, 2, 3, undefined, undefined]
1exact(2)([1, 2, 3]); 2// ⇒ [1, 2]
Filters out the given value.
1<T>(y: T) => (xs: T[]) => T[]
1except(2)([1, 2, 3, 4, 5]); 2// ⇒ [1, 3, 4, 5]
1except(2)([1, 2, 2, 4, 2]); 2// ⇒ [1, 4]
Filters the given array with the given predicate just like Array.filter but does it in-place thus mutates the original array.
1<T>(f: (value: T, index: number, context: T[]) => boolean) => (xs: T[]) => T[]
1const xs = [1, 2, 3, 4, 5, 6, 7]; 2const odd = x => x % 2 === 1; 3 4const ys = filterInPlace(odd)(xs); 5 6ys === xs; 7// ⇒ true 8ys; 9// ⇒ [1, 3, 5, 7]
Finds an element by a predicate function within the given array, otherwise, it returns the given fallback value or undefined when fallback is not present.
1<T>(predicate: (value: T, index: number, context: T[]) => boolean, fallback?: T) => (xs: T[]) => T
1find(x => x > 2)([1, 2, 3, 5, 7]); 2// ⇒ 3
1find(x => x > 2)([1, 2, -3, -5, -7]); 2// ⇒ undefined
Returns the first element or undefined when there are no elements in the given array.
1<T>([x]: T[]) => T | undefined
1first([1, 2, 3]); 2// ⇒ 1
1first([]); 2// ⇒ undefined
Maps and flattens the result.
1<T, TResult>(f: (value: T, index: number, context: T[]) => TResult[]) => (xs: T[]) => TResult[]
1flatMap(text => [...text])(["test", "123"]); 2// ⇒ ["t", "e", "s", "t", "1", "2", "3"]
Flattens the nested arrays by a single level.
1<T>(xs: T[]) => T[]
1flatten([1, [2, 3], 4, [5, 6]]); 2// ⇒ [1, 2, 3, 4, 5, 6]
1flatten([1, [2, [3, 6]], 4, [5, 6]]); 2// ⇒ [1, 2, [3, 6], 4, 5, 6]
Inserts the given item to the array at a specific index.
1(index: number) => <T>(item: T) => ([...xs]: T[]) => T[]
1insert(0)('d')(['a', 'b', 'c']); 2// ⇒ ['d', 'a', 'b', 'c']
1insert(1)('d')(['a', 'b', 'c']); 2// ⇒ ['a', 'd', 'b', 'c']
Finds common elements between both arrays.
1<T>(xs: T[], ys: T[]) => T[]
1intersection([1, 2, 3, 4, 5], [5, 5, 3, 2]); 2// ⇒ [2, 3, 5]
Checks if the given argument is an array.
1(value?: unknown) => boolean
1is([1, 2, 3]); 2// ⇒ true
1is({ a: 5 }); 2// ⇒ false
Returns the last element or undefined when there are no elements in the given array.
1<T>(xs: T[]) => T | undefined
1last([1, 2, 3]); 2// ⇒ 3
1last([]); 2// ⇒ undefined
Returns the number of elements in the given array.
1<T>(xs: T[]) => number
1length([true, 1]); 2// ⇒ 2
1length([1, 2, 3]); 2// ⇒ 3
1length([]); 2// ⇒ 0
Checks if lengths of the given arrays differ.
1<T1, T2>(a: T1[], b: T2[]) => boolean
1lengthDiffers([1, 2, 3], [1, 2]); 2// ⇒ true
1lengthDiffers([6, 7], [1, 2]); 2// ⇒ false
Maps the given array with the given functions.
1<T>(...fs: ((x: T) => T)[]) => (xs: T[]) => T[]
1map(x => x * x)([1, 2, 3]); 2// ⇒ [1, 4, 9]
1map(x => x * x, x => x + 1)([1, 2, 3]); 2// ⇒ [2, 5, 10]
Returns the middle element or the right one when the number of elements is even.
1<T>(xs: T[]) => T | undefined
1midpoint([1, 2, 3, 4, 5]); 2// ⇒ 3
1midpoint([1, 2, 3, 4]); 2// ⇒ 3
Computes minimum and maximum values of the given array in a single run.
1(xs: number[]) => number[]
1minMax([10, 5, 3, -5, -4, 23, 32, 8, 1, 0]); 2// ⇒ [-5, 32]
1minMax([1]); 2// ⇒ [1, 1]
1minMax([]); 2// ⇒ [undefined, undefined]
Checks if the given array contains more than one element.
1<T>(xs: T[]) => boolean
1multiple([1, 2, 3]); 2// ⇒ true
1multiple([1, 2]); 2// ⇒ true
1multiple([1]); 2// ⇒ false
1multiple([]); 2// ⇒ false
Checks if the given array is empty.
1<T>(xs?: T[]) => boolean
1none([]); 2// ⇒ true
1none([1, 2, 3]); 2// ⇒ false
Partitions the given array to the ones that pass the given predicate function and the ones that do not. By convention of the Haskell's Data.Either, values that pass the predicate are placed at the right.
1<T>(predicate: (x: T) => boolean) => (xs: T[]) => readonly [T[], T[]]
1partition(x => x % 2 === 1)([1, 2, 3, 4, 5]); 2// ⇒ [[2, 4], [1, 3, 5]])
Returns the given array without the last element.
1<T>(xs: T[]) => T[]
1pop([1, 2, 3, 4]); // ⇒ [1, 2, 3]
1pop([]); // ⇒ []
Generates an array of numbers from 0 to n - 1.
1(n: number) => number[]
1range(3); 2// ⇒ [0, 1, 2]
Removes an element at the given index from the given array.
1(index: number) => <T>(xs: T[]) => T[]
1removeAt(3)([1, 2, 3, 4, 5, 6]) 2// ⇒ [1, 2, 3, 5, 6]
Repeats the given element by the given count of times.
1(count: number) => <T>(value: T) => T[]
1repeat(3)("test"); 2// ⇒ ["test", "test", "test"]
Reverses the given array without mutating it (in contrast to Array.reverse).
1<T>(xs: T[]) => T[]
1reverse([1, 2, 3, 4, 5]); 2// ⇒ [5, 4, 3, 2, 1]
Reverses the given array when enabled.
1(enabled: boolean) => <T>(xs: T[]) => T[]
1reverseIf(true)([1, 2, 3, 4, 5]); 2// ⇒ [5, 4, 3, 2, 1]
1reverseIf(false)([1, 2, 3, 4, 5]); 2// ⇒ [1, 2, 3, 4, 5]
Returns the second element or undefined when there are less than two elements in the given array.
1<T>(xs: T[]) => T | undefined
1second([1, 2, 3, 4, 5]); 2// ⇒ 2
1second([1]); 2// ⇒ undefined
1second([]); 2// ⇒ undefined
Returns the second to last element or undefined when there are less than two elements in the given array.
1<T>(xs: T[]) => T | undefined
1secondToLast([1, 2, 3, 4, 5]); 2// ⇒ 4
1secondToLast([1]); 2// ⇒ undefined
1secondToLast([]); 2// ⇒ undefined
Shifts the given array to the left and circulates the elements back by modulo of the array's length.
1(count: number) => <T>(xs: T[]) => T[]
1shift(1)([1, 2, 3, 4, 5]); 2// ⇒ [2, 3, 4, 5, 1]
1shift(2)([1, 2, 3, 4, 5]); 2// ⇒ [3, 4, 5, 1, 2]
1shift(3)([1, 2, 3, 4, 5]); 2// ⇒ [4, 5, 1, 2, 3]
Shuffles the given array in random order with Math.random as the default.
1<T>(xs: T[], random?: () => number) => T[]
1let i = 0; 2 3const random = () => 4 [ 5 0.013606630487694282, 6 0.21052486239086554, 7 0.28299838254636556, 8 0.696161009199874, 9 0.32165320593537117 10 ][i++]; 11 12shuffle([1, 2, 3, 4, 5], random); // => [3, 5, 4, 2, 1]
Shuffles the given array in-place in random order with Math.random as the default.
1<T>(xs: T[], random?: () => number) => T[]
1let i = 0; 2 3const random = () => 4 [ 5 0.013606630487694282, 6 0.21052486239086554, 7 0.28299838254636556, 8 0.696161009199874, 9 0.32165320593537117 10 ][i++]; 11 12shuffleInPlace([1, 2, 3, 4, 5], random); // => [3, 5, 4, 2, 1]
Checks if the given array contains exactly one element.
1<T>(xs: T[]) => boolean
1single([1]); 2// ⇒ true
1single([1, 2, 3]); 2// ⇒ false
1single([]); 2// ⇒ false
Skips the given count of elements from the given array.
1(count: number) => <T>(xs: T[]) => T[]
1skip(2)([1, 2, 3, 4, 5]); 2// ⇒ [3, 4, 5]
Returns a new array composed of tuples of the given sliding window length of consecutive elements.
1(count: number) => <T>(xs: T[]) => T[][]
1slidingWindow(2)([1, 2, 3, 4]); 2// ⇒ [[1, 2], [2, 3], [3, 4]]
1slidingWindow(3)([1, 2, 3, 4, 5]); 2// ⇒ [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
1slidingWindow(1)([1, 2, 3, 4, 5, 6]); 2// ⇒ [[1], [2], [3], [4], [5], [6]]
Sorts the given array without mutating it.
1<T>(f?: (a: T, b: T) => number) => (xs: T[]) => T[]
1sort((a, b) => a - b)([13, 79, 20, 69, 44, 67, 18, 95, 26, 55]); 2// ⇒ [13, 18, 20, 26, 44, 55, 67, 69, 79, 95]
Sums the given array of numbers.
1(xs: number[]) => number
1sum([1, 2, 3, 4, 5]); 2// ⇒ 15
Takes up to a given count of elements.
1(count: number) => <T>(xs: T[]) => T[]
1take(2)([1, 2, 3, 4, 5]); 2// ⇒ [1, 2]
1take(10)([1, 2, 3, 4, 5]); 2// ⇒ [1, 2, 3, 4, 5]
Returns unique elements of the given array.
1<T>(xs: T[]) => T[]
1unique([1, 2, 3, 4, 3, 4, 3, 6]); 2// ⇒ [1, 2, 3, 4, 6]
Filters out duplicated values based on the result of the given key selector.
1<T, TResult>(f: (x: T) => TResult) => (xs: T[]) => T[]
1uniqueBy(({ id }) => id)([ 2 { id: 1, value: 'a' }, 3 { id: 2, value: 'b' }, 4 { id: 1, value: 'c' } 5]) 6// ⇒ [{ id: 1, value: 'c' }, { id: 2, value: 'b' }]
Zips the given arrays together into pairs.
1(xs: unknown[], ys: unknown[]) => [unknown, unknown][]
1zip([1, 2, 3], [4, 5, 6]); 2// ⇒ [[1, 4],[2, 5],[3, 6]]
Zips the given arrays together into pairs.
1<T>(...xs: T[][]) => T[][]
1zipN([1, 2, 3], [4, 5, 6]); 2// ⇒ [[1, 4], [2, 5], [3, 6]]
1zipN([1, 2, 3], [4, 5, 6], [7, 8, 9]); 2// ⇒ [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
1zipN([1, 2], [4, 5, 6], [7, 8, 9]); 2// ⇒ [[1, 4, 7],[2, 5, 8]]
Zips the given arrays together with the given function.
1<T1, T2>(f?: (x: T1, y: T2) => [T1, T2]) => (xs: T1[], ys: T2[]) => [T1, T2][]
1zipWith((x, y) => x * x + y)([1, 2, 3], [4, 5, 6]); 2// ⇒ [5, 9, 15]
Makes the function run after the given period of not being called. Useful to delay input submission for auto-complete etc.
1(f: F, wait: number) => (...args: unknown[]) => void
1const f = () => console.log("Test"); 2 3const debounced = debounce(f, 2000); 4 5debounced(); 6setTimeout(debounced, 1000); 7setTimeout(debounced, 3000);
When awaited, delays the execution by the given number of milliseconds.
1(duration: number) => Promise<unknown>
1delay(2000)(() => console.log("Test"));
Runs the given tasks in a sequence.
1<T>(tasks: Task<T>[]) => Promise<Awaited<T>[]>
1const f = () => new Promise(resolve => setTimeout(resolve, 1000)); 2const g = () => new Promise(resolve => setTimeout(resolve, 2000)); 3 4sequence([f, g]).then(() => console.log("Done"));
Clamps the given date to the given date range.
1(min: Date, max: Date) => (date: Date) => Date
1const date = new Date("2019-06-15T13:54:33.232Z"); 2const min = new Date("2019-02-23T13:54:33.232Z"); 3const max = new Date("2019-03-13T13:54:33.232Z"); 4 5clamp(min, max)(date); 6// => new Date("2019-03-13T13:54:33.232Z")
Clones the given Date object.
1(date: Date) => Date
1const date = new new Date("2019-04-24T13:54:33.232Z"); 2const cloned = clone(date); 3 4cloned !== date && cloned.valueOf() === date.valueOf(); 5// ⇒ true
Computes a signed difference between two Date objects as milliseconds.
1(a: Date, b: Date) => number
1dateDiff(new Date("2017-01-01T13:00:00.000Z"), new Date("2017-01-01T12:00:00.000Z")); 2// ⇒ 3600000
Checks if the given date is between the given date range (inclusive).
1(from: Date, to: Date) => (date: Date) => boolean
1dateInRange(new Date("2018-06-10T12:00:00.000Z"), new Date("2018-06-20T12:00:00.000Z"))(new Date("2018-06-15T12:00:00.000Z")); 2// ⇒ true
Returns a local day range at a particular Date.
1(date: Date) => Date[]
1const date = new Date("2018-12-31T13:54:33.232Z"); 2 3dayRange(date); 4// ⇒ [startOfDay(date), endOfDay(date)]
Returns an array of days in a particular months. Number of days in February varies if it is a leap year or not.
1(leapYear: boolean) => [number, number, number, number, number, number, number, number, number, number, number, number]
1daysInMonths(false); 2// ⇒ [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
1daysInMonths(true); 2// ⇒ [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
Calculates the number of days in a particular year. Varies by the leap year.
1(year: number) => 366 | 365
1daysInYear(2019); 2// ⇒ 365
1daysInYear(2020); 2// ⇒ 366
Displays padded time string.
1(source: [number, number, number], showSeconds: boolean) => string
1displayTime([5, 12, 16], false); 2// ⇒ 05:12
1displayTime([5, 12, 16], true); 2// ⇒ 05:12:16
Returns a local Date of an end of the day at a particular Date.
1(date: Date) => Date
1endOfDay(new Date("2018-12-31T13:54:33.232Z")); 2// ⇒ new Date(new Date("2019-01-01T00:00:00.000Z").valueOf() + new Date("2018-12-31T13:54:33.232Z").getTimezoneOffset() * 60 * 1000)
Formats a given date as a simple YYYY-MM-DD string.
1(date: Date) => string
1formatDate(new Date("2019-02-24T01:12:34")); 2// ⇒ "2019-02-24"
Formats a given date as a simple YYYY-MM-DD HH:MM(:SS) string.
1(sourceDate: Date, showSeconds?: boolean) => string
1formatDateTime(new Date("2019-02-24T01:12:34")); 2// ⇒ "2019-02-24 01:12"
1formatDateTime(new Date("2019-02-24T01:12:34"), true); 2// ⇒ "2019-02-24 01:12:34"
Formats a duration in milliseconds to a padded time string.
1(duration: number, showSeconds?: boolean) => string
1formatDuration(26100000); 2// ⇒ 07:15
1formatDuration(26136000, true); 2// ⇒ 07:15:36
Formats a given date as a simple HH:MM(:SS) string.
1(date: Date, showSeconds?: boolean) => string
1formatTime(new Date("2019-02-24T01:12:34")); 2// ⇒ "01:12"
1formatTime(new Date("2019-02-24T01:12:34"), true); 2// ⇒ "01:12:34"
Converts the given day count to milliseconds.
1(days: number) => number
1fromDays(1); 2// ⇒ 86400000
Converts the given hour count to milliseconds.
1(hours: number) => number
1fromHours(1); 2// ⇒ 3600000
Converts the given minute count to milliseconds.
1(minutes: number) => number
1fromMinutes(1); 2// ⇒ 60000
Converts the given second count to milliseconds.
1(seconds: number) => number
1fromSeconds(1); 2// ⇒ 1000
Joins a date-time pair into a date-time string.
1(date: string, time: string) => string
1joinDateTime("2019-01-15", "13:54:33.232Z"); 2// ⇒ "2019-01-15T13:54:33.232Z"
Detects if a given year is a leap year.
1(year: number) => boolean
1leapYear(2020); 2// ⇒ true
1leapYear(2019); 2// ⇒ false
Parses HH:MM string into hours and minutes.
1(text?: string) => [number, number]
1parseHourMinutePair("12:34"); 2// ⇒ [12, 34]
Splits a date-time string into a date-time pair.
1(dateTimeString: string) => [string, string]
1splitDateTime("2019-01-15T13:54:33.232Z"); 2// ⇒ ["2019-01-15", "13:54:33.232Z"]
Returns a local Date of a start of the day at a particular Date.
1(date: Date) => Date
1endOfDay(new Date("2019-01-01T13:54:33.232Z")); 2// ⇒ new Date(new Date("2019-01-01T00:00:00.000Z").valueOf() + new Date("2019-01-01T13:54:33.232Z").getTimezoneOffset() * 60 * 1000)
Subtracts the given number of days from the given Date object.
1(sourceDate: Date, numberOfDays: number) => Date
1subtractDays(new Date("2019-01-15T13:54:33.232Z"), 1); 2// ⇒ new Date("2019-01-14T13:54:33.232Z")
Extracts padded YYYY-MM-DD date string out of the given date object.
1(date: Date) => string
1toDate(new Date("2019-01-15T12:00:00.000Z")); 2// ⇒ "2019-01-15"
Converts the given array of values into Dates using the Date constructor.
1(xs: (string | number | Date)[]) => Date[]
1toDates(["2019-01-15T13:54:33.232Z", new Date("2019-01-15T13:54:33.232Z").valueOf(), new Date("2019-01-15T13:54:33.232Z")]); 2// ⇒ [new Date("2019-01-15T13:54:33.232Z"), new Date("2019-01-15T13:54:33.232Z"), new Date("2019-01-15T13:54:33.232Z")]
Converts milliseconds into days.
1(milliseconds: number) => number
1toDays(86400000); 2// ⇒ 1
Converts milliseconds into hours.
1(milliseconds: number) => number
1toHours(3600000); 2// ⇒ 1
Returns an ISO-compliant date-time string.
1(x: Date) => string
1toISO(new Date("2019-04-24T13:54:33.232Z")); 2// ⇒ "2019-04-24T13:54:33.232Z"
Converts milliseconds into minutes.
1(milliseconds: number) => number
1toMinutes(60000); 2// ⇒ 1
Converts milliseconds into seconds.
1(milliseconds: number) => number
1toSeconds(1000); 2// ⇒ 1
Checks if the given date is present and it is valid.
1(date?: unknown) => boolean
1valid(new Date("2020-01-31T09:52:31.618Z")); 2// ⇒ true
1valid(new Date("2020-01-42:52:31.618Z")); 2// ⇒ false
1valid(new Date("test")); 2// ⇒ false
1valid(undefined); 2// ⇒ false
Asserts given conditions.
1(condition: boolean, callbackOrMessage?: (() => void) | string) => void; 2export declare const throws: (f: () => void) => unknown | undefined; 3export declare const assertNumber: (x?: unknown) => void; 4export declare const assertInteger: (x?: unknown) => void; 5export declare const assertByte: (x?: unknown) => void; 6export declare const assertNormal: (x?: unknown) => void; 7export declare const assertString: (x?: unknown, message?: string) => void; 8export declare const assertIsDefined: (x?: unknown, message?: string) => void; 9export default assert
1assert(true === false); 2// ⇒ TypeError("Assertion failed!")
Computes a deep difference between the two values (primitives, objects, arrays, etc.).
1(obj1?: unknown, obj2?: unknown) => DiffResult; 2export default diff
1diff({ a: 1 }, { a: 2 }); 2// ⇒ { a: { data: [1, 2], type: '~' }}
Decodes the given Base64URL back into a string.
1(text: string, context?: DecodeContext) => string
1decode("PDw_Pz8-Pg"); 2// ⇒ "<<???>>"
Decodes the given Base64URL back into a byte array.
1(text: string, context?: DecodeContext) => number[]
1decodeBytes("w4Jnw6vCp20-bBsQfA"); 2// ⇒ [0xc2, 0x67, 0xeb, 0xa7, 0x6d, 0x3e, 0x6c, 0x1b, 0x10, 0x7c]
Encodes the given string into Base64URL.
1(text: string, context?: EncodeContext) => string
1encode("<<???>>"); 2// ⇒ "PDw_Pz8-Pg"
Encodes the given bytes into Base64URL.
1(bytes: number[], context?: EncodeContext) => string
1encodeBytes([0xc2, 0x67, 0xeb, 0xa7, 0x6d, 0x3e, 0x6c, 0x1b, 0x10, 0x7c]); 2// ⇒ "w4Jnw6vCp20-bBsQfA"
Converts Base64 string into Base64URL one.
1(base64: string) => string
1fromBase64("PDw/Pz8+Pg=="); 2// ⇒ "PDw_Pz8-Pg"
Converts Base64URL string into Base64 one.
1(base64Url: string) => string
1toBase64("PDw_Pz8-Pg"); 2// ⇒ "PDw/Pz8+Pg=="
Converts a string to a byte array.
1(byteString: string) => number[]
1from("PQR"); 2// ⇒ [80, 81, 82]
Coverts a byte array into a string.
1(bytes: number[]) => string
1to([0x50, 0x51, 0x52]); 2// ⇒ "PQR"
Checks if the given string is a valid Windows file name.
1(name: string) => boolean
1validName("my:file.png"); 2// ⇒ false
1validName("file.txt"); 2// ⇒ true
1validName("../file.txt"); 2// ⇒ false
1validName("COM1"); 2// ⇒ false
Composes multiple functions into a higher-order one. Goes right to left.
1<T, TResult>(...fs: ((x: T) => T)[]) => (x: T) => T
1compose(x => x * x, x => x + 1)(3); 2// ⇒ 16
Returns the given constant no matter the input.
1<T>(x: T) => () => T
1constant(3)("anything"); 2// ⇒ 3
Always return the given value.
1<T>(x: T) => T
1identity(5); 2// ⇒ 5
1identity("test"); 2// ⇒ "test"
Memoizes the function result so it is not computed for the same parameters. Uses deep equality.
1<TResult>(f: (...xs: unknown[]) => TResult) => (...args: unknown[]) => TResult
1const f = x => { console.log(x); return x + 1; }; 2 3const memoized = memoize(f); 4 5memoized(5); 6memoized(5); 7memoized(5); 8memoized(3);
Memoizes the function result so it is not computed for the same parameters. Uses shallow equality.
1<TResult>(f: (...xs: unknown[]) => TResult) => (...args: unknown[]) => TResult
1const f = ({ x }) => { console.log(x); return x + 1; }; 2 3const memoized = memoizeShallow(f); 4 5memoized({ x: 5 }); 6memoized({ x: 5 }); 7memoized({ x: 5 }); 8memoized({ x: 3 });
Memoizes the function result so it is not computed for the same parameters. Uses the given equality function.
1<T>(equals: (x: T[], y: T[]) => boolean) => <TResult>(f: (...xs: T[]) => TResult) => (...args: T[]) => TResult
1const f = ({ x }) => { console.log(x); return x + 1; }; 2 3const memoized = memoizeWith((a, b) => a.x === b.x)(f); 4 5memoized({ x: 5 }); 6memoized({ x: 5 }); 7memoized({ x: 5 }); 8memoized({ x: 3 });
It does exactly nothing.
1() => void
1noOp("anything"); 2// ⇒ undefined
Inverts the given function result.
1(f: (...xs: unknown[]) => unknown) => (...args: unknown[]) => boolean
1not(x > 10)(15); 2// ⇒ true
Pipes an input through given functions.
1<T>(...fs: ((x: T) => T)[]) => (x: T) => T
1pipe(x => x * x, x => x + 1)(3); 2// ⇒ 10
Runs the given function only when the condition is met.
1(predicate: (...xs: unknown[]) => boolean) => (action: (...xs: unknown[]) => unknown) => (...args: unknown[]) => unknown
1when(x => x > 0)(x => console.log(x))(5); 2when(x => x > 0)(x => console.log(x))(-3);
Runs the given function only when the condition is exactly true.
1(action: (...xs: unknown[]) => unknown) => (...args: unknown[]) => unknown
1whenTrue(x => console.log(x))(false); 2when(x => x > 0)(x => console.log(x))(true);
Checks if the given argument is an array.
1(x?: unknown) => boolean
1array([1, 2, 3]); 2// ⇒ true
1array({ a: 1 }); 2// ⇒ false
Checks if the given value is a boolean.
1(x?: unknown) => x is boolean
1boolean(false); // ⇒ true
1boolean(1); // ⇒ false
Checks if the given value is a byte.
1(x?: unknown) => boolean
1byte(128); 2// ⇒ true
1byte(325); 2// ⇒ false
1byte(65.5); 2// ⇒ false
Checks if the given value is a Date object.
1(x?: unknown) => boolean
1date(new Date()); 2// ⇒ true
1date(123); 2// ⇒ false
Checks if the given value is defined.
1(x?: unknown) => boolean
1defined(undefined); 2// ⇒ false
1defined(null); 2// ⇒ true
1defined(0); 2// ⇒ true
1defined({ a: 1 }); 2// ⇒ true
Checks if the given value is a function.
1(x?: unknown) => x is Function
1_function(x => x + 5); 2// ⇒ true
Checks if the given value is an integer.
1(x?: unknown) => boolean
1integer(5); 2// ⇒ true
1integer(32.5); 2// ⇒ false
Checks and asserts the given value is not null or undefined.
1<T>(val: T) => val is NonNullable<T>
1nonNullable(null); 2// ⇒ false
1nonNullable(undefined); 2// ⇒ false
1nonNullable(false); 2// ⇒ true
1nonNullable({ a: 1 }); 2// ⇒ true
Checks if the given value is a number in a normal range [0, 1].
1(x?: unknown) => boolean
1normal(0.75); 2// ⇒ true
1normal(-1); 2// ⇒ false
1normal(2.5); 2// ⇒ false
Checks if the given value is a number.
1(x?: unknown) => boolean
1number(0 / 0); 2// ⇒ false
1number(15.6); 2// ⇒ true
Checks if the given value is an object.
1(x?: unknown) => boolean
1object({ a: 1, b: 2 }); 2// ⇒ true
1object([1, 2, 3]); 2// ⇒ false
Checks if the given value is a string.
1(x?: unknown) => x is string
1string("Test"); 2// ⇒ true
1string(['T', 'e', 's', 't']); 2// ⇒ false
Adds two values.
1(a: number, b: number) => number
1add(3, 5); 2// ⇒ 8
Calculates the average of the given array of numbers.
1(xs?: number[]) => number
1average([2, 4, 15]); 2// ⇒ 7
Finds the nearest power of two greater or equal to the given value.
1(x: number) => number
1ceilToNearestPowerOfTwo(345); 2// ⇒ 512
Clamps the given value to the given range.
1(min: number, max: number) => ((x: number) => number)
1clamp(0, 10)(5); 2// ⇒ 5
1clamp(0, 10)(-5); 2// ⇒ 0
1clamp(0, 10)(15); 2// ⇒ 10
Clamps the given value to the [0, 1] range.
1(x: number) => number
1clampNormal(0.5); 2// ⇒ 0.5
1clampNormal(-0.5); 2// ⇒ 0
1clampNormal(1.5); 2// ⇒ 1
Clamps the given value to the [0, 100] range.
1(x: number) => number
1clampPercentage(50); 2// ⇒ 50
1clampPercentage(-50); 2// ⇒ 0
1clampPercentage(150); 2// ⇒ 100
Calculates the absolute distance between given values.
1(a: number, b: number) => number
1delta(-3, 5); 2// ⇒ 8
Checks if the given value is in the rectangular range of [0, width] and [0, height]
1(width: number, height: number) => ((x: number, y: number) => boolean)
1inRectangleRange(50, 100)(25, 50); 2// ⇒ true
1inRectangleRange(50, 100)(-25, 50); 2// ⇒ false
Linearly interpolates two given values by the normal value of their distance.
1(t: number) => ((a: number, b: number) => number)
1lerp(0.5)(0, 10); 2// ⇒ 5
1lerp(0)(0, 10); 2// ⇒ 0
1lerp(1)(0, 10); 2// ⇒ 10
Calculates the maximum by a given selector.
1(f: (x: number) => number) => ((xs: number[]) => number)
1maximumBy(({ age }) => age)([{ age: 13 }, { age: 20 }, { age: 7 }, { age: 18 }]); 2// ⇒ { age: 20 }
Calculates the median of the values. If there is an even number of items, the average of the middle ones is returned.
1(xs?: number[]) => number | undefined
1median([-5, 3, 2, 29, 43]); 2// ⇒ 3
Calculates the minimum and maximum value of the two given values.
1([a, b]: [number, number]) => [number, number]
1minMax([5, 3]); 2// ⇒ [3, 5]
1minMax([3, 5]); 2// ⇒ [3, 5]
Checks if all the given values have the same sign.
1(xs: number[]) => boolean
1sameSign([-1, -2, -3]); 2// ⇒ true
1sameSign([1, 2, -3]); 2// ⇒ false
Calculates the sign of the value and returns -1 for negative values, 1 for positive values and 0 for zeros.
1(x: number) => number
1sign(3); 2// ⇒ 1
1sign(-5); 2// ⇒ 5
1sign(0); 2// ⇒ 0
1sign(-0); 2// ⇒ 0
Calculates the standard deviation of the given array of numbers.
1(xs: number[], origin?: number) => number
1standardDeviation([96, 81, 68, 79, 23, 13, 13, 59, 44, 86]); 2// ⇒ (2 * Math.sqrt(10922 / 5)) / 3
Subtracts two values.
1(a: number, b: number) => number
1subtract(3, 5); 2// ⇒ -2
Checks if the given object is present and it is not empty (contains at least one entry).
1<T>(xs?: GenericObject<T>) => boolean
1any({ a: 1, b: 2, c: 3 }); 2// ⇒ true
1any({ }); 2// ⇒ false
1any(null); 2// ⇒ false
1any(undefined); 2// ⇒ false
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
Found 2/7 approved changesets -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-03-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More