JavaScript String 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.

  • Encode string to Base64

    JavaScript, Node

    Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data.

  • Capitalize every word

    JavaScript, String

    Capitalizes the first letter of every word in a string.

  • Escape RegExp

    JavaScript, String

    Escapes a string to use in a regular expression.

  • Expand tabs into spaces

    JavaScript, String

    Convert tabs to spaces, where each tab corresponds to count spaces.

  • Check if absolute URL

    JavaScript, String

    Checks if the given string is an absolute URL.

  • String is alphanumeric

    JavaScript, String

    Checks if a string contains only alphanumeric characters.

  • Normalize line endings

    JavaScript, String

    Normalizes line endings in a string.

  • Strip HTML tags

    JavaScript, String

    Removes HTML/XML tags from string.

  • Byte size of string

    JavaScript, String

    Returns the length of a string in bytes.

  • String is alpha

    JavaScript, String

    Checks if a string contains only alpha characters.

  • Mask a value

    JavaScript, String

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

  • Convert to absolute path

    JavaScript, Node

    Converts a tilde path to an absolute path.

  • Checks if the given string contains any whitespace characters.

  • Pad string

    JavaScript, String

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

  • Serialize cookie

    JavaScript, Browser

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