segment() — tailwindcss Function Reference
Architecture documentation for the segment() function in segment.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 2a20ea29_c850_cd61_5600_aeebbe3dda66["segment()"] 4d72f15c_1184_4396_0a3a_6a120fe36ae0["analyze()"] 4d72f15c_1184_4396_0a3a_6a120fe36ae0 -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 03d4ca08_7ec2_689c_47d8_1be20f931aa5["migrateAtApply()"] 03d4ca08_7ec2_689c_47d8_1be20f931aa5 -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 2ec0ecaf_3c01_fcc3_d0f0_05dbeae5f6e0["migrateAtLayerUtilities()"] 2ec0ecaf_3c01_fcc3_d0f0_05dbeae5f6e0 -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 22885c03_eded_5619_af73_329b957dad5a["migrateImport()"] 22885c03_eded_5619_af73_329b957dad5a -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 750de917_02a7_4958_9148_77485207558a["migrateMissingLayers()"] 750de917_02a7_4958_9148_77485207558a -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 e186eef0_e5f2_5d47_3825_19ab57be2de9["migrateLegacyArbitraryValues()"] e186eef0_e5f2_5d47_3825_19ab57be2de9 -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 c9435653_47da_ca15_e937_6532e96367aa["extractV3Base()"] c9435653_47da_ca15_e937_6532e96367aa -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 da84d4b5_fc28_e826_1855_2340e6df074e["createConverter()"] da84d4b5_fc28_e826_1855_2340e6df074e -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 5f3acb43_b93f_4293_caaa_25ba26d38178["substituteAtApply()"] 5f3acb43_b93f_4293_caaa_25ba26d38178 -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 53cf41fe_5903_d247_3bb3_38414ba7d631["parseCandidate()"] 53cf41fe_5903_d247_3bb3_38414ba7d631 -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 ca76ae68_c9c0_d977_a6d8_8ba86685bf25["parseVariant()"] ca76ae68_c9c0_d977_a6d8_8ba86685bf25 -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 71b68838_221b_7f75_2376_3e23d6c37929["collapseCandidates()"] 71b68838_221b_7f75_2376_3e23d6c37929 -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 3a7318a6_ec18_9d9c_0667_804b7d2f542d["createConverterCache()"] 3a7318a6_ec18_9d9c_0667_804b7d2f542d -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 501c79ac_a9e3_eaff_6439_702972cbae47["arbitraryValueToBareValueVariant()"] 501c79ac_a9e3_eaff_6439_702972cbae47 -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66 style 2a20ea29_c850_cd61_5600_aeebbe3dda66 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