escape() — tailwindcss Function Reference
Architecture documentation for the escape() function in escape.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 433dc479_0296_0a89_fd12_79fc4ea2b8bd["escape()"] e28f6b6c_be9a_6950_8075_180c1b66f0ea["escape.ts"] 433dc479_0296_0a89_fd12_79fc4ea2b8bd -->|defined in| e28f6b6c_be9a_6950_8075_180c1b66f0ea b7531519_9055_fbfa_5f69_ebc8586b0422["candidate()"] b7531519_9055_fbfa_5f69_ebc8586b0422 -->|calls| 433dc479_0296_0a89_fd12_79fc4ea2b8bd e26bfad3_530e_6523_7463_161205321110["migrateTheme()"] e26bfad3_530e_6523_7463_161205321110 -->|calls| 433dc479_0296_0a89_fd12_79fc4ea2b8bd b28200b3_b5d3_7858_38e3_b07a399f3495["removeUnnecessarySpacingKeys()"] b28200b3_b5d3_7858_38e3_b07a399f3495 -->|calls| 433dc479_0296_0a89_fd12_79fc4ea2b8bd a0e7559e_bcba_7de4_f51b_c146c7957bfd["replaceNestedClassNameReferences()"] a0e7559e_bcba_7de4_f51b_c146c7957bfd -->|calls| 433dc479_0296_0a89_fd12_79fc4ea2b8bd e57db502_ed4e_4f14_1b2a_b25af3c0477d["compileAstNodes()"] e57db502_ed4e_4f14_1b2a_b25af3c0477d -->|calls| 433dc479_0296_0a89_fd12_79fc4ea2b8bd 3970218d_3d6c_e455_87cc_45b4a094f0e9["parseCss()"] 3970218d_3d6c_e455_87cc_45b4a094f0e9 -->|calls| 433dc479_0296_0a89_fd12_79fc4ea2b8bd 93293d0f_8972_0a6a_eb24_f17846e7cfae["themeKey()"] 93293d0f_8972_0a6a_eb24_f17846e7cfae -->|calls| 433dc479_0296_0a89_fd12_79fc4ea2b8bd style 433dc479_0296_0a89_fd12_79fc4ea2b8bd 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
Defined In
Called By
Source
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