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.

  • Same-origin URLs

    JavaScript, Object

    Checks if two URLs are on the same origin.

  • Value is string

    JavaScript, Type

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

  • Pad number

    JavaScript, String

    Pads a given number to the specified length.

  • Rounds a number to a specified amount of digits.

  • Array union

    JavaScript, Array

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

  • Validate number

    JavaScript, Math

    Checks if the given value is a number.

  • Binary function arity

    JavaScript, Function

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

  • Clamp number

    JavaScript, Math

    Clamps num within the inclusive range specified by the boundary values a and b.

  • Clone RegExp

    JavaScript, Type

    Clones a regular expression.

  • Logical complement

    JavaScript, Function

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

  • Copy sign to number

    JavaScript, Math

    Returns the absolute value of the first number, but the sign of the second.

  • Logical or for functions

    JavaScript, Function

    Checks if at least one function returns true for a given set of arguments.

  • Checks if the parent element contains the child element.

  • Checks if the element specified is visible in the viewport.

  • Toggle fullscreen mode

    JavaScript, Browser

    Opens or closes an element in fullscreen mode.