30 seconds of code

Utility

Click on a snippet card to view the snippet.

RGBToHex

Converts the values of RGB components to a color code.

castArray

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

cloneRegExp

Clones a regular expression.

coalesce

Returns the first non-null/undefined argument.

coalesceFactory

Returns a customized coalesce function that returns the first argument that returns true from the provided argument validation function.

extendHex

Extends a 3-digit color code to a 6-digit color code.

getURLParameters

Returns an object containing the parameters of the current URL.

hexToRGB

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

httpGet

Makes a GET request to the passed URL.

httpPost

Makes a POST request to the passed URL.

isBrowser

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

mostPerformant

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

nthArg

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

parseCookie

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

prettyBytes

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

randomHexColorCode

Generates a random hexadecimal color code.

serializeCookie

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

timeTaken

Measures the time taken by a function to execute.

toCurrency

Take a number and return specified currency formatting.

toDecimalMark

toOrdinalSuffix

Adds an ordinal suffix to a number.

validateNumber

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

yesNo

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