@visulima/fs
Version:
Human friendly file system utilities for Node.js
36 lines (35 loc) • 1.15 kB
TypeScript
/** End-of-line character for POSIX platforms such as macOS and Linux. */
export declare const LF: "\n";
/** End-of-line character for Windows platforms. */
export declare const CRLF: "\r\n";
/**
* End-of-line character evaluated for the current platform.
*/
export declare const EOL: "\n" | "\r\n";
/**
* Detect the EOL character for string input.
* Returns null if no newline.
* @param content The string content to detect the EOL from.
* @example
* ```javascript
* import { detect } from "@visulima/fs/eol";
*
* detect("Hello\r\nWorld"); // "\r\n"
* detect("Hello\nWorld"); // "\n"
* detect("HelloWorld"); // null
* ```
*/
export declare const detect: (content: string) => typeof EOL | null;
/**
* Format the file to the targeted EOL.
* @param content The string content to format.
* @param eol The target EOL character.
* @example
* ```javascript
* import { format, LF, CRLF } from "@visulima/fs/eol";
*
* format("Hello\r\nWorld\nUnix", LF); // "Hello\nWorld\nUnix"
* format("Hello\nWorld\r\nWindows", CRLF); // "Hello\r\nWorld\r\nWindows"
* ```
*/
export declare const format: (content: string, eol: typeof EOL) => string;