@hyperfrontend/project-scope/core/platform

platform

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

§function

detectCaseSensitivity(): boolean

Detect if file system is case sensitive.

Returns

boolean
True if file system is case-sensitive

Example

Detecting case sensitivity

if (detectCaseSensitivity()) {
  // Linux: 'File.ts' and 'file.ts' are different files
} else {
  // Windows/macOS: treat as same file
}
§function

detectLineEnding(content: string): DetectedLineEnding

Detect line ending style used in content.

Parameters

NameTypeDescription
§content
string
Content to analyze

Returns

DetectedLineEnding
Detected line ending style

Example

Detecting line ending style

const ending = detectLineEnding('line1\nline2\n')
// => 'lf'

const mixed = detectLineEnding('line1\r\nline2\nline3')
// => 'mixed'
§function

detectPlatform(): PlatformInfo

Detect current platform.

Returns

PlatformInfo
Platform information object

Example

Detecting current platform

const platform = detectPlatform()
if (platform.isWindows) {
  // Windows-specific handling
}
§function

getLineEnding(): " " | " "

Get platform-appropriate line ending.

Returns

" " | " "
Line ending for current platform

Example

Getting platform line ending

const eol = getLineEnding()
const lines = ['line1', 'line2', 'line3']
const content = lines.join(eol)
§function

getPathSeparator(): "\" | "/"

Get platform-appropriate path separator.

Returns

"\" | "/"
Path separator for current platform

Example

Getting platform path separator

const sep = getPathSeparator()
const fullPath = ['src', 'utils', 'helpers.ts'].join(sep)
§function

getPlatformInfo(): PlatformInfo

Get comprehensive platform information.

Returns

PlatformInfo
Platform information object (cached after first call)

Example

Getting platform information

const info = getPlatformInfo()
console.log(info.os)           // => 'linux'
console.log(info.pathSeparator) // => '/'
console.log(info.lineEnding)    // => '\n'
§function

isCaseSensitiveFs(): boolean

Check if file system is case-sensitive.

Returns

boolean
True if file system is case-sensitive

Example

Checking case sensitivity

const caseSensitive = isCaseSensitiveFs()
// => true on Linux, false on Windows/macOS
§function

isWindows(): boolean

Check if running on Windows.

Returns

boolean
True if running on Windows

Example

Checking for Windows

if (isWindows()) {
  // Use Windows-specific paths or commands
}
§function

normalizeLineEndings(content: string, style: LineEndingStyle): string

Normalize line endings in content.

Parameters

NameTypeDescription
§content
string
Content to normalize
§style
LineEndingStyle
Target line ending style ('lf', 'crlf', or 'auto' for platform default)
(default: 'lf')

Returns

string
Content with normalized line endings

Example

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')
§function

pathsEqual(path1: string, path2: string): boolean

Compare paths with case sensitivity awareness.

Parameters

NameTypeDescription
§path1
string
First path
§path2
string
Second path

Returns

boolean
True if paths are equal (respecting case sensitivity)

Example

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

§interface

PlatformInfo

Platform information.

Properties

§arch:string
CPU architecture
§caseSensitive:boolean
File system case sensitivity
§isLinux:boolean
Is Linux
§isMac:boolean
Is macOS
§isWindows:boolean
Is Windows
§lineEnding:" " | " "
Line ending for platform
§nodeVersion:string
Node.js version
§os:"darwin" | "linux" | "win32" | "freebsd" | "sunos" | "aix" | "other"
Operating system
§pathSeparator:"\" | "/"
Path separator for platform

Types

§type

DetectedLineEnding

Result of analyzing line endings in content.
type DetectedLineEnding = "lf" | "crlf" | "mixed" | "none"
§type

LineEndingStyle

Target specification for normalizing line endings.
type LineEndingStyle = "lf" | "crlf" | "auto"

Variables

§type

CRLF

Windows line ending
§type

LF

Unix line ending