@hyperfrontend/project-scope/core/platformplatform
Operating system detection and platform-specific normalization for filesystem case sensitivity and line endings.
detectPlatform, getPlatformInfo, isWindows, isMac and isLinux classify the host OS; isCaseSensitiveFs and detectCaseSensitivity decide whether path comparisons must be case-aware, by probing the file system, since APFS and NTFS volumes can be configured either way. 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
A and looking for a. The answer is probed on every platform, since APFS and NTFS can be configured either way; only when no file can be written does it fall back to the platform's default, case-sensitive on Linux and insensitive elsewhere.Returns
booleanExample
Detecting case sensitivity
if (detectCaseSensitivity()) {
// 'File.ts' and 'file.ts' are different files, as on most Linux file systems
} else {
// treat them as the same file, as the Windows and macOS defaults do
}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()
// => usually true on Linux, false on a default Windows or macOS volumeReturns
booleanExample
Checking for Linux
if (isLinux()) {
// Use Linux-specific behavior
}Returns
booleanExample
Checking for macOS
if (isMac()) {
// Use macOS-specific behavior
}Returns
booleanExample
Checking for Windows
if (isWindows()) {
// Use Windows-specific paths or commands
}Parameters
| Name | Type | Description |
|---|---|---|
§content | string | Content to normalize |
§style | LineEndingStyle | Target line ending style ('lf', 'crlf', or 'auto' for platform default)(default: 'lf') |
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◈ Interfaces
Properties
◆ Types
type DetectedLineEnding = "lf" | "crlf" | "mixed" | "none"type LineEndingStyle = "lf" | "crlf" | "auto"