@hyperfrontend/project-scope/core/platformplatform
Operating system detection and platform-specific normalization for filesystem case sensitivity and line endings.
detectPlatform, getPlatformInfo, and isWindows classify the host OS; isCaseSensitiveFs and detectCaseSensitivity decide whether path comparisons must be case-aware (POSIX) or case-insensitive (Windows/macOS HFS+). Line-ending helpers (detectLineEnding, getLineEnding, normalizeLineEndings, plus LF/CRLF constants) let writers convert content to a consistent style before commit. pathsEqual performs platform-aware path equality, and getPathSeparator returns the active separator.
API Reference
ƒ Functions
Returns
booleanExample
Detecting case sensitivity
if (detectCaseSensitivity()) {
// Linux: 'File.ts' and 'file.ts' are different files
} else {
// Windows/macOS: treat as same file
}Parameters
| Name | Type | Description |
|---|---|---|
§content | string | Content to analyze |
Returns
DetectedLineEndingExample
Detecting line ending style
const ending = detectLineEnding('line1\nline2\n')
// => 'lf'
const mixed = detectLineEnding('line1\r\nline2\nline3')
// => 'mixed'Returns
PlatformInfoExample
Detecting current platform
const platform = detectPlatform()
if (platform.isWindows) {
// Windows-specific handling
}Returns
"
" | "
"Example
Getting platform line ending
const eol = getLineEnding()
const lines = ['line1', 'line2', 'line3']
const content = lines.join(eol)Returns
"\" | "/"Example
Getting platform path separator
const sep = getPathSeparator()
const fullPath = ['src', 'utils', 'helpers.ts'].join(sep)Returns
PlatformInfoExample
Getting platform information
const info = getPlatformInfo()
console.log(info.os) // => 'linux'
console.log(info.pathSeparator) // => '/'
console.log(info.lineEnding) // => '\n'Returns
booleanExample
Checking case sensitivity
const caseSensitive = isCaseSensitiveFs()
// => true on Linux, false on Windows/macOSReturns
booleanExample
Checking for Windows
if (isWindows()) {
// Use Windows-specific paths or commands
}Parameters
Returns
stringExample
Normalizing line endings
// Normalize to Unix line endings
const normalized = normalizeLineEndings('line1\r\nline2\r\n', 'lf')
// => 'line1\nline2\n'
// Use platform default
const platformNormalized = normalizeLineEndings(content, 'auto')Returns
booleanExample
Comparing paths
// On case-insensitive filesystem (Windows/macOS)
pathsEqual('src/App.tsx', 'src/app.tsx')
// => true
// On case-sensitive filesystem (Linux)
pathsEqual('src/App.tsx', 'src/app.tsx')
// => false