@vortex.so/cli
Version:
CLI to interact with Vortex.
26 lines (23 loc) • 794 B
JavaScript
import { strip } from './string.strip.mjs';
function line(string, perLine) {
const lines = String(strip(string) || "").split(/\r?\n/);
if (!perLine)
return lines.length;
return lines.map((l) => Math.ceil(l.length / perLine)).reduce((a, b) => a + b);
}
function detectNewline(string) {
if (typeof string !== "string") {
throw new TypeError("Expected a string");
}
const newlines = string.match(/\r?\n/g) || [];
if (newlines.length === 0) {
return;
}
const crlf = newlines.filter((newline) => newline === "\r\n").length;
const lf = newlines.length - crlf;
return crlf > lf ? "\r\n" : "\n";
}
function detectNewlineGraceful(string) {
return typeof string === "string" && detectNewline(string) || "\n";
}
export { detectNewline, detectNewlineGraceful, line };