Skip to main content
Deno 2 is finally here 🎉️
Learn more
import * as 30SecondsOfTypescript from "https://deno.land/x/30_seconds_of_typescript@v1.0.1/util.ts";

Variables

Returns an array of partial sums. Use Array.prototype.reduce(), Array.prototype.slice(-1) and the unary + operator to add each value to the unary array containing the previous sum.

Returns true if the provided predicate function returns true for all elements in a collection, false otherwise.

Check if all elements in an array are equal.

Returns true if both arguments are true, false otherwise.

Returns true if the provided predicate function returns true for at least one element in a collection, false otherwise. Use Array.prototype.some() to test if any elements in the collection return true based on fn. Omit the second argument, fn, to use Boolean as a default.

Returns an array of n-tuples of consecutive elements.

Checks if two numbers are approximately equal to each other.

Converts a 2D array to a comma-separated values (CSV) string.

Converts the given array elements into <li> tags and appends them to the list of the given id. Use Array.prototype.map(), document.querySelector(), and an anonymous inner closure to create a list of html tags.

Creates a function that accepts up to n arguments, ignoring any additional arguments.

Attempts to invoke a function with the provided arguments, returning either the result or the caught error object.

Attempts to invoke a function with the provided arguments, returning either the result or the caught error object.

Returns the average of two or more numbers.

Splits values into two groups. If an element in filter is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.

Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group.

Creates a function that accepts up to two arguments, ignoring any additional arguments. Call the provided function, fn, with the first two arguments given.

Creates a function that invokes fn with a given context, optionally adding any additional supplied parameters to the beginning of the arguments.

Binds methods of an object to the object itself, overwriting the existing method Use Array.prototype.forEach() to return a function that uses Function.prototype.apply() to apply the given context (obj) to fn for each function specified.

Evaluates the binomial coefficient of two integers n and k.

Returns true if both functions return true for a given set of arguments, false otherwise. Use the logical and (&&) operator on the result of calling the two functions with the supplied args.

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Capitalizes the first letter of a string.

Capitalizes the first letter of every word in a string. Use String.prototype.replace() to match the first character of each word and String.prototype.toUpperCase() to capitalize it.

Casts the provided value as an array if it's not one.

Converts Celsius to Fahrenheit. Follows the conversion formula F = 1.8C + 32.

Chunks an array into smaller arrays of a specified size.

Add special characters to text to print in color in the console (combined with console.log()).

Add special characters to text to print in color in the console (combined with console.log()).

Removes falsy values from an array. Use Array.prototype.filter() to filter out falsy values (false, null, 0, "", undefined, and NaN).

Returns a string with whitespaces compacted. Use String.prototype.replace() with a regular expression to replace all occurrences of 2 or more whitespace characters with a single space.

Returns a function that is the logical complement of the given function, fn.

Performs right-to-left function composition.

Performs left-to-right function composition.

Returns true if given string s1 contains s2. Compare is case insensitive.

Returns true if the given string contains any whitespace characters, false otherwise.

Groups the elements of an array based on the given function and returns the count of elements in each group.

Counts the occurrences of a value in an array.

Creates an element from a string (without appending it to the document). if the given string contains multiple elements, only the first one will be returned.

Creates a pub/sub (publish–subscribe) event hub with emit, on, and off methods.

Converts a comma-separated values (CSV) string to a 2D array.

Curries a function.

dayOfYear: Gets the day of the year from a Date object.

Creates a debounced function that delays invoking the provided function until at least ms milliseconds have elapsed since the last time it was invoked.

Creates a deep clone of an object.

Performs a deep comparison between two values to determine if they are equivalent. Same as equals, but without type check

Deep flattens an array.

Deep freezes an object.

Returns the target value in a nested JSON object, based on the keys array.

Assigns default values for all properties in an object that are undefined.

Invokes the provided function after wait milliseconds.

Return a promise, Resolve after wait milliseconds.

Convert array(csv) string to doanloadable file

Returns true if at least one function returns true for a given set of arguments, false otherwise.

ellipsis a string up to a specified length.

Performs a deep comparison between two values to determine if they are equivalent.

Escapes a string for use in HTML.

Escapes a string to use in a regular expression.

Calculates the factorial of a number.

Converts Fahrenheit to Celsius.

Initializes and fills an array with the specified values.

Filters out the non-unique values in an array.

Filters out the non-unique values in an array, based on a provided comparator function.

Returns the first key that satisfies the provided testing function. Otherwise undefined is returned.

Flattens an array up to the specified depth.

Executes a provided function once for each array element, starting from the array's last element.

Returns the human readable format of the given number of milliseconds.

Retrieve a set of properties indicated by the given selectors from an object.

Retrieve a set of properties indicated by the given selectors(string[]) from an object.

Returns the current URL without any parameters. Use String.prototype.indexOf() to check if the given url has parameters, String.prototype.slice() to remove them if necessary.

Returns the native type of a value.

Groups the elements of an array based on the given function.

Check if the current arguments contain the specified flags.

Converts a color code to a rgb() or rgba() string if alpha value is provided.

Converts a color code to a rgb() or rgba() string if alpha value is provided.

Hides all the elements specified.

Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history.

Converts a string to humanize string url

Returns true if all the elements in values are included in arr, false otherwise.

Indents each line in the provided string.

Initializes and fills an array with the specified values.

Checks if the given number | Date | string falls within the given range.

Mutates the original array to insert the given values at the specified index.

Insert the given values at the specified index.

Returns a list of elements that exist in both arrays.

Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both.

Returns a list of elements that exist in both arrays, using a provided comparator function.

Check if a date is after another date.

Checks if the given argument is a array like

Check if a date is before another date.

Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors.

Returns true if the a value is an empty object, collection, has no enumerable properties or is any type that is not considered a collection.

Checks if the given argument is a string. Only works for string primitives.

Returns true if the given year is a leap year, false otherwise.

Checks if a string is lower case.

Returns true if the specified value is null or undefined, false otherwise.

Returns true if the specified value is null, false otherwise.

Checks if the given argument is a number.

Returns a boolean determining if the passed value is an object or not.

Checks if the provided value is an object created by the Object constructor.

Returns a boolean determining if the passed value is primitive or not.

Check if a date is the same as another date.

Returns 1 if the array is sorted in ascending order, -1 if it is sorted in descending order or 0 if it is not sorted.

Checks if the given argument is a string. Only works for string primitives.

Checks if a string is upper case.

Checks if the provided string is a valid JSON.

Converts an array of objects to a comma-separated values (CSV) string that contains only the columns specified.

Returns the last element in an array.

Adds an event listener to an element that will only run the callback the first time the event is triggered.

Creates a new object from the specified object, where all the keys are in lowercase.

Creates a new map with the results of calling a provided function on every value in the calling function.

Creates an object with keys generated by running the provided function for each key and the same values as the provided object.

Maps the values of an array to an object using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value.

Creates a new string with the results of calling a provided function on every character in the calling string.

Replaces all but the last num of characters with the specified mask character.

Compares two objects to determine if the first one contains equivalent property values to the second one.

Compares two objects to determine if the first one contains equivalent property values to the second one, based on a provided function.

Returns the maximum value of an array, after mapping each element to a value using the provided function.

Returns the maximum of the given dates.

Returns the n maximum elements from the provided array. If n is greater than or equal to the provided array's length, then return the original array (sorted in descending order).

Returns the memoized (cached) function.

Creates a new object from the combination of two or more objects.

Returns the minimum value of an array, after mapping each element to a value using the provided function.

Returns the most frequent element in an array.

Returns the index of the function in an array of functions which executed the fastest.

Negates a predicate function.

Given a flat array of objects linked to one another, it will nest them recursively. Useful for nesting comments, such as the ones on reddit.com.

Converts a NodeList to an array.

Returns true if the provided predicate function returns false for all elements in a collection, false otherwise.

Returns the logical inverse of the given value.

Creates a function that gets the argument at index n. If n is negative, the nth argument from the end is returned.

Returns a query string generated from the key-value pairs of the given object.

Moves the specified amount of elements to the end of the array.

Omits the key-value pairs corresponding to the given keys from an object.

Creates an object composed of the properties the given function returns falsy for. The function is invoked with two arguments: (value, key).

Returns true if at least one of the arguments is true, false otherwise.

Returns a sorted array of objects ordered by properties and orders.

Returns a sorted array of objects ordered by properties and orders.

Pads a string on both sides with the specified character, if it's shorter than the specified length.

Parse an HTTP Cookie header string and return an object of all cookie name-value pairs.

Creates a function that invokes fn with partials prepended to the arguments it receives.

Creates a function that invokes fn with partials appended to the arguments it receives.

Groups the elements into two arrays, depending on the provided function's truthiness for each element.

Applies fn to each value in arr, splitting it each time fn returns a new value.

Picks the key-value pairs corresponding to the given keys from an object.

Creates an object composed of the properties the given function returns truthy for. The function is invoked with two arguments: (value, key).

Performs left-to-right function composition.

Returns the singular or plural form of the word based on the input number.

Returns the prefixed version (if necessary) of a CSS property that the browser supports.

Converts a number in bytes to a human-readable string.

Template String funtion, Same as prettyBytes but more cleaner way

Converts an asynchronous function to return a promise.

Converts an angle from radians to degrees.

Generates a random hexadecimal color code.

Returns a random integer in the specified range.

Returns a random number in the specified range.

Returns the minimum/maximum value of an array, after applying the provided function to set comparing rule.

Removes non-printable ASCII characters.

Renders the given DOM tree in the specified DOM element.

Reverses a string.

Converts the values of RGB components to a color code.

Rounds a number to a specified amount of digits.

Smooth-scrolls to the top of the page.

Serialize a cookie name-value pair into a Set-Cookie header string.

Shows all the elements specified.

Randomizes the order of the values of an array, returning a new array.

Gets the size of an array, object or string.

Delays the execution of an asynchronous function.

Same as any

Sort by based on the key.

Splits a multiline string into an array of lines.

Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.

Performs stable sorting of an array, preserving the initial indexes of items when their values are the same. Does not mutate the original array, but returns a new array instead.

Removes HTML/XML tags from string.

Returns the sum of two or more numbers/arrays.

Returns the sum of an array, after mapping each element to a value using the provided function.

Returns all elements in an array except for the first one.

Returns an array with n elements removed from the beginning.

Returns an array with n elements removed from the end.

Removes elements from the end of an array until the passed function returns true. Returns the removed elements.

Removes elements in an array until the passed function returns true. Returns the removed elements.

Iterates over a callback n times

Measures the time taken by a function to execute.

Converts a ArrayLike to an array.

Converts a string to camelcase.

Converts a number to a decimal mark formatted string.

Converts a string to kebab case.

Adds an ordinal suffix to a number.

Creates an array of key-value pair arrays from an object or other iterable (object, array, string, set etc.).

Break the string into words and combine them adding _ as a separator, using a regexp.

Converts a string to title case.

Applies a function against an accumulator and each key in the object (from left to right).

Triggers a specific event on a given element, optionally passing custom data.

Truncates a string up to a specified length.

Creates a function that accepts up to one argument, ignoring any additional arguments.

Uncurries a function up to depth n.

Unescapes escaped HTML characters.

Returns every element that exists in any of the two arrays once.

Returns every element that exists in any of the two arrays once, after applying the provided function to each array element of both.

Returns all unique values in an array.

Returns all unique values of an array, based on a provided comparator function.

Returns all unique values of an array, based on a provided comparator function, starting from the right.

Creates an array of arrays, ungrouping the elements in an array produced by zip.

Creates an array of elements, ungrouping the elements in an array produced by zip and applying the provided function.

Joins all given URL segments together, then normalizes the resulting URL.

Joins all given URL segments together, then normalizes the resulting URL.

Generates a UUID in a browser.

Returns true if the given value is a number, false otherwise.

Returns true if the string is y/yes or false if the string is n/no.

Functions

Validate date