segment() — tailwindcss Function Reference
Architecture documentation for the segment() function in segment.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD f712ed47_45d4_4e5a_dd73_fdefa1da71da["segment()"] ef204000_8998_5a6c_5455_324b37624713["segment.ts"] f712ed47_45d4_4e5a_dd73_fdefa1da71da -->|defined in| ef204000_8998_5a6c_5455_324b37624713 60cad534_12fe_6e72_4bc7_443aad14536b["analyze()"] 60cad534_12fe_6e72_4bc7_443aad14536b -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da 66e0bbad_4b95_c393_4a95_0a694140aecd["migrateAtApply()"] 66e0bbad_4b95_c393_4a95_0a694140aecd -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da a0235ccd_65fd_a71a_fafb_d79570dbb04c["migrateAtLayerUtilities()"] a0235ccd_65fd_a71a_fafb_d79570dbb04c -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da d0429f7e_c0b8_e2df_15f9_96e807ee2d3a["migrateImport()"] d0429f7e_c0b8_e2df_15f9_96e807ee2d3a -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da 7bb0e1ac_e34f_8717_7c79_c91f3f7b81f2["migrateMissingLayers()"] 7bb0e1ac_e34f_8717_7c79_c91f3f7b81f2 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da 2d17c912_6324_fc2c_8ab3_065595647555["migrateLegacyArbitraryValues()"] 2d17c912_6324_fc2c_8ab3_065595647555 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da 140850c7_e088_0df8_4c28_edc0207aa6e0["extractV3Base()"] 140850c7_e088_0df8_4c28_edc0207aa6e0 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da dc9585e4_0c18_e5de_1302_9b707f3ab6ed["createConverter()"] dc9585e4_0c18_e5de_1302_9b707f3ab6ed -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da 96876152_5423_5f9b_9f88_1db666070351["substituteAtApply()"] 96876152_5423_5f9b_9f88_1db666070351 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da d4b90da0_01b5_b21d_ff05_b37798744576["parseCandidate()"] d4b90da0_01b5_b21d_ff05_b37798744576 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da 7ba77268_84c7_7083_8f22_251a4a791d25["parseVariant()"] 7ba77268_84c7_7083_8f22_251a4a791d25 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da 6b36dfc9_f213_8083_55ea_8d0541032f05["collapseCandidates()"] 6b36dfc9_f213_8083_55ea_8d0541032f05 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da 77acef4a_feff_6e9f_7c6b_2b6942c9ad63["createConverterCache()"] 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da style f712ed47_45d4_4e5a_dd73_fdefa1da71da 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
Defined In
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, defined in packages/tailwindcss/src/utils/segment.ts.
Where is segment() defined?
segment() is defined in packages/tailwindcss/src/utils/segment.ts at line 29.
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