tmcsplit 0.0.1 → 0.0.2

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name":
3
3
  "tmcsplit",
4
4
  "version":
5
- "0.0.1",
5
+ "0.0.2",
6
6
  "description":
7
7
  "Basic Javascript implementation of GNU Split.",
8
8
  "funding": {
@@ -57,11 +57,15 @@
57
57
  },
58
58
  "devDependencies": {
59
59
  "crash-js-webpack":
60
- "^0.0.2",
60
+ "^0.0.3",
61
61
  "eslint":
62
- "^9.32.0",
63
- "serve":
64
- "^14.2.5",
62
+ "^10.0.0",
63
+ "globals":
64
+ "^17.3.0",
65
+ "@eslint/js":
66
+ "^10.0.1",
67
+ "safely-serve":
68
+ "^0.0.9",
65
69
  "webpack":
66
70
  "^5.102.1",
67
71
  "webpack-cli":
@@ -69,14 +73,17 @@
69
73
  },
70
74
  "dependencies": {
71
75
  "crash-js":
72
- "^0.1.66",
76
+ "^0.1.73",
73
77
  "split-file":
74
- "npm:@themartiancompany/split-file@2.3.2"
78
+ "npm:@themartiancompany/split-file@2.3.12"
75
79
  },
76
80
  "type":
77
81
  "commonjs",
78
82
  "main":
79
- "tmcsplit",
83
+ "libtmcsplit",
84
+ "bin":
85
+ { "tmcsplit":
86
+ "tmcsplit" },
80
87
  "scripts": {
81
88
  "build-fs-worker":
82
89
  "npx webpack --mode 'production' --config 'fs-worker.webpack.config.cjs' --stats-error-details",
@@ -91,7 +98,7 @@
91
98
  "publish-pnm":
92
99
  "npm run build && npm publish --access public",
93
100
  "start":
94
- "serve -c 'serve.json'",
101
+ "npx safely-serve --help # index.html --port 3000 --https --no-cache",
95
102
  "test":
96
103
  "echo \"Error: no test specified\" && exit 1"
97
104
  }
package/tmcsplit CHANGED
@@ -2,58 +2,136 @@
2
2
 
3
3
  // SPDX-License-Identifier: AGPL-3.0-or-later
4
4
 
5
- // ----------------------------------------------------------------------
6
- // Copyright © 2024, 2025 Pellegrino Prevete
7
- //
8
- // All rights reserved
9
- // ----------------------------------------------------------------------
10
- //
11
- // This program is free software: you can redistribute it and/or modify
12
- // it under the terms of the GNU Affero General Public License as published by
13
- // the Free Software Foundation, either version 3 of the License, or
14
- // (at your option) any later version.
15
- //
16
- // This program is distributed in the hope that it will be useful,
17
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- // GNU Affero General Public License for more details.
20
- //
21
- // You should have received a copy of the GNU Affero General Public License
22
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
5
+ /** ----------------------------------------------------------------------
6
+ * tmcsplit
7
+ * ----------------------------------------------------------------------
8
+ * Copyright ©
9
+ * Pellegrino Prevete
10
+ * 2024, 2025, 2026
11
+ *
12
+ * All rights reserved
13
+ * ----------------------------------------------------------------------
14
+ *
15
+ * This program is free software: you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License as published by
17
+ * the Free Software Foundation, either version 3 of the License, or
18
+ * (at your option) any later version.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU General Public License
26
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
27
+ */
28
+
29
+ /* eslint
30
+ no-unused-vars: [
31
+ "error",
32
+ { "vars":
33
+ "local",
34
+ "argsIgnorePattern":
35
+ "output_prefix" } ] */
23
36
 
24
37
  const
25
38
  _libcrash =
26
- require(
27
- 'crash-js');
28
- _cmdline_check =
29
- _libcrash._cmdline_check;
30
- _msg_info =
31
- _libcrash._msg_info;
39
+ require(
40
+ 'crash-js');
41
+ /* global
42
+ _argv_url_get */
43
+ const
44
+ _argv_url_get =
45
+ _libcrash._argv_url_get;
46
+ /* global
47
+ _cmdline_check */
48
+ const
49
+ _cmdline_check =
50
+ _libcrash._cmdline_check;
51
+ /* global
52
+ _msg_info */
53
+ const
54
+ _msg_info =
55
+ _libcrash._msg_info;
56
+ /* global
57
+ _msg_error */
58
+ const
32
59
  _msg_error =
33
60
  _libcrash._msg_error;
61
+ /* global
62
+ _yargv_get */
63
+ const
64
+ _yargv_get =
65
+ _libcrash._yargv_get;
34
66
  const
35
67
  _split_module =
36
68
  require(
37
69
  "./libtmcsplit");
38
- _tmcsplit =
39
- _split_module._tmcsplit;
70
+ /* global
71
+ _tmcsplit */
72
+ const
73
+ _split =
74
+ _split_module._split;
40
75
 
41
76
  function
42
77
  _global_variables() {
78
+ /* global
79
+ app_name:
80
+ writable */
43
81
  app_name =
44
82
  "tmcsplit";
83
+ /* global
84
+ app_opts:
85
+ writable */
86
+ app_opts =
87
+ [];
88
+ /* global
89
+ runtime_environment:
90
+ writable */
91
+ runtime_environment =
92
+ "";
93
+ /* global
94
+ numeric_suffix:
95
+ writable */
96
+ numeric_suffix =
97
+ "";
98
+ /* global
99
+ suffix_length:
100
+ writable */
45
101
  suffix_length =
46
102
  "";
103
+ /* global
104
+ chunks_amount:
105
+ writable */
47
106
  chunks_amount =
48
107
  "";
49
- string_length =
50
- "";
108
+ // string_length =
109
+ // "";
110
+ /* global
111
+ size_max:
112
+ writable */
51
113
  size_max =
52
114
  "";
115
+ /* global
116
+ input_file:
117
+ writable */
118
+ input_file =
119
+ "";
120
+ /* global
121
+ output_prefix:
122
+ writable */
53
123
  output_prefix =
54
124
  "";
125
+ /* global
126
+ quiet:
127
+ writable */
55
128
  quiet =
56
129
  "";
130
+ /* global
131
+ verbose:
132
+ writable */
133
+ verbose =
134
+ "";
57
135
  }
58
136
 
59
137
  function
@@ -64,24 +142,24 @@ function
64
142
  }
65
143
  if ( output_prefix == "" ) {
66
144
  output_prefix =
67
- _input_file + ".";
145
+ input_file + ".";
68
146
  }
69
147
  }
70
148
 
71
149
  function
72
150
  _config_show() {
73
151
  let
74
- _line,
75
- _text;
76
- _text = [
77
- `${app_name} configuration:`,
78
- ` Runtime environment: ${runtime_environment}`,
79
- ` Suffix length: ${suffix_length}`,
80
- ` Maximum chunk size: ${size_max} bytes`,
81
- ` Amount of chunks: ${chunks_amount}`,
82
- ` In file: ${input_file}`,
83
- ` Out files prefix: ${output_prefix}`,
84
- ];
152
+ _line;
153
+ const
154
+ _text = [
155
+ `${app_name} configuration:`,
156
+ ` Runtime environment: ${runtime_environment}`,
157
+ ` Suffix length: ${suffix_length}`,
158
+ ` Maximum chunk size: ${size_max} bytes`,
159
+ ` Amount of chunks: ${chunks_amount}`,
160
+ ` In file: ${input_file}`,
161
+ ` Out files prefix: ${output_prefix}`,
162
+ ];
85
163
  for ( _line of _text ) {
86
164
  _msg_info(
87
165
  _line);
@@ -92,62 +170,67 @@ function
92
170
  _usage(
93
171
  _exit_code) {
94
172
  let
95
- _line,
96
- _text;
97
- _text = [
98
- "Output pieces of FILE to PREFIXaa, PREFIXab, ...",
99
- "default size is 1000 lines, and default PREFIX is 'x'.",
100
- "",
101
- "Usage:",
102
- "",
103
- " tmcsplit",
104
- " <in-file>",
105
- " <out-txt-prefix>",
106
- "",
107
- " arguments:",
108
- " <in-file> An input file.",
109
- " <out-file-prefix> Prefix for the output file(s).",
110
- "",
111
- " options:",
112
- "",
113
- " -a, --suffix-length=N Generate suffixes of length N",
114
- ` Default: '${suffix_length}'`,
115
- " --additional-suffix=SUFFIX append an additional SUFFIX",
116
- " to file names",
117
- " -b, --bytes=SIZE Put SIZE bytes per output file",
118
- " -C, --line-bytes=SIZE Put at most SIZE bytes of",
119
- " records per output file.",
120
- " -d Use numeric suffixes starting",
121
- " at 0, not alphabetic",
122
- " --numeric-suffixes[=FROM] Same as -d, but allow setting",
123
- " the start value.",
124
- " -l, --lines=NUMBER Put NUMBER lines/records per",
125
- " output file.",
126
- " -n, --number=CHUNKS Generate CHUNKS output files;",
127
- " see explanation below",
128
- " -t, --separator=SEP Use SEP instead of newline as",
129
- " the record separator;",
130
- " '\0' (zero) specifies the",
131
- " NUL character.",
132
- "",
133
- " -h --help This message.",
134
- " -v --verbose Enable verbose output.",
135
- "",
136
- "The SIZE argument is an integer and optional",
137
- "unit (example: 10K is 10*1024).",
138
- "Units are K,M,G,T,P,E,Z,Y,R,Q (powers of 1024)",
139
- "or KB,MB,... (powers of 1000).",
140
- "Binary prefixes can be used, too: KiB=K, MiB=M, and so on.",
141
- "",
142
- "CHUNKS may be:",
143
- " N split into N files based on size of input",
144
- " K/N output Kth of N to standard output",
145
- " l/N split into N files without splitting lines/records",
146
- " l/K/N output Kth of N to standard output without",
147
- " splitting lines/records",
148
- ];
173
+ _line;
174
+ const
175
+ _text = [
176
+ "Output pieces of FILE to PREFIXaa, PREFIXab, ...",
177
+ "default size is 1000 lines, and default PREFIX is 'x'.",
178
+ "",
179
+ "Usage:",
180
+ "",
181
+ " tmcsplit",
182
+ " <in-file>",
183
+ " <out-txt-prefix>",
184
+ "",
185
+ " arguments:",
186
+ " <in-file> An input file.",
187
+ " <out-file-prefix> Prefix for the output",
188
+ " file(s).",
189
+ "",
190
+ " options:",
191
+ "",
192
+ " -a, --suffix-length=N Generate suffixes of",
193
+ " length N.",
194
+ ` Default: '${suffix_length}'`,
195
+ " --additional-suffix=SUFFIX append an additional SUFFIX",
196
+ " to file names.",
197
+ " -b, --bytes=SIZE Put SIZE bytes per output",
198
+ " file.",
199
+ " -C, --line-bytes=SIZE Put at most SIZE bytes of",
200
+ " records per output file.",
201
+ " -d Use numeric suffixes",
202
+ " starting at 0, not",
203
+ " alphabetic.",
204
+ " --numeric-suffixes[=FROM] Same as -d, but allow",
205
+ " setting the start value.",
206
+ " -l, --lines=NUMBER Put NUMBER lines/records",
207
+ " per output file.",
208
+ " -n, --number=CHUNKS Generate CHUNKS output",
209
+ " files; see explanation",
210
+ " below",
211
+ " -t, --separator=SEP Use SEP instead of newline",
212
+ " as the record separator;",
213
+ " '\0' (zero) specifies the",
214
+ " NUL character.",
215
+ "",
216
+ " -h --help This message.",
217
+ " -v --verbose Enable verbose output.",
218
+ "",
219
+ "The SIZE argument is an integer and optional",
220
+ "unit (example: 10K is 10*1024).",
221
+ "Units are K,M,G,T,P,E,Z,Y,R,Q (powers of 1024)",
222
+ "or KB,MB,... (powers of 1000).",
223
+ "Binary prefixes can be used, too: KiB=K, MiB=M, and so on.",
224
+ "",
225
+ "CHUNKS may be:",
226
+ " N split into N files based on size of input",
227
+ " K/N output Kth of N to standard output",
228
+ " l/N split into N files without splitting lines/records",
229
+ " l/K/N output Kth of N to standard output without",
230
+ " splitting lines/records",
231
+ ];
149
232
  for ( _line of _text ) {
150
- _msg_info(
233
+ console.log(
151
234
  _line);
152
235
  }
153
236
  process.exit(
@@ -157,13 +240,12 @@ function
157
240
  function
158
241
  _cmdline_parse_help(
159
242
  _argv) {
160
- let
161
- _help_display;
162
- _help_display =
163
- _argv[
164
- "help"] ||
165
- _argv[
166
- "h"];
243
+ const
244
+ _help_display =
245
+ _argv[
246
+ "help"] ||
247
+ _argv[
248
+ "h"];
167
249
  if ( _help_display ) {
168
250
  quiet =
169
251
  "n";
@@ -177,8 +259,9 @@ function
177
259
  _argv) {
178
260
  if ( _argv[
179
261
  "_"].length < 1 ) {
180
- _msg =
181
- "Input file argument required.";
262
+ const
263
+ _msg =
264
+ "Input file argument required.";
182
265
  _msg_error(
183
266
  _msg,
184
267
  0);
@@ -189,16 +272,14 @@ function
189
272
 
190
273
  function
191
274
  _cmdline_parse() {
192
- let
193
- _argv,
194
- _msg;
195
- _argv =
196
- _yargv_get();
275
+ const
276
+ _argv =
277
+ _yargv_get();
197
278
  quiet =
198
279
  "y";
199
280
  runtime_environment =
200
281
  "node";
201
- _cmline_parse_help(
282
+ _cmdline_parse_help(
202
283
  _argv);
203
284
  _input_args_check(
204
285
  _argv);
@@ -209,7 +290,7 @@ function
209
290
  if ( _argv[
210
291
  "_"].length < 2 ) {
211
292
  output_prefix =
212
- input_file + "."
293
+ `${input_file}.`;
213
294
  }
214
295
  if ( "a" in _argv ) {
215
296
  suffix_length =
@@ -221,12 +302,21 @@ function
221
302
  _argv[
222
303
  "suffix-length"];
223
304
  }
305
+ if ( "d" in _argv ) {
306
+ numeric_suffix =
307
+ true;
308
+ }
309
+ if ( "suffix-length" in _argv ) {
310
+ suffix_length =
311
+ _argv[
312
+ "suffix-length"];
313
+ }
224
314
  chunks_amount =
225
315
  _argv[
226
316
  "chunks-amount"] ||
227
317
  _argv[
228
318
  "n"];
229
- chunks_amount =
319
+ size_max =
230
320
  _argv[
231
321
  "size-max"] ||
232
322
  _argv[
@@ -244,27 +334,26 @@ function
244
334
 
245
335
  function
246
336
  _url_parse() {
247
- let
248
- _argv;
337
+ const
338
+ _argv =
339
+ _argv_url_get();
249
340
  runtime_environment =
250
341
  "browser";
251
- _argv =
252
- _argv_url_get();
253
342
  input_file =
254
- _argv_url_get(
255
- "input_file")[
343
+ _argv[
344
+ "input_file"][
256
345
  0];
257
346
  output_prefix =
258
- _argv_url_get(
259
- "output_prefix")[
347
+ _argv_url_get[
348
+ "output_prefix"][
260
349
  0];
261
350
  chunks_amount =
262
- _argv_url_get(
263
- "chunks_amount")[
351
+ _argv_url_get[
352
+ "chunks_amount"][
264
353
  0];
265
354
  quiet =
266
- _argv_url_get(
267
- "quiet");
355
+ _argv_url_get[
356
+ "quiet"];
268
357
  if ( quiet.length === 0 ) {
269
358
  quiet =
270
359
  "n";
@@ -272,6 +361,7 @@ function
272
361
  }
273
362
 
274
363
  _global_variables();
364
+ _overrides_set();
275
365
  if ( _cmdline_check(
276
366
  "tmcsplit") == true ) {
277
367
  _cmdline_parse();
@@ -286,6 +376,6 @@ app_opts = [
286
376
  chunks_amount,
287
377
  size_max
288
378
  ];
289
- _tmcsplit.apply(
379
+ _split.apply(
290
380
  null,
291
381
  app_opts);