cli-kiss 0.2.7 → 0.2.8

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.
Files changed (39) hide show
  1. package/dist/index.d.ts +127 -137
  2. package/dist/index.js +2 -2
  3. package/dist/index.js.map +1 -1
  4. package/docs/.vitepress/config.mts +1 -1
  5. package/docs/.vitepress/theme/Layout.vue +16 -0
  6. package/docs/.vitepress/theme/index.ts +5 -1
  7. package/docs/.vitepress/theme/style.css +5 -1
  8. package/docs/guide/02_commands.md +1 -1
  9. package/docs/guide/03_options.md +11 -11
  10. package/docs/guide/05_input_types.md +9 -10
  11. package/docs/guide/06_run_as_cli.md +1 -1
  12. package/docs/index.md +2 -2
  13. package/docs/public/favicon.ico +0 -0
  14. package/docs/public/logo.png +0 -0
  15. package/package.json +1 -1
  16. package/src/index.ts +1 -1
  17. package/src/lib/Command.ts +45 -39
  18. package/src/lib/Operation.ts +28 -20
  19. package/src/lib/Option.ts +196 -127
  20. package/src/lib/Positional.ts +44 -23
  21. package/src/lib/Reader.ts +194 -226
  22. package/src/lib/Run.ts +19 -8
  23. package/src/lib/Suggest.ts +78 -0
  24. package/src/lib/Type.ts +36 -37
  25. package/src/lib/Typo.ts +58 -55
  26. package/src/lib/Usage.ts +12 -12
  27. package/tests/unit.Reader.commons.ts +92 -116
  28. package/tests/unit.Reader.parsings.ts +14 -26
  29. package/tests/unit.Reader.shortBig.ts +81 -96
  30. package/tests/unit.command.aliases.ts +100 -0
  31. package/tests/unit.command.execute.ts +1 -1
  32. package/tests/unit.command.usage.ts +12 -6
  33. package/tests/unit.fuzzed.alternatives.ts +35 -26
  34. package/tests/unit.runner.colors.ts +8 -33
  35. package/tests/unit.runner.cycle.ts +118 -146
  36. package/tests/unit.runner.errors.ts +25 -22
  37. package/docs/public/hero.png +0 -0
  38. package/src/lib/Similarity.ts +0 -41
  39. package/tests/unit.Reader.aliases.ts +0 -62
@@ -1,41 +0,0 @@
1
- export function similaritySort<Value>(
2
- reference: string,
3
- candidates: { [key: string]: Value } | Array<{ key: string; value: Value }>,
4
- ): Array<Value> {
5
- let entries = Array.isArray(candidates)
6
- ? candidates.map(({ key, value }) => [key, value] as const)
7
- : Object.entries(candidates);
8
- const ranked = entries.map(([key, value]) => {
9
- const score =
10
- damerauLevenshtein(reference, key) /
11
- Math.max(reference.length, key.length);
12
- return { key, value, score };
13
- });
14
- return ranked.sort((a, b) => a.score - b.score).map((v) => v.value);
15
- }
16
-
17
- function damerauLevenshtein(a: string, b: string): number {
18
- const m = a.length;
19
- const n = b.length;
20
- const dp = Array.from({ length: m + 1 }, () => Array<number>(n + 1).fill(0));
21
- for (let i = 0; i <= m; i++) {
22
- dp[i]![0] = i;
23
- }
24
- for (let j = 0; j <= n; j++) {
25
- dp[0]![j] = j;
26
- }
27
- for (let i = 1; i <= m; i++) {
28
- for (let j = 1; j <= n; j++) {
29
- const cost = a[i - 1] === b[j - 1] ? 0 : 1;
30
- dp[i]![j] = Math.min(
31
- dp[i - 1]![j]! + 1,
32
- dp[i]![j - 1]! + 1,
33
- dp[i - 1]![j - 1]! + cost,
34
- );
35
- if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
36
- dp[i]![j] = Math.min(dp[i]![j]!, dp[i - 2]![j - 2]! + cost);
37
- }
38
- }
39
- }
40
- return dp[m]![n]!;
41
- }
@@ -1,62 +0,0 @@
1
- import { expect, it } from "@jest/globals";
2
- import { ReaderArgs, ReaderOptionParsing } from "../src";
3
-
4
- it("run", async function () {
5
- const readerArgs = new ReaderArgs([
6
- "--option=1.1",
7
- "--option-alias1=1.2",
8
- "--option-alias2",
9
- "1.3",
10
- "-pts=1.4",
11
- "-o",
12
- "1.5",
13
- "--flag1-alias",
14
- "-fa2=woops",
15
- "-fa2o=1.6",
16
- ]);
17
-
18
- const kOption = readerArgs.registerOption({
19
- longs: ["option", "option-alias1", "option-alias2"],
20
- shorts: ["pts", "o"],
21
- parsing: optionValueFixedUniqueParsing,
22
- });
23
- const kFlag1 = readerArgs.registerOption({
24
- longs: ["flag1", "flag1-alias"],
25
- shorts: [],
26
- parsing: optionFlagParsing,
27
- });
28
- const kFlag2 = readerArgs.registerOption({
29
- longs: ["flag2"],
30
- shorts: ["fa2"],
31
- parsing: optionFlagParsing,
32
- });
33
-
34
- expect(readerArgs.consumePositional()).toStrictEqual(undefined);
35
-
36
- expect(readerArgs.getOptionValues(kOption)).toStrictEqual([
37
- { inlined: "1.1", separated: [] },
38
- { inlined: "1.2", separated: [] },
39
- { inlined: null, separated: ["1.3"] },
40
- { inlined: "1.4", separated: [] },
41
- { inlined: null, separated: ["1.5"] },
42
- { inlined: "1.6", separated: [] },
43
- ]);
44
- expect(readerArgs.getOptionValues(kFlag1)).toStrictEqual([
45
- { inlined: null, separated: [] },
46
- ]);
47
- expect(readerArgs.getOptionValues(kFlag2)).toStrictEqual([
48
- { inlined: "woops", separated: [] },
49
- { inlined: null, separated: [] },
50
- ]);
51
- });
52
-
53
- const optionFlagParsing: ReaderOptionParsing = {
54
- consumeShortGroup: false,
55
- consumeNextArg: () => false,
56
- };
57
-
58
- const optionValueFixedUniqueParsing: ReaderOptionParsing = {
59
- consumeShortGroup: true,
60
- consumeNextArg: (inlined, separated) =>
61
- inlined === null && separated.length === 0,
62
- };