@clerc/utils 0.8.1 → 0.8.3

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/dist/index.d.ts CHANGED
@@ -1,271 +1,32 @@
1
- import * as terminal_link from 'terminal-link';
2
- import * as child_process from 'child_process';
3
- import * as picocolors_types from 'picocolors/types';
4
- import * as tasuku from 'tasuku';
5
- import * as kons from 'kons';
6
- import * as konsola from 'kons/consola';
7
- import spinner from 'ora';
8
- import open from 'open';
9
- import progress from 'cli-progress';
10
- import columns from 'terminal-columns';
11
- import Table from 'cli-table3';
12
- import { prompt } from 'enquirer';
1
+ import * as clerc from 'clerc';
2
+ import { Command } from 'clerc';
13
3
 
14
- declare const Toolkit: {
15
- prompt: typeof prompt;
16
- task: tasuku.Task;
17
- figures: {
18
- readonly tick: string;
19
- readonly info: string;
20
- readonly warning: string;
21
- readonly cross: string;
22
- readonly square: string;
23
- readonly squareSmall: string;
24
- readonly squareSmallFilled: string;
25
- readonly squareDarkShade: string;
26
- readonly squareMediumShade: string;
27
- readonly squareLightShade: string;
28
- readonly squareTop: string;
29
- readonly squareBottom: string;
30
- readonly squareLeft: string;
31
- readonly squareRight: string;
32
- readonly squareCenter: string;
33
- readonly circle: string;
34
- readonly circleFilled: string;
35
- readonly circleDotted: string;
36
- readonly circleDouble: string;
37
- readonly circleCircle: string;
38
- readonly circleCross: string;
39
- readonly circlePipe: string;
40
- readonly circleQuestionMark: string;
41
- readonly radioOn: string;
42
- readonly radioOff: string;
43
- readonly checkboxOn: string;
44
- readonly checkboxOff: string;
45
- readonly checkboxCircleOn: string;
46
- readonly checkboxCircleOff: string;
47
- readonly questionMarkPrefix: string;
48
- readonly bullet: string;
49
- readonly dot: string;
50
- readonly ellipsis: string;
51
- readonly pointer: string;
52
- readonly pointerSmall: string;
53
- readonly triangleUp: string;
54
- readonly triangleUpSmall: string;
55
- readonly triangleUpOutline: string;
56
- readonly triangleDown: string;
57
- readonly triangleDownSmall: string;
58
- readonly triangleLeft: string;
59
- readonly triangleLeftSmall: string;
60
- readonly triangleRight: string;
61
- readonly triangleRightSmall: string;
62
- readonly lozenge: string;
63
- readonly lozengeOutline: string;
64
- readonly home: string;
65
- readonly hamburger: string;
66
- readonly smiley: string;
67
- readonly mustache: string;
68
- readonly heart: string;
69
- readonly star: string;
70
- readonly play: string;
71
- readonly musicNote: string;
72
- readonly musicNoteBeamed: string;
73
- readonly nodejs: string;
74
- readonly arrowUp: string;
75
- readonly arrowDown: string;
76
- readonly arrowLeft: string;
77
- readonly arrowRight: string;
78
- readonly arrowLeftRight: string;
79
- readonly arrowUpDown: string;
80
- readonly almostEqual: string;
81
- readonly notEqual: string;
82
- readonly lessOrEqual: string;
83
- readonly greaterOrEqual: string;
84
- readonly identical: string;
85
- readonly infinity: string;
86
- readonly subscriptZero: string;
87
- readonly subscriptOne: string;
88
- readonly subscriptTwo: string;
89
- readonly subscriptThree: string;
90
- readonly subscriptFour: string;
91
- readonly subscriptFive: string;
92
- readonly subscriptSix: string;
93
- readonly subscriptSeven: string;
94
- readonly subscriptEight: string;
95
- readonly subscriptNine: string;
96
- readonly oneHalf: string;
97
- readonly oneThird: string;
98
- readonly oneQuarter: string;
99
- readonly oneFifth: string;
100
- readonly oneSixth: string;
101
- readonly oneSeventh: string;
102
- readonly oneEighth: string;
103
- readonly oneNinth: string;
104
- readonly oneTenth: string;
105
- readonly twoThirds: string;
106
- readonly twoFifths: string;
107
- readonly threeQuarters: string;
108
- readonly threeFifths: string;
109
- readonly threeEighths: string;
110
- readonly fourFifths: string;
111
- readonly fiveSixths: string;
112
- readonly fiveEighths: string;
113
- readonly sevenEighth: string;
114
- readonly line: string;
115
- readonly lineBold: string;
116
- readonly lineDouble: string;
117
- readonly lineDashed0: string;
118
- readonly lineDashed1: string;
119
- readonly lineDashed2: string;
120
- readonly lineDashed3: string;
121
- readonly lineDashed4: string;
122
- readonly lineDashed5: string;
123
- readonly lineDashed6: string;
124
- readonly lineDashed7: string;
125
- readonly lineDashed8: string;
126
- readonly lineDashed9: string;
127
- readonly lineDashed10: string;
128
- readonly lineDashed11: string;
129
- readonly lineDashed12: string;
130
- readonly lineDashed13: string;
131
- readonly lineDashed14: string;
132
- readonly lineDashed15: string;
133
- readonly lineVertical: string;
134
- readonly lineVerticalBold: string;
135
- readonly lineVerticalDouble: string;
136
- readonly lineVerticalDashed0: string;
137
- readonly lineVerticalDashed1: string;
138
- readonly lineVerticalDashed2: string;
139
- readonly lineVerticalDashed3: string;
140
- readonly lineVerticalDashed4: string;
141
- readonly lineVerticalDashed5: string;
142
- readonly lineVerticalDashed6: string;
143
- readonly lineVerticalDashed7: string;
144
- readonly lineVerticalDashed8: string;
145
- readonly lineVerticalDashed9: string;
146
- readonly lineVerticalDashed10: string;
147
- readonly lineVerticalDashed11: string;
148
- readonly lineDownLeft: string;
149
- readonly lineDownLeftArc: string;
150
- readonly lineDownBoldLeftBold: string;
151
- readonly lineDownBoldLeft: string;
152
- readonly lineDownLeftBold: string;
153
- readonly lineDownDoubleLeftDouble: string;
154
- readonly lineDownDoubleLeft: string;
155
- readonly lineDownLeftDouble: string;
156
- readonly lineDownRight: string;
157
- readonly lineDownRightArc: string;
158
- readonly lineDownBoldRightBold: string;
159
- readonly lineDownBoldRight: string;
160
- readonly lineDownRightBold: string;
161
- readonly lineDownDoubleRightDouble: string;
162
- readonly lineDownDoubleRight: string;
163
- readonly lineDownRightDouble: string;
164
- readonly lineUpLeft: string;
165
- readonly lineUpLeftArc: string;
166
- readonly lineUpBoldLeftBold: string;
167
- readonly lineUpBoldLeft: string;
168
- readonly lineUpLeftBold: string;
169
- readonly lineUpDoubleLeftDouble: string;
170
- readonly lineUpDoubleLeft: string;
171
- readonly lineUpLeftDouble: string;
172
- readonly lineUpRight: string;
173
- readonly lineUpRightArc: string;
174
- readonly lineUpBoldRightBold: string;
175
- readonly lineUpBoldRight: string;
176
- readonly lineUpRightBold: string;
177
- readonly lineUpDoubleRightDouble: string;
178
- readonly lineUpDoubleRight: string;
179
- readonly lineUpRightDouble: string;
180
- readonly lineUpDownLeft: string;
181
- readonly lineUpBoldDownBoldLeftBold: string;
182
- readonly lineUpBoldDownBoldLeft: string;
183
- readonly lineUpDownLeftBold: string;
184
- readonly lineUpBoldDownLeftBold: string;
185
- readonly lineUpDownBoldLeftBold: string;
186
- readonly lineUpDownBoldLeft: string;
187
- readonly lineUpBoldDownLeft: string;
188
- readonly lineUpDoubleDownDoubleLeftDouble: string;
189
- readonly lineUpDoubleDownDoubleLeft: string;
190
- readonly lineUpDownLeftDouble: string;
191
- readonly lineUpDownRight: string;
192
- readonly lineUpBoldDownBoldRightBold: string;
193
- readonly lineUpBoldDownBoldRight: string;
194
- readonly lineUpDownRightBold: string;
195
- readonly lineUpBoldDownRightBold: string;
196
- readonly lineUpDownBoldRightBold: string;
197
- readonly lineUpDownBoldRight: string;
198
- readonly lineUpBoldDownRight: string;
199
- readonly lineUpDoubleDownDoubleRightDouble: string;
200
- readonly lineUpDoubleDownDoubleRight: string;
201
- readonly lineUpDownRightDouble: string;
202
- readonly lineDownLeftRight: string;
203
- readonly lineDownBoldLeftBoldRightBold: string;
204
- readonly lineDownLeftBoldRightBold: string;
205
- readonly lineDownBoldLeftRight: string;
206
- readonly lineDownBoldLeftBoldRight: string;
207
- readonly lineDownBoldLeftRightBold: string;
208
- readonly lineDownLeftRightBold: string;
209
- readonly lineDownLeftBoldRight: string;
210
- readonly lineDownDoubleLeftDoubleRightDouble: string;
211
- readonly lineDownDoubleLeftRight: string;
212
- readonly lineDownLeftDoubleRightDouble: string;
213
- readonly lineUpLeftRight: string;
214
- readonly lineUpBoldLeftBoldRightBold: string;
215
- readonly lineUpLeftBoldRightBold: string;
216
- readonly lineUpBoldLeftRight: string;
217
- readonly lineUpBoldLeftBoldRight: string;
218
- readonly lineUpBoldLeftRightBold: string;
219
- readonly lineUpLeftRightBold: string;
220
- readonly lineUpLeftBoldRight: string;
221
- readonly lineUpDoubleLeftDoubleRightDouble: string;
222
- readonly lineUpDoubleLeftRight: string;
223
- readonly lineUpLeftDoubleRightDouble: string;
224
- readonly lineUpDownLeftRight: string;
225
- readonly lineUpBoldDownBoldLeftBoldRightBold: string;
226
- readonly lineUpDownBoldLeftBoldRightBold: string;
227
- readonly lineUpBoldDownLeftBoldRightBold: string;
228
- readonly lineUpBoldDownBoldLeftRightBold: string;
229
- readonly lineUpBoldDownBoldLeftBoldRight: string;
230
- readonly lineUpBoldDownLeftRight: string;
231
- readonly lineUpDownBoldLeftRight: string;
232
- readonly lineUpDownLeftBoldRight: string;
233
- readonly lineUpDownLeftRightBold: string;
234
- readonly lineUpBoldDownBoldLeftRight: string;
235
- readonly lineUpDownLeftBoldRightBold: string;
236
- readonly lineUpBoldDownLeftBoldRight: string;
237
- readonly lineUpBoldDownLeftRightBold: string;
238
- readonly lineUpDownBoldLeftBoldRight: string;
239
- readonly lineUpDownBoldLeftRightBold: string;
240
- readonly lineUpDoubleDownDoubleLeftDoubleRightDouble: string;
241
- readonly lineUpDoubleDownDoubleLeftRight: string;
242
- readonly lineUpDownLeftDoubleRightDouble: string;
243
- readonly lineCross: string;
244
- readonly lineBackslash: string;
245
- readonly lineSlash: string;
246
- };
247
- colors: picocolors_types.Colors & {
248
- createColors: (enabled?: boolean | undefined) => picocolors_types.Colors;
249
- };
250
- spinner: typeof spinner;
251
- open: {
252
- (target: string, options?: open.Options | undefined): Promise<child_process.ChildProcess>;
253
- apps: Record<open.AppName, string | readonly string[]>;
254
- openApp: (name: string | readonly string[], options?: open.OpenAppOptions | undefined) => Promise<child_process.ChildProcess>;
255
- };
256
- progress: typeof progress;
257
- columns: typeof columns;
258
- link: {
259
- (text: string, url: string, options?: terminal_link.Options | undefined): string;
260
- readonly stderr: {
261
- (text: string, url: string, options?: terminal_link.Options | undefined): string;
262
- readonly isSupported: boolean;
263
- };
264
- readonly isSupported: boolean;
265
- };
266
- kons: typeof kons;
267
- konsola: typeof konsola;
268
- Table: Table;
269
- };
4
+ /**
5
+ * Copied from type-fest
6
+ */
7
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
8
+ /**
9
+ * Copied from type-fest
10
+ */
11
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
12
+ type Dict<T> = Record<string, T>;
13
+ type MustArray<T> = T extends any[] ? T : [T];
14
+ type MaybeArray<T> = T | T[];
15
+ type GetLength<T extends any[]> = T extends {
16
+ length: infer L extends number;
17
+ } ? L : never;
18
+ type GetTail<T extends any[]> = T extends [infer _Head, ...infer Tail] ? Tail : never;
19
+ type EnhanceSingle<T, E extends Dict<any>> = T & E;
20
+ type Enhance<T, E extends Dict<any> | Dict<any>[]> = GetLength<MustArray<E>> extends 0 ? T : Enhance<EnhanceSingle<T, MustArray<E>[0]>, GetTail<MustArray<E>>>;
21
+ declare const mustArray: <T>(a: MaybeArray<T>) => T[];
22
+ type CamelCase<T extends string> = T extends `${infer A}-${infer B}${infer C}` ? `${A}${Capitalize<B>}${CamelCase<C>}` : T;
23
+ declare const camelCase: <T extends string>(s: T) => CamelCase<T>;
24
+ type KebabCase<T extends string, A extends string = ""> = T extends `${infer F}${infer R}` ? KebabCase<R, `${A}${F extends Lowercase<F> ? "" : "-"}${Lowercase<F>}`> : A;
25
+ declare const kebabCase: <T extends string>(s: T) => KebabCase<T, "">;
26
+ declare const gracefulFlagName: (n: string) => string;
27
+ declare const gracefulVersion: (v: string) => string;
28
+ declare const arrayStartsWith: <T>(arr: T[], start: T[]) => boolean;
29
+ declare const arrayEquals: <T>(arr1: T[], arr2: T[]) => boolean;
30
+ declare const generateCommandRecordFromCommandArray: <C extends Command<string, clerc.CommandOptions<string[], MaybeArray<string>, Dict<clerc.FlagOptions>>>>(commands: C[]) => Dict<C>;
270
31
 
271
- export { Toolkit, Toolkit as default };
32
+ export { CamelCase, Dict, Enhance, GetLength, GetTail, KebabCase, LiteralUnion, MaybeArray, MustArray, Primitive, arrayEquals, arrayStartsWith, camelCase, generateCommandRecordFromCommandArray, gracefulFlagName, gracefulVersion, kebabCase, mustArray };
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ const mustArray = (a) => Array.isArray(a) ? a : [a];
2
+ const camelCase = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
3
+ const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
4
+ const gracefulFlagName = (n) => n.length <= 1 ? `-${n}` : `--${n}`;
5
+ const gracefulVersion = (v) => v.length === 0 ? "" : v.startsWith("v") ? v : `v${v}`;
6
+ const arrayStartsWith = (arr, start) => {
7
+ if (start.length > arr.length) {
8
+ return false;
9
+ }
10
+ return arr.slice(0, start.length).every((item, i) => item === start[i]);
11
+ };
12
+ const arrayEquals = (arr1, arr2) => {
13
+ if (arr2.length !== arr1.length) {
14
+ return false;
15
+ }
16
+ return arr1.every((item, i) => item === arr2[i]);
17
+ };
18
+ const generateCommandRecordFromCommandArray = (commands) => {
19
+ const record = {};
20
+ for (const command of commands) {
21
+ record[command.name] = command;
22
+ }
23
+ return record;
24
+ };
25
+
26
+ export { arrayEquals, arrayStartsWith, camelCase, generateCommandRecordFromCommandArray, gracefulFlagName, gracefulVersion, kebabCase, mustArray };
package/dist/index.mjs CHANGED
@@ -1,29 +1,26 @@
1
- import * as kons from 'kons';
2
- import * as konsola from 'kons/consola';
3
- import colors from 'picocolors';
4
- import figures from 'figures';
5
- import task from 'tasuku';
6
- import spinner from 'ora';
7
- import open from 'open';
8
- import progress from 'cli-progress';
9
- import columns from 'terminal-columns';
10
- import link from 'terminal-link';
11
- import Table from 'cli-table3';
12
- import { prompt } from 'enquirer';
13
-
14
- const Toolkit = {
15
- prompt,
16
- task,
17
- figures,
18
- colors,
19
- spinner,
20
- open,
21
- progress,
22
- columns,
23
- link,
24
- kons,
25
- konsola,
26
- Table
1
+ const mustArray = (a) => Array.isArray(a) ? a : [a];
2
+ const camelCase = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
3
+ const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
4
+ const gracefulFlagName = (n) => n.length <= 1 ? `-${n}` : `--${n}`;
5
+ const gracefulVersion = (v) => v.length === 0 ? "" : v.startsWith("v") ? v : `v${v}`;
6
+ const arrayStartsWith = (arr, start) => {
7
+ if (start.length > arr.length) {
8
+ return false;
9
+ }
10
+ return arr.slice(0, start.length).every((item, i) => item === start[i]);
11
+ };
12
+ const arrayEquals = (arr1, arr2) => {
13
+ if (arr2.length !== arr1.length) {
14
+ return false;
15
+ }
16
+ return arr1.every((item, i) => item === arr2[i]);
17
+ };
18
+ const generateCommandRecordFromCommandArray = (commands) => {
19
+ const record = {};
20
+ for (const command of commands) {
21
+ record[command.name] = command;
22
+ }
23
+ return record;
27
24
  };
28
25
 
29
- export { Toolkit, Toolkit as default };
26
+ export { arrayEquals, arrayStartsWith, camelCase, generateCommandRecordFromCommandArray, gracefulFlagName, gracefulVersion, kebabCase, mustArray };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/utils",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
5
5
  "description": "Clerc utils",
6
6
  "keywords": [
@@ -11,8 +11,10 @@
11
11
  "arguments",
12
12
  "argv",
13
13
  "args",
14
- "terminal"
14
+ "terminal",
15
+ "utils"
15
16
  ],
17
+ "type": "module",
16
18
  "homepage": "https://github.com/so1ve/clerc/tree/main/packages/utils#readme",
17
19
  "repository": {
18
20
  "type": "git",
@@ -27,11 +29,10 @@
27
29
  "exports": {
28
30
  ".": {
29
31
  "types": "./dist/index.d.ts",
30
- "require": "./dist/index.cjs",
31
32
  "import": "./dist/index.mjs"
32
33
  }
33
34
  },
34
- "main": "dist/index.cjs",
35
+ "main": "dist/index.js",
35
36
  "module": "dist/index.mjs",
36
37
  "types": "dist/index.d.ts",
37
38
  "files": [
@@ -40,23 +41,6 @@
40
41
  "publishConfig": {
41
42
  "access": "public"
42
43
  },
43
- "peerDependencies": {
44
- "clerc": "*"
45
- },
46
- "dependencies": {
47
- "@types/cli-progress": "^3.11.0",
48
- "cli-progress": "^3.11.2",
49
- "cli-table3": "^0.6.3",
50
- "enquirer": "^2.3.6",
51
- "figures": "^5.0.0",
52
- "kons": "^0.5.4",
53
- "open": "^8.4.0",
54
- "ora": "^6.1.2",
55
- "picocolors": "^1.0.0",
56
- "tasuku": "^2.0.0",
57
- "terminal-columns": "^1.4.1",
58
- "terminal-link": "^3.0.0"
59
- },
60
44
  "scripts": {
61
45
  "build": "puild",
62
46
  "watch": "puild --watch"
package/dist/index.cjs DELETED
@@ -1,66 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var kons = require('kons');
6
- var konsola = require('kons/consola');
7
- var colors = require('picocolors');
8
- var figures = require('figures');
9
- var task = require('tasuku');
10
- var spinner = require('ora');
11
- var open = require('open');
12
- var progress = require('cli-progress');
13
- var columns = require('terminal-columns');
14
- var link = require('terminal-link');
15
- var Table = require('cli-table3');
16
- var enquirer = require('enquirer');
17
-
18
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
-
20
- function _interopNamespace(e) {
21
- if (e && e.__esModule) return e;
22
- var n = Object.create(null);
23
- if (e) {
24
- Object.keys(e).forEach(function (k) {
25
- if (k !== 'default') {
26
- var d = Object.getOwnPropertyDescriptor(e, k);
27
- Object.defineProperty(n, k, d.get ? d : {
28
- enumerable: true,
29
- get: function () { return e[k]; }
30
- });
31
- }
32
- });
33
- }
34
- n["default"] = e;
35
- return Object.freeze(n);
36
- }
37
-
38
- var kons__namespace = /*#__PURE__*/_interopNamespace(kons);
39
- var konsola__namespace = /*#__PURE__*/_interopNamespace(konsola);
40
- var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
41
- var figures__default = /*#__PURE__*/_interopDefaultLegacy(figures);
42
- var task__default = /*#__PURE__*/_interopDefaultLegacy(task);
43
- var spinner__default = /*#__PURE__*/_interopDefaultLegacy(spinner);
44
- var open__default = /*#__PURE__*/_interopDefaultLegacy(open);
45
- var progress__default = /*#__PURE__*/_interopDefaultLegacy(progress);
46
- var columns__default = /*#__PURE__*/_interopDefaultLegacy(columns);
47
- var link__default = /*#__PURE__*/_interopDefaultLegacy(link);
48
- var Table__default = /*#__PURE__*/_interopDefaultLegacy(Table);
49
-
50
- const Toolkit = {
51
- prompt: enquirer.prompt,
52
- task: task__default["default"],
53
- figures: figures__default["default"],
54
- colors: colors__default["default"],
55
- spinner: spinner__default["default"],
56
- open: open__default["default"],
57
- progress: progress__default["default"],
58
- columns: columns__default["default"],
59
- link: link__default["default"],
60
- kons: kons__namespace,
61
- konsola: konsola__namespace,
62
- Table: Table__default["default"]
63
- };
64
-
65
- exports.Toolkit = Toolkit;
66
- exports["default"] = Toolkit;