1.1.1 • Published 4 months ago

crlf-es v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

crlf-es

0 dependency, promise-based utility to convert files to CRLF or LF or get file endings for files or strings.

Uses all native NodeJS API's: util.parseArgs util.styleText fs.glob

Based on kolodny/crlf

CLI Usage

Set line endings

Use --set or -s

$ crlf-es ./files/**/*.txt -s CRLF

[ SKIPPED ] ./files/10.txt  (7 ms)
[ SKIPPED ] ./files/11.txt  (76 ms)
[ SKIPPED ] ./files/16.txt  (77 ms)
[ SKIPPED ] ./files/17.txt  (77 ms)
[ SKIPPED ] ./files/4.txt   (78 ms)
[ SKIPPED ] ./files/8.txt   (78 ms)
[ SKIPPED ] ./files/12.txt  (81 ms)
[ SKIPPED ] ./files/7.txt   (82 ms)
[ SUCCESS ] ./files/1.txt   (89 ms)
[ SUCCESS ] ./files/13.txt  (90 ms)
[ SUCCESS ] ./files/14.txt  (90 ms)
[ SUCCESS ] ./files/2.txt   (90 ms)
[ SUCCESS ] ./files/15.txt  (91 ms)
[ SUCCESS ] ./files/3.txt   (91 ms)
[ SUCCESS ] ./files/5.txt   (91 ms)
[ SUCCESS ] ./files/6.txt   (91 ms)
[ SUCCESS ] ./files/9.txt   (91 ms)

Done in 133 ms

* Files are skipped when they are already a certain line ending or have no newlines (override with --force/-f)

Get line endings

$ npx crlf-es ./files/**/*.txt

./files/1.txt   LF
./files/10.txt  CRLF
./files/11.txt  CRLF
./files/13.txt  LF
./files/14.txt  LF
./files/15.txt  LF
./files/16.txt  CRLF
./files/17.txt  CRLF
./files/2.txt   LF
./files/3.txt   LF
./files/4.txt   CRLF
./files/5.txt   LF
./files/6.txt   LF
./files/8.txt   CRLF
./files/9.txt   LF
./files/12.txt  None
./files/7.txt   None

Done in 53 ms

API Usage

Set line endings in file

import { setLineEndings } from 'crlf-es';

await setLineEndings('./my-file.txt', 'CRLF');

Set line endings in multiple files

import { setLineEndings } from 'crlf-es';

// Uses NodeJS fs.glob
await setLineEndings('./files/**/*.txt', 'LF');

// Also accepts array
await setLineEndings(['./files/**/*.txt', './other-files/**/*.txt'], 'CRLF');

Get line endings for file

import { getFileLineEndings } from 'crlf-es';

await getFileLineEndings('./my-file.txt', 'LF');

Get line endings for string

import { getStringLineEndings } from 'crlf-es';

const myString =
    'Aut adipisci sit qui.\r\nEnim quibusdam accusamus cum fugiat.\r\nOfficiis qui veritatis facilis sint tempora impedit';

const result = await getStringLineEndings(myString);
// result = CRLF
1.1.1

4 months ago

1.1.0

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago