@cto.af/linewrap-cli 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/linewrap.js +33 -33
- package/package.json +7 -7
package/bin/linewrap.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* eslint-disable no-console */
|
|
3
3
|
|
|
4
|
-
import {inspect, promisify} from 'util'
|
|
5
|
-
import {LineWrap} from '@cto.af/linewrap'
|
|
6
|
-
import {fileURLToPath} from 'url'
|
|
7
|
-
import fs from 'fs'
|
|
8
|
-
import os from 'os'
|
|
9
|
-
import {parseArgsWithHelp} from 'minus-h'
|
|
4
|
+
import {inspect, promisify} from 'util';
|
|
5
|
+
import {LineWrap} from '@cto.af/linewrap';
|
|
6
|
+
import {fileURLToPath} from 'url';
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
import os from 'os';
|
|
9
|
+
import {parseArgsWithHelp} from 'minus-h';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @type {Parameters<generateHelp>[0]}
|
|
@@ -131,7 +131,7 @@ const config = {
|
|
|
131
131
|
argumentName: '...file',
|
|
132
132
|
argumentDescription: 'files to wrap and concatenate. Use "-" for stdin. Default: "-"',
|
|
133
133
|
description: 'Wrap some text, either from file, stdin, or given on the command line. Each chunk of text is wrapped independently from one another, and streamed to stdout (or an outFile, if given). Command line arguments with -t/--text are processed before files.',
|
|
134
|
-
}
|
|
134
|
+
};
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
137
|
* Read stdin to completion with the configured encoding.
|
|
@@ -140,13 +140,13 @@ const config = {
|
|
|
140
140
|
*/
|
|
141
141
|
function readStdin(opts, stream) {
|
|
142
142
|
// Below, d will be a string
|
|
143
|
-
stream.setEncoding(opts.encoding)
|
|
143
|
+
stream.setEncoding(opts.encoding);
|
|
144
144
|
return new Promise((resolve, reject) => {
|
|
145
|
-
let s = ''
|
|
146
|
-
stream.on('data', d => (s += d))
|
|
147
|
-
stream.on('end', () => resolve(s))
|
|
148
|
-
stream.on('error', reject)
|
|
149
|
-
})
|
|
145
|
+
let s = '';
|
|
146
|
+
stream.on('data', d => (s += d));
|
|
147
|
+
stream.on('end', () => resolve(s));
|
|
148
|
+
stream.on('error', reject);
|
|
149
|
+
});
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
const ESCAPES = {
|
|
@@ -156,7 +156,7 @@ const ESCAPES = {
|
|
|
156
156
|
'"': '"',
|
|
157
157
|
"'": ''',
|
|
158
158
|
'\xA0': ' ',
|
|
159
|
-
}
|
|
159
|
+
};
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
162
|
* Escape HTML
|
|
@@ -166,12 +166,12 @@ const ESCAPES = {
|
|
|
166
166
|
* @private
|
|
167
167
|
*/
|
|
168
168
|
function htmlEscape(str) {
|
|
169
|
-
return str.replace(/[&<>\xA0]/g, m => ESCAPES[m])
|
|
169
|
+
return str.replace(/[&<>\xA0]/g, m => ESCAPES[m]);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
const {
|
|
173
173
|
exit, stdin, stdout, stderr,
|
|
174
|
-
} = process
|
|
174
|
+
} = process;
|
|
175
175
|
|
|
176
176
|
export async function main(
|
|
177
177
|
extraConfig,
|
|
@@ -184,10 +184,10 @@ export async function main(
|
|
|
184
184
|
}, {
|
|
185
185
|
width: config.options.width.default,
|
|
186
186
|
...options,
|
|
187
|
-
})
|
|
187
|
+
});
|
|
188
188
|
|
|
189
189
|
if ((values.text.length === 0) && (positionals.length === 0)) {
|
|
190
|
-
positionals.push('-')
|
|
190
|
+
positionals.push('-');
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
// Always a valid string, due to choices enforcement
|
|
@@ -196,11 +196,11 @@ export async function main(
|
|
|
196
196
|
visible: LineWrap.OVERFLOW_VISIBLE,
|
|
197
197
|
clip: LineWrap.OVERFLOW_CLIP,
|
|
198
198
|
anywhere: LineWrap.OVERFLOW_ANYWHERE,
|
|
199
|
-
}[values.overflow]
|
|
199
|
+
}[values.overflow];
|
|
200
200
|
|
|
201
201
|
const outstream = values.outFile ?
|
|
202
202
|
fs.createWriteStream(values.outFile, values.encoding) :
|
|
203
|
-
process.stdout // Don't set encoding, will confuse terminal.
|
|
203
|
+
process.stdout; // Don't set encoding, will confuse terminal.
|
|
204
204
|
|
|
205
205
|
/** @type {ConstructorParameters<typeof LineWrap>[0]} */
|
|
206
206
|
const opts = {
|
|
@@ -220,39 +220,39 @@ export async function main(
|
|
|
220
220
|
trim: !values.noTrim,
|
|
221
221
|
verbose: values.verbose,
|
|
222
222
|
width: parseInt(values.width, 10),
|
|
223
|
-
}
|
|
223
|
+
};
|
|
224
224
|
if (typeof values.isNewline === 'string') {
|
|
225
225
|
opts.isNewline = (values.isNewline.length === 0) ?
|
|
226
226
|
null :
|
|
227
|
-
new RegExp(values.isNewline, 'gu')
|
|
227
|
+
new RegExp(values.isNewline, 'gu');
|
|
228
228
|
}
|
|
229
229
|
if (values.verbose) {
|
|
230
|
-
process.stdout.write(inspect(opts))
|
|
230
|
+
process.stdout.write(inspect(opts));
|
|
231
231
|
}
|
|
232
|
-
const w = new LineWrap(opts)
|
|
232
|
+
const w = new LineWrap(opts);
|
|
233
233
|
|
|
234
234
|
for (const t of values.text) {
|
|
235
|
-
outstream.write(w.wrap(t))
|
|
236
|
-
outstream.write(values.newline)
|
|
235
|
+
outstream.write(w.wrap(t));
|
|
236
|
+
outstream.write(values.newline);
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
for (const f of positionals) {
|
|
240
240
|
const t = f === '-' ?
|
|
241
241
|
await readStdin(values, process.stdin) :
|
|
242
|
-
await fs.promises.readFile(f, values.encoding)
|
|
242
|
+
await fs.promises.readFile(f, values.encoding);
|
|
243
243
|
|
|
244
|
-
outstream.write(w.wrap(t))
|
|
245
|
-
outstream.write(values.newline)
|
|
244
|
+
outstream.write(w.wrap(t));
|
|
245
|
+
outstream.write(values.newline);
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
// Be careful to wait for the file to close, to ensure tests run
|
|
249
249
|
// correctly.
|
|
250
|
-
await promisify(outstream.end.bind(outstream))()
|
|
250
|
+
await promisify(outstream.end.bind(outstream))();
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
if (fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
254
254
|
main().catch(e => {
|
|
255
|
-
console.error(e)
|
|
256
|
-
process.exit(1)
|
|
257
|
-
})
|
|
255
|
+
console.error(e);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
});
|
|
258
258
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cto.af/linewrap-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Wrap lines using the Unicode Line Breaking algorithm from UAX #14",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"repository": "cto-af/linewrap-cli",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@cto.af/linewrap": "1.0
|
|
30
|
-
"minus-h": "1.
|
|
29
|
+
"@cto.af/linewrap": "1.1.0",
|
|
30
|
+
"minus-h": "1.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@cto.af/eslint-config": "
|
|
34
|
-
"@types/node": "20.
|
|
35
|
-
"c8": "
|
|
36
|
-
"eslint": "8.
|
|
33
|
+
"@cto.af/eslint-config": "3.0.2",
|
|
34
|
+
"@types/node": "20.8.10",
|
|
35
|
+
"c8": "8.0.1",
|
|
36
|
+
"eslint": "8.52.0",
|
|
37
37
|
"mocha": "10.2.0"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|