segment() — tailwindcss Function Reference
Architecture documentation for the segment() function in segment.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 03b8d706_a876_a776_0056_186ced5d6067["segment()"] 6a659766_1d3a_b133_2d7b_62f11f4e9450["analyze()"] 6a659766_1d3a_b133_2d7b_62f11f4e9450 -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 d42d902c_ed1a_408e_b745_e2810d7e1b4b["migrateAtApply()"] d42d902c_ed1a_408e_b745_e2810d7e1b4b -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 f57a23db_2b42_5741_b08b_f818729aad91["migrateAtLayerUtilities()"] f57a23db_2b42_5741_b08b_f818729aad91 -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 6dee7bcb_2b1c_cd79_688e_3f0f0ce8ea8f["migrateImport()"] 6dee7bcb_2b1c_cd79_688e_3f0f0ce8ea8f -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 f75d1fa5_ba0d_e52d_fd05_1915da788b5c["migrateMissingLayers()"] f75d1fa5_ba0d_e52d_fd05_1915da788b5c -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 c54c0b46_6508_253f_e6ff_d96bcc4246d5["migrateLegacyArbitraryValues()"] c54c0b46_6508_253f_e6ff_d96bcc4246d5 -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 67093833_9187_af4f_e028_9ac2a45069f5["extractV3Base()"] 67093833_9187_af4f_e028_9ac2a45069f5 -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 a5e6dda1_40ba_a775_d007_2d6576a30911["createConverter()"] a5e6dda1_40ba_a775_d007_2d6576a30911 -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 556f6ab2_af7d_ed90_84f0_6b49e632571a["substituteAtApply()"] 556f6ab2_af7d_ed90_84f0_6b49e632571a -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 0bec5ca9_74c8_dcc7_ec12_6404fb6493bd["parseCandidate()"] 0bec5ca9_74c8_dcc7_ec12_6404fb6493bd -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 ceb1ff41_a641_27dd_6289_7f779710b411["parseVariant()"] ceb1ff41_a641_27dd_6289_7f779710b411 -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 830bd29f_3420_9239_4bdf_20fd57106bdf["collapseCandidates()"] 830bd29f_3420_9239_4bdf_20fd57106bdf -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 c11e076e_d776_4d2a_acbf_702c1e172792["createConverterCache()"] c11e076e_d776_4d2a_acbf_702c1e172792 -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 cd080430_2569_72ec_53e4_15be9f1a9c2a["arbitraryValueToBareValueVariant()"] cd080430_2569_72ec_53e4_15be9f1a9c2a -->|calls| 03b8d706_a876_a776_0056_186ced5d6067 style 03b8d706_a876_a776_0056_186ced5d6067 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/utils/segment.ts lines 29–102
export function segment(input: string, separator: string) {
// SAFETY: We can use an index into a shared buffer because this function is
// synchronous, non-recursive, and runs in a single-threaded environment.
let stackPos = 0
let parts: string[] = []
let lastPos = 0
let len = input.length
let separatorCode = separator.charCodeAt(0)
for (let idx = 0; idx < len; idx++) {
let char = input.charCodeAt(idx)
if (stackPos === 0 && char === separatorCode) {
parts.push(input.slice(lastPos, idx))
lastPos = idx + 1
continue
}
switch (char) {
case BACKSLASH:
// The next character is escaped, so we skip it.
idx += 1
break
// Strings should be handled as-is until the end of the string. No need to
// worry about balancing parens, brackets, or curlies inside a string.
case SINGLE_QUOTE:
case DOUBLE_QUOTE:
// Ensure we don't go out of bounds.
while (++idx < len) {
let nextChar = input.charCodeAt(idx)
// The next character is escaped, so we skip it.
if (nextChar === BACKSLASH) {
idx += 1
continue
}
if (nextChar === char) {
break
}
}
break
case OPEN_PAREN:
closingBracketStack[stackPos] = CLOSE_PAREN
stackPos++
break
case OPEN_BRACKET:
closingBracketStack[stackPos] = CLOSE_BRACKET
stackPos++
break
case OPEN_CURLY:
closingBracketStack[stackPos] = CLOSE_CURLY
stackPos++
break
case CLOSE_BRACKET:
case CLOSE_CURLY:
case CLOSE_PAREN:
if (stackPos > 0 && char === closingBracketStack[stackPos - 1]) {
// SAFETY: The buffer does not need to be mutated because the stack is
// only ever read from or written to its current position. Its current
// position is only ever incremented after writing to it. Meaning that
// the buffer can be dirty for the next use and still be correct since
// reading/writing always starts at position `0`.
stackPos--
}
break
}
}
parts.push(input.slice(lastPos))
return parts
}
Domain
Subdomains
Called By
- alpha()
- alphaReplacedDropShadowProperties()
- alphaReplacedShadowProperties()
- analyze()
- applyCompatibilityHooks()
- arbitraryValueToBareValueVariant()
- bareAspectRatio()
- buildPluginApi()
- collapseCandidates()
- createConverter()
- createConverterCache()
- createCssUtility()
- createVariants()
- expand()
- expandDeclaration()
- extractV3Base()
- getPropertyValue()
- isBackgroundPosition()
- isBackgroundSize()
- isFamilyName()
- isImage()
- isLineWidth()
- migrateAtApply()
- migrateAtLayerUtilities()
- migrateImport()
- migrateLegacyArbitraryValues()
- migrateMissingLayers()
- parseCandidate()
- parseCss()
- parseThemeOptions()
- parseVariant()
- quoteAttributeValue()
- registerLegacyUtilities()
- render()
- replaceShadowColors()
- resolveValueFunction()
- substituteAtApply()
- substituteFunctionsInValue()
- toKeyPath()
Source
Frequently Asked Questions
What does segment() do?
segment() is a function in the tailwindcss codebase.
What calls segment()?
segment() is called by 39 function(s): alpha, alphaReplacedDropShadowProperties, alphaReplacedShadowProperties, analyze, applyCompatibilityHooks, arbitraryValueToBareValueVariant, bareAspectRatio, buildPluginApi, and 31 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free