@hugojosefson/cli 0.11.0 → 0.13.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/README.md +1 -1
- package/esm/deno.js +16 -8
- package/esm/hj.js +19 -0
- package/esm/node_modules/@conventional-changelog/template/LICENSE.md +21 -0
- package/esm/node_modules/@conventional-changelog/template/README.md +66 -0
- package/esm/node_modules/@conventional-changelog/template/dist/elements.d.ts +78 -0
- package/esm/node_modules/@conventional-changelog/template/dist/elements.d.ts.map +1 -0
- package/esm/node_modules/@conventional-changelog/template/dist/elements.js +132 -0
- package/esm/node_modules/@conventional-changelog/template/dist/index.d.ts +6 -0
- package/esm/node_modules/@conventional-changelog/template/dist/index.d.ts.map +1 -0
- package/esm/node_modules/@conventional-changelog/template/dist/index.js +5 -0
- package/esm/node_modules/@conventional-changelog/template/dist/legacy.d.ts +20 -0
- package/esm/node_modules/@conventional-changelog/template/dist/legacy.d.ts.map +1 -0
- package/esm/node_modules/@conventional-changelog/template/dist/legacy.js +22 -0
- package/esm/node_modules/@conventional-changelog/template/dist/references.d.ts +43 -0
- package/esm/node_modules/@conventional-changelog/template/dist/references.d.ts.map +1 -0
- package/esm/node_modules/@conventional-changelog/template/dist/references.js +82 -0
- package/esm/node_modules/@conventional-changelog/template/dist/templates.d.ts +74 -0
- package/esm/node_modules/@conventional-changelog/template/dist/templates.d.ts.map +1 -0
- package/esm/node_modules/@conventional-changelog/template/dist/templates.js +125 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/commit.d.ts +37 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/commit.d.ts.map +1 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/commit.js +2 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/context.d.ts +113 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/context.d.ts.map +1 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/context.js +2 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/index.d.ts +4 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/index.d.ts.map +1 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/index.js +2 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/utils.d.ts +2 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/utils.d.ts.map +1 -0
- package/esm/node_modules/@conventional-changelog/template/dist/types/utils.js +2 -0
- package/esm/node_modules/@conventional-changelog/template/package.json +38 -0
- package/esm/node_modules/@simple-libs/stream-utils/LICENSE +21 -0
- package/esm/node_modules/@simple-libs/stream-utils/README.md +79 -0
- package/esm/node_modules/@simple-libs/stream-utils/dist/index.d.ts +51 -0
- package/esm/node_modules/@simple-libs/stream-utils/dist/index.d.ts.map +1 -0
- package/esm/node_modules/@simple-libs/stream-utils/dist/index.js +116 -0
- package/esm/node_modules/@simple-libs/stream-utils/package.json +38 -0
- package/esm/node_modules/argue-cli/LICENSE +21 -0
- package/esm/node_modules/argue-cli/README.md +239 -0
- package/esm/node_modules/argue-cli/dist/args.d.ts +30 -0
- package/esm/node_modules/argue-cli/dist/args.d.ts.map +1 -0
- package/esm/node_modules/argue-cli/dist/argv.d.ts +14 -0
- package/esm/node_modules/argue-cli/dist/argv.d.ts.map +1 -0
- package/esm/node_modules/argue-cli/dist/core.d.ts +24 -0
- package/esm/node_modules/argue-cli/dist/core.d.ts.map +1 -0
- package/esm/node_modules/argue-cli/dist/index.d.ts +6 -0
- package/esm/node_modules/argue-cli/dist/index.d.ts.map +1 -0
- package/esm/node_modules/argue-cli/dist/index.js +254 -0
- package/esm/node_modules/argue-cli/dist/index.js.map +1 -0
- package/esm/node_modules/argue-cli/dist/options.d.ts +9 -0
- package/esm/node_modules/argue-cli/dist/options.d.ts.map +1 -0
- package/esm/node_modules/argue-cli/dist/types.d.ts +16 -0
- package/esm/node_modules/argue-cli/dist/types.d.ts.map +1 -0
- package/esm/node_modules/argue-cli/dist/utils.d.ts +24 -0
- package/esm/node_modules/argue-cli/dist/utils.d.ts.map +1 -0
- package/esm/node_modules/argue-cli/package.json +34 -0
- package/esm/node_modules/conventional-changelog-core/node_modules/conventional-changelog-writer/LICENSE.md +21 -0
- package/esm/node_modules/conventional-changelog-core/node_modules/conventional-changelog-writer/README.md +369 -0
- package/esm/node_modules/conventional-changelog-core/node_modules/conventional-changelog-writer/package.json +53 -0
- package/esm/node_modules/conventional-changelog-core/node_modules/conventional-commits-filter/LICENSE +21 -0
- package/esm/node_modules/conventional-changelog-core/node_modules/conventional-commits-filter/README.md +184 -0
- package/esm/node_modules/conventional-changelog-core/node_modules/conventional-commits-filter/package.json +31 -0
- package/esm/node_modules/conventional-changelog-core/node_modules/conventional-commits-parser/LICENSE.md +21 -0
- package/esm/node_modules/conventional-changelog-core/node_modules/conventional-commits-parser/README.md +383 -0
- package/esm/node_modules/conventional-changelog-core/node_modules/conventional-commits-parser/package.json +47 -0
- package/esm/node_modules/conventional-changelog-writer/README.md +49 -342
- package/esm/node_modules/conventional-changelog-writer/dist/cli/index.d.ts +3 -0
- package/esm/node_modules/conventional-changelog-writer/dist/cli/index.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/cli/index.js +68 -0
- package/esm/node_modules/conventional-changelog-writer/dist/cli/utils.d.ts +4 -0
- package/esm/node_modules/conventional-changelog-writer/dist/cli/utils.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/cli/utils.js +39 -0
- package/esm/node_modules/conventional-changelog-writer/dist/commit.d.ts +10 -0
- package/esm/node_modules/conventional-changelog-writer/dist/commit.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/commit.js +43 -0
- package/esm/node_modules/conventional-changelog-writer/dist/context.d.ts +27 -0
- package/esm/node_modules/conventional-changelog-writer/dist/context.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/context.js +134 -0
- package/esm/node_modules/conventional-changelog-writer/dist/index.d.ts +7 -0
- package/esm/node_modules/conventional-changelog-writer/dist/index.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/index.js +6 -0
- package/esm/node_modules/conventional-changelog-writer/dist/options.d.ts +25 -0
- package/esm/node_modules/conventional-changelog-writer/dist/options.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/options.js +79 -0
- package/esm/node_modules/conventional-changelog-writer/dist/template.d.ts +10 -0
- package/esm/node_modules/conventional-changelog-writer/dist/template.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/template.js +18 -0
- package/esm/node_modules/conventional-changelog-writer/dist/types/index.d.ts +8 -0
- package/esm/node_modules/conventional-changelog-writer/dist/types/index.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/types/index.js +2 -0
- package/esm/node_modules/conventional-changelog-writer/dist/types/options.d.ts +122 -0
- package/esm/node_modules/conventional-changelog-writer/dist/types/options.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/types/options.js +2 -0
- package/esm/node_modules/conventional-changelog-writer/dist/types/utils.d.ts +9 -0
- package/esm/node_modules/conventional-changelog-writer/dist/types/utils.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/types/utils.js +2 -0
- package/esm/node_modules/conventional-changelog-writer/dist/utils.d.ts +20 -0
- package/esm/node_modules/conventional-changelog-writer/dist/utils.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/utils.js +70 -0
- package/esm/node_modules/conventional-changelog-writer/dist/writers.d.ts +29 -0
- package/esm/node_modules/conventional-changelog-writer/dist/writers.d.ts.map +1 -0
- package/esm/node_modules/conventional-changelog-writer/dist/writers.js +94 -0
- package/esm/node_modules/conventional-changelog-writer/package.json +24 -26
- package/esm/node_modules/conventional-commits-filter/README.md +51 -170
- package/esm/node_modules/conventional-commits-filter/dist/RevertedCommitsFilter.d.ts +17 -0
- package/esm/node_modules/conventional-commits-filter/dist/RevertedCommitsFilter.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-filter/dist/RevertedCommitsFilter.js +46 -0
- package/esm/node_modules/conventional-commits-filter/dist/filters.d.ts +19 -0
- package/esm/node_modules/conventional-commits-filter/dist/filters.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-filter/dist/filters.js +34 -0
- package/esm/node_modules/conventional-commits-filter/dist/index.d.ts +4 -0
- package/esm/node_modules/conventional-commits-filter/dist/index.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-filter/dist/index.js +3 -0
- package/esm/node_modules/conventional-commits-filter/dist/types.d.ts +6 -0
- package/esm/node_modules/conventional-commits-filter/dist/types.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-filter/dist/types.js +2 -0
- package/esm/node_modules/conventional-commits-filter/dist/utils.d.ts +16 -0
- package/esm/node_modules/conventional-commits-filter/dist/utils.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-filter/dist/utils.js +43 -0
- package/esm/node_modules/conventional-commits-filter/package.json +22 -16
- package/esm/node_modules/conventional-commits-parser/README.md +49 -353
- package/esm/node_modules/conventional-commits-parser/dist/CommitParser.d.ts +40 -0
- package/esm/node_modules/conventional-commits-parser/dist/CommitParser.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-parser/dist/CommitParser.js +319 -0
- package/esm/node_modules/conventional-commits-parser/dist/cli/index.d.ts +3 -0
- package/esm/node_modules/conventional-commits-parser/dist/cli/index.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-parser/dist/cli/index.js +67 -0
- package/esm/node_modules/conventional-commits-parser/dist/cli/options.d.ts +3 -0
- package/esm/node_modules/conventional-commits-parser/dist/cli/options.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-parser/dist/cli/options.js +40 -0
- package/esm/node_modules/conventional-commits-parser/dist/cli/utils.d.ts +5 -0
- package/esm/node_modules/conventional-commits-parser/dist/cli/utils.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-parser/dist/cli/utils.js +49 -0
- package/esm/node_modules/conventional-commits-parser/dist/index.d.ts +4 -0
- package/esm/node_modules/conventional-commits-parser/dist/index.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-parser/dist/index.js +3 -0
- package/esm/node_modules/conventional-commits-parser/dist/options.d.ts +3 -0
- package/esm/node_modules/conventional-commits-parser/dist/options.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-parser/dist/options.js +27 -0
- package/esm/node_modules/conventional-commits-parser/dist/regex.d.ts +8 -0
- package/esm/node_modules/conventional-commits-parser/dist/regex.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-parser/dist/regex.js +63 -0
- package/esm/node_modules/conventional-commits-parser/dist/stream.d.ts +14 -0
- package/esm/node_modules/conventional-commits-parser/dist/stream.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-parser/dist/stream.js +38 -0
- package/esm/node_modules/conventional-commits-parser/dist/types.d.ts +100 -0
- package/esm/node_modules/conventional-commits-parser/dist/types.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-parser/dist/types.js +2 -0
- package/esm/node_modules/conventional-commits-parser/dist/utils.d.ts +41 -0
- package/esm/node_modules/conventional-commits-parser/dist/utils.d.ts.map +1 -0
- package/esm/node_modules/conventional-commits-parser/dist/utils.js +75 -0
- package/esm/node_modules/conventional-commits-parser/package.json +22 -23
- package/esm/src/cli/command-help.js +15 -0
- package/esm/src/cli/repair-configuration-description.js +98 -0
- package/esm/src/cli/run-changelog.js +51 -0
- package/esm/src/cli/run-cli.js +8 -0
- package/esm/src/features/built-in-feature-registry.js +2 -0
- package/esm/src/features/changelog-feature.js +155 -0
- package/esm/src/features/github-ci-artifacts.js +17 -3
- package/esm/src/features/github-ci-runtime-matrix.js +50 -0
- package/esm/src/features/github-release-publish-artifacts.js +5 -4
- package/esm/src/features/github-release-publish-feature.js +7 -2
- package/esm/src/features/github-workflow-cache.js +18 -0
- package/esm/src/features/npm-readme-badge.js +163 -0
- package/esm/src/features/readme-contribution-plans.js +18 -1
- package/esm/src/features/workflow-deno.js +1 -1
- package/esm/src/package/npm-name.js +5 -0
- package/esm/src/readme/contribution-blocks.js +33 -6
- package/esm/src/release/changelog-markdown.js +41 -0
- package/esm/src/release/changelog.js +155 -7
- package/esm/src/release/format-changelog.js +15 -0
- package/esm/src/release/migrate-changelog.js +92 -0
- package/esm/src/release/publish-github.js +7 -3
- package/esm/src/release/publish-npm.js +2 -2
- package/esm/src/release/publish-tag-prepare.js +63 -78
- package/esm/src/release/release-history.js +53 -0
- package/npm-dependencies.lock.json +115 -48
- package/package.json +7 -5
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/build/dependencies.js +0 -11036
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/build/index.d.ts +0 -1416
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/build/index.js +0 -100
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/build/licenses.md +0 -1767
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/build/options.js +0 -92
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/build/parser.js +0 -84
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/build/utils.js +0 -7
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/build/validate.js +0 -122
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/license +0 -9
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/package.json +0 -107
- package/esm/node_modules/conventional-commits-parser/node_modules/meow/readme.md +0 -314
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core/node_modules/conventional-changelog-writer}/cli.mjs +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core/node_modules/conventional-changelog-writer}/index.js +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core/node_modules/conventional-changelog-writer}/lib/util.js +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core/node_modules/conventional-changelog-writer}/templates/commit.hbs +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core/node_modules/conventional-changelog-writer}/templates/footer.hbs +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core/node_modules/conventional-changelog-writer}/templates/header.hbs +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core/node_modules/conventional-changelog-writer}/templates/template.hbs +0 -0
- /package/esm/node_modules/{conventional-commits-filter → conventional-changelog-core/node_modules/conventional-commits-filter}/index.js +0 -0
- /package/esm/node_modules/{conventional-commits-parser → conventional-changelog-core/node_modules/conventional-commits-parser}/cli.mjs +0 -0
- /package/esm/node_modules/{conventional-commits-parser → conventional-changelog-core/node_modules/conventional-commits-parser}/index.js +0 -0
- /package/esm/node_modules/{conventional-commits-parser → conventional-changelog-core/node_modules/conventional-commits-parser}/lib/parser.js +0 -0
- /package/esm/node_modules/{conventional-commits-parser → conventional-changelog-core/node_modules/conventional-commits-parser}/lib/regex.js +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/build/dependencies.js +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/build/index.d.ts +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/build/index.js +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/build/licenses.md +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/build/options.js +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/build/parser.js +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/build/utils.js +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/build/validate.js +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/license +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/package.json +0 -0
- /package/esm/node_modules/{conventional-changelog-writer → conventional-changelog-core}/node_modules/meow/readme.md +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
/**
|
|
3
|
+
* Get all items from an async iterable and return them as an array.
|
|
4
|
+
* @param iterable
|
|
5
|
+
* @returns A promise that resolves to an array of items.
|
|
6
|
+
*/
|
|
7
|
+
export async function toArray(iterable) {
|
|
8
|
+
const result = [];
|
|
9
|
+
for await (const item of iterable) {
|
|
10
|
+
result.push(item);
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Concatenate all buffers from an async iterable into a single Buffer.
|
|
16
|
+
* @param iterable
|
|
17
|
+
* @returns A promise that resolves to a single Buffer containing all concatenated buffers.
|
|
18
|
+
*/
|
|
19
|
+
export async function concatBufferStream(iterable) {
|
|
20
|
+
return Buffer.concat(await toArray(iterable));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Concatenate all strings from an async iterable into a single string.
|
|
24
|
+
* @param iterable
|
|
25
|
+
* @returns A promise that resolves to a single string containing all concatenated strings.
|
|
26
|
+
*/
|
|
27
|
+
export async function concatStringStream(iterable) {
|
|
28
|
+
return (await toArray(iterable)).join('');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the first item from an async iterable.
|
|
32
|
+
* @param stream
|
|
33
|
+
* @returns A promise that resolves to the first item, or null if the iterable is empty.
|
|
34
|
+
*/
|
|
35
|
+
export async function firstFromStream(stream) {
|
|
36
|
+
for await (const tag of stream) {
|
|
37
|
+
return tag;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Merges multiple Readable streams into a single Readable stream.
|
|
43
|
+
* Each chunk will be an object containing the source stream name and the chunk data.
|
|
44
|
+
* @param streams - An object where keys are stream names and values are Readable streams.
|
|
45
|
+
* @returns A merged Readable stream.
|
|
46
|
+
*/
|
|
47
|
+
export function mergeReadables(streams) {
|
|
48
|
+
const mergedStream = new Readable({
|
|
49
|
+
objectMode: true,
|
|
50
|
+
read() { }
|
|
51
|
+
});
|
|
52
|
+
let ended = 0;
|
|
53
|
+
Object.entries(streams).forEach(([name, stream], _i, entries) => {
|
|
54
|
+
stream
|
|
55
|
+
.on('data', (chunk) => mergedStream.push({
|
|
56
|
+
source: name,
|
|
57
|
+
chunk
|
|
58
|
+
}))
|
|
59
|
+
.on('end', () => {
|
|
60
|
+
ended += 1;
|
|
61
|
+
if (ended === entries.length) {
|
|
62
|
+
mergedStream.push(null);
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
.on('error', err => mergedStream.destroy(err));
|
|
66
|
+
});
|
|
67
|
+
return mergedStream;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Split stream by separator.
|
|
71
|
+
* @param stream
|
|
72
|
+
* @param separator
|
|
73
|
+
* @yields String chunks.
|
|
74
|
+
*/
|
|
75
|
+
export async function* splitStream(stream, separator) {
|
|
76
|
+
let chunk;
|
|
77
|
+
let payload;
|
|
78
|
+
let buffer = '';
|
|
79
|
+
for await (chunk of stream) {
|
|
80
|
+
buffer += chunk.toString();
|
|
81
|
+
if (buffer.includes(separator)) {
|
|
82
|
+
payload = buffer.split(separator);
|
|
83
|
+
buffer = payload.pop() || '';
|
|
84
|
+
yield* payload;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (buffer) {
|
|
88
|
+
yield buffer;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse JSON objects from a stream, separated by a delimiter (default is newline).
|
|
93
|
+
* @param stream
|
|
94
|
+
* @param delimiter
|
|
95
|
+
* @yields Parsed JSON objects of type T.
|
|
96
|
+
*/
|
|
97
|
+
export async function* parseJsonStream(stream, delimiter = /\r?\n/) {
|
|
98
|
+
let chunk;
|
|
99
|
+
let payload;
|
|
100
|
+
let buffer = '';
|
|
101
|
+
let json;
|
|
102
|
+
for await (chunk of stream) {
|
|
103
|
+
buffer += chunk.toString();
|
|
104
|
+
if (delimiter.test(buffer)) {
|
|
105
|
+
payload = buffer.split(delimiter);
|
|
106
|
+
buffer = payload.pop() || '';
|
|
107
|
+
for (json of payload) {
|
|
108
|
+
yield JSON.parse(json);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (buffer) {
|
|
113
|
+
yield JSON.parse(buffer);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLFFBQVEsQ0FBQTtBQUVqQzs7OztHQUlHO0FBQ0gsTUFBTSxDQUFDLEtBQUssVUFBVSxPQUFPLENBQUksUUFBMEI7SUFDekQsTUFBTSxNQUFNLEdBQVEsRUFBRSxDQUFBO0lBRXRCLElBQUksS0FBSyxFQUFFLE1BQU0sSUFBSSxJQUFJLFFBQVEsRUFBRSxDQUFDO1FBQ2xDLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUE7SUFDbkIsQ0FBQztJQUVELE9BQU8sTUFBTSxDQUFBO0FBQ2YsQ0FBQztBQUVEOzs7O0dBSUc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLGtCQUFrQixDQUFDLFFBQStCO0lBQ3RFLE9BQU8sTUFBTSxDQUFDLE1BQU0sQ0FBQyxNQUFNLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFBO0FBQy9DLENBQUM7QUFFRDs7OztHQUlHO0FBQ0gsTUFBTSxDQUFDLEtBQUssVUFBVSxrQkFBa0IsQ0FBQyxRQUErQjtJQUN0RSxPQUFPLENBQUMsTUFBTSxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUE7QUFDM0MsQ0FBQztBQUVEOzs7O0dBSUc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLGVBQWUsQ0FBSSxNQUF3QjtJQUMvRCxJQUFJLEtBQUssRUFBRSxNQUFNLEdBQUcsSUFBSSxNQUFNLEVBQUUsQ0FBQztRQUMvQixPQUFPLEdBQUcsQ0FBQTtJQUNaLENBQUM7SUFFRCxPQUFPLElBQUksQ0FBQTtBQUNiLENBQUM7QUFPRDs7Ozs7R0FLRztBQUNILE1BQU0sVUFBVSxjQUFjLENBSTVCLE9BQTRCO0lBRTVCLE1BQU0sWUFBWSxHQUFHLElBQUksUUFBUSxDQUFDO1FBQ2hDLFVBQVUsRUFBRSxJ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
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@simple-libs/stream-utils",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.0.0",
|
|
5
|
+
"description": "A small set of utilities for streams.",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Dan Onoshko",
|
|
8
|
+
"email": "danon0404@gmail.com",
|
|
9
|
+
"url": "https://github.com/dangreen"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://github.com/TrigenSoftware/simple-libs/tree/main/packages/stream-utils#readme",
|
|
13
|
+
"funding": "https://ko-fi.com/dangreen",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/TrigenSoftware/simple-libs.git",
|
|
17
|
+
"directory": "packages/stream-utils"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/TrigenSoftware/simple-libs/issues"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"stream",
|
|
24
|
+
"streams",
|
|
25
|
+
"utilities",
|
|
26
|
+
"utils"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 - present, TrigenSoftware
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# argue-cli
|
|
2
|
+
|
|
3
|
+
[![ESM-only package][package]][package-url]
|
|
4
|
+
[![NPM version][npm]][npm-url]
|
|
5
|
+
[![Node version][node]][node-url]
|
|
6
|
+
[![Dependencies status][deps]][deps-url]
|
|
7
|
+
[![Install size][size]][size-url]
|
|
8
|
+
[![Build status][build]][build-url]
|
|
9
|
+
[![Coverage status][coverage]][coverage-url]
|
|
10
|
+
|
|
11
|
+
[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
|
|
12
|
+
[package-url]: https://nodejs.org/api/esm.html
|
|
13
|
+
|
|
14
|
+
[npm]: https://img.shields.io/npm/v/argue-cli.svg
|
|
15
|
+
[npm-url]: https://www.npmjs.com/package/argue-cli
|
|
16
|
+
|
|
17
|
+
[node]: https://img.shields.io/node/v/argue-cli.svg
|
|
18
|
+
[node-url]: https://nodejs.org
|
|
19
|
+
|
|
20
|
+
[deps]: https://img.shields.io/librariesio/release/npm/argue-cli
|
|
21
|
+
[deps-url]: https://libraries.io/npm/argue-cli
|
|
22
|
+
|
|
23
|
+
[size]: https://packagephobia.com/badge?p=argue-cli
|
|
24
|
+
[size-url]: https://packagephobia.com/result?p=argue-cli
|
|
25
|
+
|
|
26
|
+
[build]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/Argue/tests.yml?branch=master
|
|
27
|
+
[build-url]: https://github.com/TrigenSoftware/Argue/actions
|
|
28
|
+
|
|
29
|
+
[coverage]: https://img.shields.io/codecov/c/github/TrigenSoftware/Argue.svg
|
|
30
|
+
[coverage-url]: https://app.codecov.io/gh/TrigenSoftware/Argue
|
|
31
|
+
|
|
32
|
+
A thin and strongly typed CLI arguments parser for Node.js.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
1. Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# pnpm
|
|
40
|
+
pnpm add argue-cli
|
|
41
|
+
# yarn
|
|
42
|
+
yarn add argue-cli
|
|
43
|
+
# npm
|
|
44
|
+
npm i argue-cli
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
2. Import in your code and use it!
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { read, end, expect, alias, option, readOptions } from 'argue-cli'
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Expect and read one of the commands
|
|
54
|
+
*/
|
|
55
|
+
const command = expect(
|
|
56
|
+
alias('install', 'i'),
|
|
57
|
+
'remove'
|
|
58
|
+
)
|
|
59
|
+
let options = {}
|
|
60
|
+
|
|
61
|
+
if (command === 'install') {
|
|
62
|
+
/**
|
|
63
|
+
* Read passed options
|
|
64
|
+
*/
|
|
65
|
+
options = readOptions(
|
|
66
|
+
option(alias('save', 'S'), Boolean),
|
|
67
|
+
option(alias('saveDev', 'save-dev', 'D'), Boolean),
|
|
68
|
+
option('workspace', String)
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Read next argument
|
|
74
|
+
*/
|
|
75
|
+
const packageName = read()
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Expect end of the arguments
|
|
79
|
+
*/
|
|
80
|
+
end()
|
|
81
|
+
|
|
82
|
+
/* ... */
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## API
|
|
86
|
+
|
|
87
|
+
Argue reads arguments sequentially from an internal state, which is initialized with `process.argv`. Every call consumes the arguments it reads, so you describe your CLI step by step: expect a command, read its options, read positional arguments, and finally assert the end.
|
|
88
|
+
|
|
89
|
+
> [!TIP]
|
|
90
|
+
> The internal state can be controlled manually with `setArgs(...args)` and `resetArgs()` — handy in tests.
|
|
91
|
+
|
|
92
|
+
### read
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
function read(): string
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Reads the next argument and returns it. Throws an error if there are no arguments left.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// my-cli sort-imports
|
|
102
|
+
const fileName = read() // 'sort-imports'
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### rest
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
function rest(): string[]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Reads all remaining arguments and returns them. Returns an empty array if there are none — unlike [`read`](#read), it never throws.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
// my-cli format a.js b.js c.js
|
|
115
|
+
expect('format')
|
|
116
|
+
|
|
117
|
+
const files = rest() // ['a.js', 'b.js', 'c.js']
|
|
118
|
+
|
|
119
|
+
end() // always passes after rest()
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### end
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
function end(): void
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Asserts that all arguments were consumed. Throws an error if there are any arguments left — useful to catch typos and unexpected input.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
// my-cli install --sav
|
|
132
|
+
expect('install')
|
|
133
|
+
readOptions(
|
|
134
|
+
option(alias('save', 'S'), Boolean)
|
|
135
|
+
)
|
|
136
|
+
end() // throws: Unexpected argument "--sav"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### expect
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
function expect(...argRefs: ArgRef[]): string
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Expects the next argument to be one of the given ones and returns the matched name. If an [alias](#alias) matches, the main name is returned. Throws an error on any other input.
|
|
146
|
+
|
|
147
|
+
The return type is inferred as a union of the given names:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
// my-cli i
|
|
151
|
+
const command = expect(alias('install', 'i'), 'remove')
|
|
152
|
+
// typeof command: 'install' | 'remove'
|
|
153
|
+
// command === 'install'
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### alias
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
function alias(name: string, ...aliases: string[]): AliasArgRef
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Describes an argument that has alternative names. Use it anywhere an argument name is expected — in [`expect`](#expect) and [`option`](#option).
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
alias('install', 'i')
|
|
166
|
+
alias('saveDev', 'save-dev', 'D')
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### autocase
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
function autocase(argRef: ArgRef): ArgRef
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Describes an argument that matches both camelCase and kebab-case forms. The name can be given in either form — the twin form is added as an alias. Aliases longer than one character are autocased too. Use it anywhere an argument name is expected.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
autocase('firstRelease')
|
|
179
|
+
// --firstRelease and --first-release are both accepted
|
|
180
|
+
|
|
181
|
+
autocase(alias('save-dev', 'D'))
|
|
182
|
+
// --save-dev, --saveDev and -D
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### option
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
function option(argRef: ArgRef, type: OptionConstructor): OptionReader
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Describes an option with a value of the given type, to be read by [`readOptions`](#readoptions):
|
|
192
|
+
|
|
193
|
+
- `String` — takes the next argument as a value: `--workspace packages/app`
|
|
194
|
+
- `Number` — parses the next argument as a number: `--port 8080`
|
|
195
|
+
- `Boolean` — a flag without a value, `true` when present: `--verbose`
|
|
196
|
+
- `Array` — splits the next argument by commas; repeated options are merged: `--plugins eslint,swc --plugins tsc` → `['eslint', 'swc', 'tsc']`
|
|
197
|
+
- `[String]` or `[Number]` — takes the next argument as a whole; repeated options are collected: `--match '*.{js,ts}' --match '*.css'` → `['*.{js,ts}', '*.css']`. Use it instead of `Array` for values that may contain commas of their own
|
|
198
|
+
|
|
199
|
+
### flag
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
function flag(argRef: ArgRef): OptionReader
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Describes a boolean flag with `--no-*` negation support, to be read by [`readOptions`](#readoptions): `--verbose` sets `true`, `--no-verbose` sets `false`. Use `option(argRef, Boolean)` when negation is not wanted.
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
const options = readOptions(
|
|
209
|
+
flag(autocase('firstRelease'))
|
|
210
|
+
)
|
|
211
|
+
// --first-release → { firstRelease: true }
|
|
212
|
+
// --no-first-release, --no-firstRelease → { firstRelease: false }
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### readOptions
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
function readOptions(...optionReaders: OptionReader[]): OptionResult
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Scans the arguments and reads all described options. Both `--option` and `-o` prefixes are accepted, and a value can be passed either as the next argument or inline: `--workspace packages/app` and `--workspace=packages/app` are equivalent. Arguments that don't match any described option are left untouched, so you can continue reading them afterwards.
|
|
222
|
+
|
|
223
|
+
The result is a strongly typed object, where every property is optional — an option simply may not be passed:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
// my-cli --save-dev --workspace packages/app my-package
|
|
227
|
+
const options = readOptions(
|
|
228
|
+
option(alias('saveDev', 'save-dev', 'D'), Boolean),
|
|
229
|
+
option('workspace', String)
|
|
230
|
+
)
|
|
231
|
+
// typeof options: { saveDev?: boolean, workspace?: string }
|
|
232
|
+
// options: { saveDev: true, workspace: 'packages/app' }
|
|
233
|
+
|
|
234
|
+
const packageName = read() // 'my-package'
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## TypeScript
|
|
238
|
+
|
|
239
|
+
In the [API section](#api) types are described in a simplified way. A detailed example of the inferred types you can see in [type tests](src/types.spec.ts).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AliasArgRef, ArgRef, OptionConstructor, OptionsReaderState, OptionsReaderRead, OptionResult } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Describe argument with aliases.
|
|
4
|
+
* @param name - Main name.
|
|
5
|
+
* @param alias - Alias name.
|
|
6
|
+
* @param restAliases - Rest aliases.
|
|
7
|
+
* @returns Description of argument with aliases..
|
|
8
|
+
*/
|
|
9
|
+
export declare function alias<T extends string>(name: T, alias: string, ...restAliases: string[]): AliasArgRef<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Describe argument that matches both camelCase and kebab-case forms.
|
|
12
|
+
* Name and every alias longer than one character get the twin form as an alias.
|
|
13
|
+
* @param argRef - Argument name in either form.
|
|
14
|
+
* @returns Description of argument with the twin forms as aliases.
|
|
15
|
+
*/
|
|
16
|
+
export declare function autocase<T extends string>(argRef: ArgRef<T>): ArgRef<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Describe option with value.
|
|
19
|
+
* @param argRef - Option name.
|
|
20
|
+
* @param type - Value type.
|
|
21
|
+
* @returns Option reader.
|
|
22
|
+
*/
|
|
23
|
+
export declare function option<T extends string, K extends OptionConstructor>(argRef: ArgRef<T>, type: K): (option: string, read: OptionsReaderRead, options: OptionsReaderState) => OptionResult<T, K> | null;
|
|
24
|
+
/**
|
|
25
|
+
* Describe boolean flag with `--no-*` negation support.
|
|
26
|
+
* @param argRef - Flag name.
|
|
27
|
+
* @returns Option reader.
|
|
28
|
+
*/
|
|
29
|
+
export declare function flag<T extends string>(argRef: ArgRef<T>): (option: string) => OptionResult<T, BooleanConstructor> | null;
|
|
30
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,MAAM,EACN,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACb,MAAM,YAAY,CAAA;AAGnB;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAKxG;AAUD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAuBvE;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,iBAAiB,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,YAE5E,MAAM,QAAQ,iBAAiB,WAAW,kBAAkB,+BA4E/E;AAID;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,YACtC,MAAM,gDAiBvB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal state of arguments.
|
|
3
|
+
*/
|
|
4
|
+
export declare const argv: string[];
|
|
5
|
+
/**
|
|
6
|
+
* Reset arguments state.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resetArgs(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Set arguments state.
|
|
11
|
+
* @param args
|
|
12
|
+
*/
|
|
13
|
+
export declare function setArgs(...args: string[]): void;
|
|
14
|
+
//# sourceMappingURL=argv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"argv.d.ts","sourceRoot":"","sources":["../src/argv.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,IAAI,UAAuC,CAAA;AAExD;;GAEG;AACH,wBAAgB,SAAS,SAGxB;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,QAGxC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ArgRef } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read next argument.
|
|
4
|
+
* Throws error if no next argument.
|
|
5
|
+
* @returns Next argument.
|
|
6
|
+
*/
|
|
7
|
+
export declare function read(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Read all remaining arguments.
|
|
10
|
+
* @returns Remaining arguments, empty array if none.
|
|
11
|
+
*/
|
|
12
|
+
export declare function rest(): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Expectation of the end.
|
|
15
|
+
* Throws an error if there are more arguments left.
|
|
16
|
+
*/
|
|
17
|
+
export declare function end(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Expect one of the given arguments.
|
|
20
|
+
* @param argRefs
|
|
21
|
+
* @returns Expected full argument name.
|
|
22
|
+
*/
|
|
23
|
+
export declare function expect<T extends string>(...argRefs: [...ArgRef<T>[]]): T;
|
|
24
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAIxC;;;;GAIG;AACH,wBAAgB,IAAI,WAQnB;AAED;;;GAGG;AACH,wBAAgB,IAAI,aAEnB;AAED;;;GAGG;AACH,wBAAgB,GAAG,SAIlB;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KASpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
|