JavaScript Snippets

The JavaScript snippet collection contains a wide variety of ES6 helper functions. It includes helpers for dealing with primitives, arrays and objects, as well as algorithms, DOM manipulation functions and Node.js utilities.

  • formatDuration

    JavaScript, Date

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

  • getURLParameters

    JavaScript, Browser

    Creates an object containing the parameters of the current URL.

  • copyToClipboard

    JavaScript, Browser

    Copies a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).

  • indexOfSubstrings

    JavaScript, String

    Finds all the indexes of a substring in a given string.

  • JSONtoCSV

    JavaScript, Array

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

  • toHSLObject

    JavaScript, String

    Converts an hsl() color string to an object with the values of each color.

  • toRGBObject

    JavaScript, String

    Converts an rgb() color string to an object with the values of each color.

  • Learn how to use the JavaScript ES6 spread syntax to converting iterables to arrays and level up your code today.

  • changeLightness

    JavaScript, String

    Changes the lightness value of an hsl() color string.

  • CSVToJSON

    JavaScript, String

    Converts a comma-separated values (CSV) string to a 2D array of objects. The first row of the string is used as the title row.

  • parseCookie

    JavaScript, Browser

    Parses an HTTP Cookie header string, returning an object of all cookie name-value pairs.

  • serializeForm

    JavaScript, Browser

    Encodes a set of form elements as a query string.

  • caesarCipher

    JavaScript, Algorithm

    Encrypts or decrypts a given string using the Caesar cipher.

  • formatSeconds

    JavaScript, Date

    Returns the ISO format of the given number of seconds.

  • escapeHTML

    JavaScript, String

    Escapes a string for use in HTML.