segment() — tailwindcss Function Reference
Architecture documentation for the segment() function in segment.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment()"] bb9924cc_8308_a1f9_0e30_76de45a64970["segment.ts"] c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 -->|defined in| bb9924cc_8308_a1f9_0e30_76de45a64970 6d7d3a7a_08dc_88e4_0b4a_9f563d66e582["analyze()"] 6d7d3a7a_08dc_88e4_0b4a_9f563d66e582 -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 6d8d6d7e_6e94_511f_8419_616e12ba69b8["migrateAtApply()"] 6d8d6d7e_6e94_511f_8419_616e12ba69b8 -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 9456daf3_1cee_2ab1_7f06_8dc2cedc967a["migrateAtLayerUtilities()"] 9456daf3_1cee_2ab1_7f06_8dc2cedc967a -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 3c115506_d301_3ffd_6d4a_a58dbd7aaed5["migrateImport()"] 3c115506_d301_3ffd_6d4a_a58dbd7aaed5 -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 59c8138d_8a81_f8cc_a0c2_1066cae6363b["migrateMissingLayers()"] 59c8138d_8a81_f8cc_a0c2_1066cae6363b -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 a8ebd8e1_4e38_4a06_28e7_e26261806723["migrateLegacyArbitraryValues()"] a8ebd8e1_4e38_4a06_28e7_e26261806723 -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 a5786cf3_5b2e_711a_6639_a1d182cf427d["extractV3Base()"] a5786cf3_5b2e_711a_6639_a1d182cf427d -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 f1c7fb37_4a69_f6f5_b7f4_9f3d8b534c40["createConverter()"] f1c7fb37_4a69_f6f5_b7f4_9f3d8b534c40 -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 7ad9d996_c0ff_47f5_d131_ab2ead06506e["substituteAtApply()"] 7ad9d996_c0ff_47f5_d131_ab2ead06506e -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 7d328a86_10c6_b5c1_6390_36f4fffe9c14["parseCandidate()"] 7d328a86_10c6_b5c1_6390_36f4fffe9c14 -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 5719096b_0f51_ab16_7fbd_4455f835804c["parseVariant()"] 5719096b_0f51_ab16_7fbd_4455f835804c -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 fd4a6387_6427_eb54_6f14_abd89a3baf61["collapseCandidates()"] fd4a6387_6427_eb54_6f14_abd89a3baf61 -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 7f0ac26e_d200_2f14_4236_46ff9eed21ef["createConverterCache()"] 7f0ac26e_d200_2f14_4236_46ff9eed21ef -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 style c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 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