Home / Function/ escape() — tailwindcss Function Reference

escape() — tailwindcss Function Reference

Architecture documentation for the escape() function in escape.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  3330a25c_8114_660c_a3c7_8f1aaa37457d["escape()"]
  efac73cf_6ebb_d715_c95b_77e505446ee2["escape.ts"]
  3330a25c_8114_660c_a3c7_8f1aaa37457d -->|defined in| efac73cf_6ebb_d715_c95b_77e505446ee2
  ce18acb2_833c_61a7_166d_0fd7613ce1c0["candidate()"]
  ce18acb2_833c_61a7_166d_0fd7613ce1c0 -->|calls| 3330a25c_8114_660c_a3c7_8f1aaa37457d
  253815a9_405f_ff30_32b6_577fe2d91fb2["migrateTheme()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 3330a25c_8114_660c_a3c7_8f1aaa37457d
  0d11f596_e057_1af5_1569_620f9e160e4b["removeUnnecessarySpacingKeys()"]
  0d11f596_e057_1af5_1569_620f9e160e4b -->|calls| 3330a25c_8114_660c_a3c7_8f1aaa37457d
  bc71102c_3f3f_0a7f_c5dc_2ea1f291aec2["replaceNestedClassNameReferences()"]
  bc71102c_3f3f_0a7f_c5dc_2ea1f291aec2 -->|calls| 3330a25c_8114_660c_a3c7_8f1aaa37457d
  8b088e47_7f37_81e9_fe8a_5da6d3f5e245["compileAstNodes()"]
  8b088e47_7f37_81e9_fe8a_5da6d3f5e245 -->|calls| 3330a25c_8114_660c_a3c7_8f1aaa37457d
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f["parseCss()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| 3330a25c_8114_660c_a3c7_8f1aaa37457d
  86530d3b_8bf7_83f5_43db_f717b3ab4ece["themeKey()"]
  86530d3b_8bf7_83f5_43db_f717b3ab4ece -->|calls| 3330a25c_8114_660c_a3c7_8f1aaa37457d
  style 3330a25c_8114_660c_a3c7_8f1aaa37457d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/utils/escape.ts lines 2–73

export function escape(value: string) {
  if (arguments.length === 0) {
    throw new TypeError('`CSS.escape` requires an argument.')
  }
  let string = String(value)
  let length = string.length
  let index = -1
  let codeUnit: number
  let result = ''
  let firstCodeUnit = string.charCodeAt(0)

  if (
    // If the character is the first character and is a `-` (U+002D), and
    // there is no second character, […]
    length === 1 &&
    firstCodeUnit === 0x002d
  ) {
    return '\\' + string
  }

  while (++index < length) {
    codeUnit = string.charCodeAt(index)
    // Note: there’s no need to special-case astral symbols, surrogate
    // pairs, or lone surrogates.

    // If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
    // (U+FFFD).
    if (codeUnit === 0x0000) {
      result += '\uFFFD'
      continue
    }

    if (
      // If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
      // U+007F, […]
      (codeUnit >= 0x0001 && codeUnit <= 0x001f) ||
      codeUnit === 0x007f ||
      // If the character is the first character and is in the range [0-9]
      // (U+0030 to U+0039), […]
      (index === 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
      // If the character is the second character and is in the range [0-9]
      // (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
      (index === 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit === 0x002d)
    ) {
      // https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
      result += '\\' + codeUnit.toString(16) + ' '
      continue
    }

    // If the character is not handled by one of the above rules and is
    // greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
    // is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
    // U+005A), or [a-z] (U+0061 to U+007A), […]
    if (
      codeUnit >= 0x0080 ||
      codeUnit === 0x002d ||
      codeUnit === 0x005f ||
      (codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
      (codeUnit >= 0x0041 && codeUnit <= 0x005a) ||
      (codeUnit >= 0x0061 && codeUnit <= 0x007a)
    ) {
      // the character itself
      result += string.charAt(index)
      continue
    }

    // Otherwise, the escaped character.
    // https://drafts.csswg.org/cssom/#escape-a-character
    result += '\\' + string.charAt(index)
  }
  return result
}

Domain

Subdomains

Frequently Asked Questions

What does escape() do?
escape() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/utils/escape.ts.
Where is escape() defined?
escape() is defined in packages/tailwindcss/src/utils/escape.ts at line 2.
What calls escape()?
escape() is called by 7 function(s): candidate, compileAstNodes, migrateTheme, parseCss, removeUnnecessarySpacingKeys, replaceNestedClassNameReferences, themeKey.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free