escape.ts — tailwindcss Source File
Architecture documentation for escape.ts, a typescript file in the tailwindcss codebase. 0 imports, 8 dependents.
Entity Profile
Dependency Diagram
graph LR e28f6b6c_be9a_6950_8075_180c1b66f0ea["escape.ts"] 9ffd1dda_9675_c514_373d_0f4ab4648249["utils.ts"] 9ffd1dda_9675_c514_373d_0f4ab4648249 --> e28f6b6c_be9a_6950_8075_180c1b66f0ea b2ba3368_7330_fe20_4543_9cafa8cfedc0["migrate-js-config.ts"] b2ba3368_7330_fe20_4543_9cafa8cfedc0 --> e28f6b6c_be9a_6950_8075_180c1b66f0ea af1a6ece_0432_a556_fd63_8cb4a91f12ad["plugin-api.ts"] af1a6ece_0432_a556_fd63_8cb4a91f12ad --> e28f6b6c_be9a_6950_8075_180c1b66f0ea 20b59de8_11c6_2432_2a83_24f6f6e741a7["plugin-functions.ts"] 20b59de8_11c6_2432_2a83_24f6f6e741a7 --> e28f6b6c_be9a_6950_8075_180c1b66f0ea 214bac69_e516_bea4_67fa_4e9e092ced3b["compile.ts"] 214bac69_e516_bea4_67fa_4e9e092ced3b --> e28f6b6c_be9a_6950_8075_180c1b66f0ea 5af9cd3c_2cf4_9dee_376e_fc39122d865a["index.ts"] 5af9cd3c_2cf4_9dee_376e_fc39122d865a --> e28f6b6c_be9a_6950_8075_180c1b66f0ea 80295787_127f_69e6_91b3_4bea3a484544["theme.ts"] 80295787_127f_69e6_91b3_4bea3a484544 --> e28f6b6c_be9a_6950_8075_180c1b66f0ea f662ccb7_32df_9b06_8d56_d9c470c48229["escape.test.ts"] f662ccb7_32df_9b06_8d56_d9c470c48229 --> e28f6b6c_be9a_6950_8075_180c1b66f0ea style e28f6b6c_be9a_6950_8075_180c1b66f0ea fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
// https://drafts.csswg.org/cssom/#serialize-an-identifier
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
}
export function unescape(escaped: string) {
return escaped.replace(/\\([\dA-Fa-f]{1,6}[\t\n\f\r ]?|[\S\s])/g, (match) => {
return match.length > 2
? String.fromCodePoint(Number.parseInt(match.slice(1).trim(), 16))
: match[1]
})
}
Domain
Subdomains
Functions
Imported By
- packages/tailwindcss/src/compile.ts
- packages/tailwindcss/src/utils/escape.test.ts
- packages/tailwindcss/src/index.ts
- packages/@tailwindcss-upgrade/src/codemods/config/migrate-js-config.ts
- packages/tailwindcss/src/compat/plugin-api.ts
- packages/tailwindcss/src/compat/plugin-functions.ts
- packages/tailwindcss/src/theme.ts
- integrations/utils.ts
Source
Frequently Asked Questions
What does escape.ts do?
escape.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the UpgradeToolkit domain, TemplateAnalysis subdomain.
What functions are defined in escape.ts?
escape.ts defines 2 function(s): escape, unescape.
What files import escape.ts?
escape.ts is imported by 8 file(s): compile.ts, escape.test.ts, index.ts, migrate-js-config.ts, plugin-api.ts, plugin-functions.ts, theme.ts, utils.ts.
Where is escape.ts in the architecture?
escape.ts is located at packages/tailwindcss/src/utils/escape.ts (domain: UpgradeToolkit, subdomain: TemplateAnalysis, directory: packages/tailwindcss/src/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free