UNPKG

@visulima/fs

Version:

Human friendly file system utilities for Node.js

27 lines (21 loc) 810 B
import { createRequire as __cjs_createRequire } from "node:module"; const __cjs_require = __cjs_createRequire(import.meta.url); const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process; const { platform } = __cjs_getProcess; const regDetect = /\r?\n/g; const LF = "\n"; const CRLF = "\r\n"; const EOL = platform === "win32" ? CRLF : LF; const detect = (content) => { const matched = content.match(regDetect); if (!matched || matched.length === 0) { return null; } const crlf = matched.filter((newline) => newline === CRLF).length; const lf = matched.length - crlf; return crlf > lf ? CRLF : LF; }; const format = (content, eol) => content.replaceAll(regDetect, eol); export { CRLF, EOL, LF, detect, format };