// src/lib/file/constants.ts
var WINDOWS_NEWLINE_REGEX = /\r\n/g;
var CROSS_PLATFORM_NEWLINE = "\n";

// src/lib/file/fileLines.ts
import {
  existsSync,
  readFileSync,
  writeFileSync
} from "fs";

// src/lib/string/empty.ts
var empty = (value) => value?.trim().length === 0;
var notEmpty = (value) => !empty(value);

// src/lib/file/ReadFileSyncOptions.ts
var defaultReadFileSyncOptions = { encoding: "utf8" };

// src/lib/file/fileLines.ts
var readLines = (uri, options = defaultReadFileSyncOptions) => existsSync(uri) ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [];
var readNonEmptyLines = (uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty);
var writeLines = (uri, lines, options = defaultReadFileSyncOptions) => {
  const existing = existsSync(uri) ? readFileSync(uri, options) : void 0;
  const desired = lines.join(CROSS_PLATFORM_NEWLINE);
  if (existing !== desired) writeFileSync(uri, desired, options);
};

// src/lib/file/tryReadFileSync.ts
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
var tryReadFileSync = (uri, options = defaultReadFileSyncOptions) => {
  return existsSync2(uri) ? readFileSync2(uri, options) : void 0;
};
export {
  CROSS_PLATFORM_NEWLINE,
  WINDOWS_NEWLINE_REGEX,
  defaultReadFileSyncOptions,
  readLines,
  readNonEmptyLines,
  tryReadFileSync,
  writeLines
};
//# sourceMappingURL=index.mjs.map