massarg 1.0.6 → 2.0.0-pre.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "massarg",
3
- "version": "1.0.6",
3
+ "version": "2.0.0-pre.1",
4
4
  "description": "Flexible, powerful, and simple command/argument parser for CLI applications",
5
5
  "keywords": [
6
6
  "shell",
@@ -15,22 +15,30 @@
15
15
  "author": "Chen Asraf <chenasrafil@gmail.com>",
16
16
  "license": "Apache",
17
17
  "scripts": {
18
- "clean": "rm -rf build",
19
- "build": "echo $(pwd); yarn clean && tsc -p tsconfig.build.json && cp package.json README.md build",
20
- "develop": "tsc --watch",
21
- "test": "jest"
18
+ "build": "tsc -p tsconfig.build.json && cp package.json README.md build",
19
+ "dev": "tsc --watch",
20
+ "cmd": "ts-node src/sample.ts",
21
+ "test": "jest",
22
+ "doc": "typedoc --out docs src/**/*.ts --exclude src/sample.ts --plugin typedoc-plugin-zod --theme default",
23
+ "deploy-doc": "pnpm doc && gh-pages -d docs",
24
+ "semantic-release": "semantic-release"
22
25
  },
23
26
  "devDependencies": {
24
- "@types/jest": "^27.0.3",
25
- "@types/lodash": "^4.14.177",
26
- "@types/node": "^16.11.11",
27
- "jest": "^27.4.3",
28
- "ts-jest": "^27.0.7",
29
- "ts-node": "^10.1.0",
30
- "typescript": "^4.5.2"
27
+ "@semantic-release/changelog": "^6.0.3",
28
+ "@semantic-release/exec": "^6.0.3",
29
+ "@semantic-release/git": "^10.0.1",
30
+ "@types/jest": "^29.5.8",
31
+ "@types/node": "^20.9.2",
32
+ "gh-pages": "^6.1.0",
33
+ "jest": "^29.7.0",
34
+ "semantic-release": "^22.0.8",
35
+ "ts-jest": "^29.1.1",
36
+ "ts-node": "^10.9.1",
37
+ "typedoc": "^0.25.3",
38
+ "typedoc-plugin-zod": "^1.1.0",
39
+ "typescript": "^5.2.2"
31
40
  },
32
41
  "dependencies": {
33
- "chalk": "^4.1.2",
34
- "lodash": "^4.17.21"
42
+ "zod": "^3.22.4"
35
43
  }
36
44
  }
package/style.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import z from 'zod';
2
+ export declare const ansiStyles: {
3
+ reset: string;
4
+ bold: string;
5
+ underline: string;
6
+ black: string;
7
+ };
8
+ export declare const ansiColors: {
9
+ red: string;
10
+ green: string;
11
+ yellow: string;
12
+ blue: string;
13
+ magenta: string;
14
+ cyan: string;
15
+ white: string;
16
+ gray: string;
17
+ grey: string;
18
+ brightRed: string;
19
+ brightGreen: string;
20
+ brightYellow: string;
21
+ brightBlue: string;
22
+ brightMagenta: string;
23
+ brightCyan: string;
24
+ brightWhite: string;
25
+ };
26
+ export declare const StringStyle: z.ZodObject<{
27
+ bold: z.ZodOptional<z.ZodBoolean>;
28
+ underline: z.ZodOptional<z.ZodBoolean>;
29
+ color: z.ZodOptional<z.ZodEnum<["red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite", ...("red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite")[]]>>;
30
+ reset: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
31
+ }, "strip", z.ZodTypeAny, {
32
+ bold?: boolean | undefined;
33
+ underline?: boolean | undefined;
34
+ color?: "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite" | undefined;
35
+ reset?: boolean | undefined;
36
+ }, {
37
+ bold?: boolean | undefined;
38
+ underline?: boolean | undefined;
39
+ color?: "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite" | undefined;
40
+ reset?: boolean | undefined;
41
+ }>;
42
+ export type StringStyle = z.infer<typeof StringStyle>;
43
+ export declare function format(string: string, style?: StringStyle): string;
44
+ export declare function stripStyle(string: string): string;
45
+ //# sourceMappingURL=style.d.ts.map
package/style.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAGnB,eAAO,MAAM,UAAU;;;;;CAKtB,CAAA;AAED,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;CAiBtB,CAAA;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;EAKtB,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAA;AAErD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,WAAgB,GAAG,MAAM,CAOtE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD"}
package/style.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.stripStyle = exports.format = exports.StringStyle = exports.ansiColors = exports.ansiStyles = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const utils_1 = require("./utils");
9
+ exports.ansiStyles = {
10
+ reset: '\x1b[0m',
11
+ bold: '\x1b[1m',
12
+ underline: '\x1b[4m',
13
+ black: '\x1b[30m',
14
+ };
15
+ exports.ansiColors = {
16
+ red: '\x1b[31m',
17
+ green: '\x1b[32m',
18
+ yellow: '\x1b[33m',
19
+ blue: '\x1b[34m',
20
+ magenta: '\x1b[35m',
21
+ cyan: '\x1b[36m',
22
+ white: '\x1b[37m',
23
+ gray: '\x1b[90m',
24
+ grey: '\x1b[90m',
25
+ brightRed: '\x1b[91m',
26
+ brightGreen: '\x1b[92m',
27
+ brightYellow: '\x1b[93m',
28
+ brightBlue: '\x1b[94m',
29
+ brightMagenta: '\x1b[95m',
30
+ brightCyan: '\x1b[96m',
31
+ brightWhite: '\x1b[97m',
32
+ };
33
+ exports.StringStyle = zod_1.default.object({
34
+ bold: zod_1.default.boolean().optional(),
35
+ underline: zod_1.default.boolean().optional(),
36
+ color: (0, utils_1.zodEnumFromObjKeys)(exports.ansiColors).optional(),
37
+ reset: zod_1.default.boolean().default(true).optional(),
38
+ });
39
+ function format(string, style = {}) {
40
+ const { color, bold, underline, reset = true } = style;
41
+ const colorCode = color ? exports.ansiColors[color] : '';
42
+ const boldCode = bold ? exports.ansiStyles.bold : '';
43
+ const underlineCode = underline ? exports.ansiStyles.underline : '';
44
+ const resetCode = reset ? exports.ansiStyles.reset : '';
45
+ return `${colorCode}${boldCode}${underlineCode}${string}${resetCode}`;
46
+ }
47
+ exports.format = format;
48
+ function stripStyle(string) {
49
+ return string.replace(/\x1b\[\d+m/gi, '');
50
+ }
51
+ exports.stripStyle = stripStyle;
52
+ //# sourceMappingURL=style.js.map
package/style.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.js","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAmB;AACnB,mCAA4C;AAE/B,QAAA,UAAU,GAAG;IACxB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,SAAS,EAAE,SAAS;IACpB,KAAK,EAAE,UAAU;CAClB,CAAA;AAEY,QAAA,UAAU,GAAG;IACxB,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,UAAU;IAClB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,UAAU;IACnB,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;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D,wBAOC;AAED,SAAgB,UAAU,CAAC,MAAc;IACvC,OAAO,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;AAC3C,CAAC;AAFD,gCAEC"}
package/utils.d.ts CHANGED
@@ -1,14 +1,34 @@
1
- import chalk from "chalk";
2
- export declare function color(color: ArrayOr<keyof typeof chalk>, ...text: any[]): string;
3
- export declare function colorCount(...colors: any[]): number;
4
- export interface WrapOptions {
5
- indent?: number;
6
- firstLineIndent?: number;
7
- printWidth?: number;
8
- colorCount?: number;
9
- }
10
- export declare function wrap(text: string, options?: WrapOptions): string[];
11
- export declare const COLOR_CODE_LEN: number;
12
- export declare type ArrayOr<T> = T | T[];
13
- export declare function asArray<T>(obj: T | T[]): T[];
1
+ import z from 'zod';
2
+ /** @internal */
3
+ export declare function setOrPush<T>(newValue: unknown, currentValue: T[] | T | undefined, isArray: boolean): T;
4
+ type Parseable = string | number | boolean | null | undefined | Record<string, unknown>;
5
+ /** A type that makes all properties of an object required, recursively. */
6
+ export type DeepRequired<T> = {
7
+ [P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : NonNullable<T[P]>;
8
+ };
9
+ /**
10
+ * Concatenates strings, arrays of strings, and objects with truthy values.
11
+ *
12
+ * It works recursively, so adding an array of strings to an array of strings will work.
13
+ *
14
+ * Falsy values are ignored, so pasing `undefined` or `null` will not add anything to the result,
15
+ * and using a boolean will only add it if it is `true`. Using 0 will also not add anything.
16
+ */
17
+ export declare function strConcat(...strs: (Parseable | Parseable[])[]): string;
18
+ /**
19
+ * Indents a string or an array of strings. Concatenates them all using `strConcat`.
20
+ */
21
+ export declare function indent(str: Parseable | Parseable[], indent?: number): string;
22
+ /** @internal */
23
+ export declare function zodEnumFromObjKeys<K extends string>(obj: Record<K, any>): z.ZodEnum<[K, ...K[]]>;
24
+ /** @internal */
25
+ export declare function deepMerge<T1, T2>(obj1: T1, obj2: T2): NonNullable<T1> & NonNullable<T2>;
26
+ /**
27
+ * Splits a name into words, using camelCase, PascalCase, snake_case, and kebab-case or
28
+ * regular spaced strings.
29
+ */
30
+ export declare function splitWords(str: string): string[];
31
+ export declare function toCamelCase(str: string): string;
32
+ export declare function toPascalCase(str: string): string;
33
+ export {};
14
34
  //# sourceMappingURL=utils.d.ts.map
package/utils.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,OAAO,KAAK,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,CAMhF;AAED,wBAAgB,UAAU,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAEnD;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE,CAqClE;AAED,eAAO,MAAM,cAAc,QAAkC,CAAA;AAqB7D,oBAAY,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;AAChC,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAE5C"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,gBAAgB;AAChB,wBAAgB,SAAS,CAAC,CAAC,EACzB,QAAQ,EAAE,OAAO,EACjB,YAAY,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,E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HANGED
@@ -1,129 +1,116 @@
1
1
  "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
- if (ar || !(i in from)) {
32
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
- ar[i] = from[i];
34
- }
35
- }
36
- return to.concat(ar || Array.prototype.slice.call(from));
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.asArray = exports.COLOR_CODE_LEN = exports.wrap = exports.colorCount = exports.color = void 0;
43
- var chalk_1 = __importDefault(require("chalk"));
44
- // import chunk from "lodash/chunk"
45
- var repeat_1 = __importDefault(require("lodash/repeat"));
46
- var merge_1 = __importDefault(require("lodash/merge"));
47
- function color(color) {
48
- var e_1, _a;
49
- var text = [];
50
- for (var _i = 1; _i < arguments.length; _i++) {
51
- text[_i - 1] = arguments[_i];
6
+ exports.toPascalCase = exports.toCamelCase = exports.splitWords = exports.deepMerge = exports.zodEnumFromObjKeys = exports.indent = exports.strConcat = exports.setOrPush = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ /** @internal */
9
+ function setOrPush(newValue, currentValue, isArray) {
10
+ if (isArray) {
11
+ return [...(currentValue ?? []), newValue];
52
12
  }
53
- var output = undefined;
54
- try {
55
- for (var _b = __values(asArray(color)), _c = _b.next(); !_c.done; _c = _b.next()) {
56
- var c = _c.value;
57
- output = chalk_1.default[c].apply(chalk_1.default, __spreadArray([], __read((output ? [output] : text)), false));
13
+ return newValue;
14
+ }
15
+ exports.setOrPush = setOrPush;
16
+ /**
17
+ * Concatenates strings, arrays of strings, and objects with truthy values.
18
+ *
19
+ * It works recursively, so adding an array of strings to an array of strings will work.
20
+ *
21
+ * Falsy values are ignored, so pasing `undefined` or `null` will not add anything to the result,
22
+ * and using a boolean will only add it if it is `true`. Using 0 will also not add anything.
23
+ */
24
+ function strConcat(...strs) {
25
+ const res = [];
26
+ for (const str of strs) {
27
+ if (typeof str === 'string') {
28
+ res.push(str);
29
+ continue;
58
30
  }
59
- }
60
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
61
- finally {
62
- try {
63
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
31
+ if (Array.isArray(str)) {
32
+ res.push(strConcat(...str));
33
+ continue;
34
+ }
35
+ if (str == null) {
36
+ continue;
37
+ }
38
+ if (typeof str === 'object') {
39
+ for (const [key, value] of Object.entries(str)) {
40
+ if (Boolean(value)) {
41
+ res.push(key);
42
+ }
43
+ }
44
+ continue;
45
+ }
46
+ if (Boolean(str)) {
47
+ res.push(str.toString());
48
+ continue;
64
49
  }
65
- finally { if (e_1) throw e_1.error; }
66
50
  }
67
- return chalk_1.default.reset(output);
51
+ return res.join('\n');
68
52
  }
69
- exports.color = color;
70
- function colorCount() {
71
- var colors = [];
72
- for (var _i = 0; _i < arguments.length; _i++) {
73
- colors[_i] = arguments[_i];
74
- }
75
- return asArray(colors).reduce(function (all, colorSet) { return all + asArray(colorSet).length; }, 0);
53
+ exports.strConcat = strConcat;
54
+ /**
55
+ * Indents a string or an array of strings. Concatenates them all using `strConcat`.
56
+ */
57
+ function indent(str, indent = 2) {
58
+ return strConcat(str)
59
+ .split('\n')
60
+ .map((s) => ' '.repeat(indent) + s)
61
+ .join('\n');
76
62
  }
77
- exports.colorCount = colorCount;
78
- function wrap(text, options) {
79
- var _a, _b;
80
- var _opts = (0, merge_1.default)({
81
- printWidth: 100,
82
- indent: 0,
83
- colorCount: 0,
84
- }, options);
85
- var indentSize = (_a = _opts.indent) !== null && _a !== void 0 ? _a : 0;
86
- var firstIndentSize = (_b = _opts.firstLineIndent) !== null && _b !== void 0 ? _b : indentSize;
87
- var maxLineLength = _opts.printWidth - firstIndentSize + exports.COLOR_CODE_LEN * _opts.colorCount;
88
- function indent(i, l) {
89
- return (0, repeat_1.default)(" ", i === 0 ? firstIndentSize : indentSize) + l;
90
- }
91
- if (!_opts.printWidth || maxLineLength <= 0) {
92
- return text.split("\n").map(function (l, i) { return indent(i, l); });
93
- }
94
- var lines = chunk(text, maxLineLength).map(function (l, i) { return indent(i, l); });
95
- lines = __spreadArray([
96
- lines[0]
97
- ], __read(chunk(lines
98
- .slice(1)
99
- .map(function (l) { return l.trim(); })
100
- .join(" ")
101
- .trim(), maxLineLength - indentSize - exports.COLOR_CODE_LEN).map(function (l, i) { return indent(i + 1, l); })), false).filter(function (l) { return l.trim().length; });
102
- return lines;
63
+ exports.indent = indent;
64
+ /** @internal */
65
+ function zodEnumFromObjKeys(obj) {
66
+ const [firstKey, ...otherKeys] = Object.keys(obj);
67
+ return zod_1.default.enum([firstKey, ...otherKeys]);
103
68
  }
104
- exports.wrap = wrap;
105
- exports.COLOR_CODE_LEN = color("yellow", " ").length - 1;
106
- function chunk(text, len) {
107
- var arr = text.split(" ");
108
- var result = [];
109
- var subStr = arr[0];
110
- for (var i = 1; i < arr.length; i++) {
111
- var word = arr[i];
112
- if (subStr.length + word.length + 1 <= len) {
113
- subStr = subStr + " " + word;
69
+ exports.zodEnumFromObjKeys = zodEnumFromObjKeys;
70
+ /** @internal */
71
+ function deepMerge(obj1, obj2) {
72
+ const res = { ...obj1 };
73
+ if (obj1 == null)
74
+ return obj2;
75
+ if (obj2 == null)
76
+ return obj1;
77
+ for (const [key, value] of Object.entries(obj2)) {
78
+ if (typeof value === 'object' && typeof res[key] === 'object') {
79
+ res[key] = deepMerge(res[key], value);
114
80
  }
115
81
  else {
116
- result.push(subStr);
117
- subStr = word;
82
+ res[key] = value;
118
83
  }
119
84
  }
120
- if (subStr.length) {
121
- result.push(subStr);
122
- }
123
- return result;
85
+ return res;
86
+ }
87
+ exports.deepMerge = deepMerge;
88
+ /**
89
+ * Splits a name into words, using camelCase, PascalCase, snake_case, and kebab-case or
90
+ * regular spaced strings.
91
+ */
92
+ function splitWords(str) {
93
+ return str
94
+ .replace(/([a-z])([A-Z])/g, '$1 $2')
95
+ .replace(/([a-zA-Z])([0-9])/g, '$1 $2')
96
+ .replace(/([0-9])([a-zA-Z])/g, '$1 $2')
97
+ .replace(/([a-z])([_-])/g, '$1 $2')
98
+ .replace(/([_-])([a-zA-Z])/g, '$1 $2')
99
+ .split(/[_-]/)
100
+ .map((s) => s.trim())
101
+ .filter(Boolean);
102
+ }
103
+ exports.splitWords = splitWords;
104
+ function toCamelCase(str) {
105
+ return splitWords(str)
106
+ .map((s, i) => (i === 0 ? s : s[0].toUpperCase() + s.slice(1)))
107
+ .join('');
124
108
  }
125
- function asArray(obj) {
126
- return Array.isArray(obj) ? obj !== null && obj !== void 0 ? obj : [] : obj ? [obj] : [];
109
+ exports.toCamelCase = toCamelCase;
110
+ function toPascalCase(str) {
111
+ return splitWords(str)
112
+ .map((s) => s[0].toUpperCase() + s.slice(1))
113
+ .join('');
127
114
  }
128
- exports.asArray = asArray;
115
+ exports.toPascalCase = toPascalCase;
129
116
  //# sourceMappingURL=utils.js.map
package/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceR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C;SACtC,OAAO,CAAC,gBAAgB,EAAE,OAAO,CAAC;SAClC,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC;SACrC,KAAK,CAAC,MAAM,CAAC;SACb,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,OAAO,CAAC,CAAA;AACpB,CAAC;AAVD,gCAUC;AAED,SAAgB,WAAW,CAAC,GAAW;IACrC,OAAO,UAAU,CAAC,GAAG,CAAC;SACnB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAC9D,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAJD,kCAIC;AAED,SAAgB,YAAY,CAAC,GAAW;IACtC,OAAO,UAAU,CAAC,GAAG,CAAC;SACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAJD,oCAIC"}
package/assertions.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { CommandDef, ExampleDef, HelpDef, MainDef, OptionDef } from "./types";
2
- export declare const colorList: string[];
3
- export declare function assertHelp(help: HelpDef): void;
4
- export declare function assertCommand(command: CommandDef<any>, allCommands: CommandDef<any>[]): void;
5
- export declare function assertOption(option: OptionDef<any, any>, allOptions: OptionDef<any, any>[]): void;
6
- export declare function assertExample(example: ExampleDef): void;
7
- export declare function assertMain(run: MainDef<any>): void;
8
- //# sourceMappingURL=assertions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAS,SAAS,EAAE,MAAM,SAAS,CAAA;AAIpF,eAAO,MAAM,SAAS,UAIrB,CAAA;AAqED,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,QAkBvC;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAI5F;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,CAMjG;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,QAIhD;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,QAE3C"}
package/assertions.js DELETED
@@ -1,145 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __read = (this && this.__read) || function (o, n) {
18
- var m = typeof Symbol === "function" && o[Symbol.iterator];
19
- if (!m) return o;
20
- var i = m.call(o), r, ar = [], e;
21
- try {
22
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
23
- }
24
- catch (error) { e = { error: error }; }
25
- finally {
26
- try {
27
- if (r && !r.done && (m = i["return"])) m.call(i);
28
- }
29
- finally { if (e) throw e.error; }
30
- }
31
- return ar;
32
- };
33
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
35
- if (ar || !(i in from)) {
36
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
37
- ar[i] = from[i];
38
- }
39
- }
40
- return to.concat(ar || Array.prototype.slice.call(from));
41
- };
42
- Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.assertMain = exports.assertExample = exports.assertOption = exports.assertCommand = exports.assertHelp = exports.colorList = void 0;
44
- var utils_1 = require("./utils");
45
- // prettier-ignore
46
- exports.colorList = [
47
- "reset", "bold", "dim", "italic", "underline", "inverse", "hidden", "strikethrough", "black", "red", "green",
48
- "yellow", "blue", "magenta", "cyan", "white", "gray", "bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue",
49
- "bgMagenta", "bgCyan", "bgWhite",
50
- ];
51
- var AssertionError = /** @class */ (function (_super) {
52
- __extends(AssertionError, _super);
53
- function AssertionError() {
54
- return _super !== null && _super.apply(this, arguments) || this;
55
- }
56
- return AssertionError;
57
- }(Error));
58
- function assert(condition, message) {
59
- if (!condition) {
60
- throw new AssertionError(message);
61
- }
62
- }
63
- function nullOr(condition, condition2) {
64
- return [null, undefined].includes(condition) || condition2;
65
- }
66
- function assertRequired(obj, prefix, name) {
67
- assert(![undefined, null].includes(obj), "".concat(prefix, ": ").concat(name, " must be provided"));
68
- }
69
- function assertType(obj, prefix, name, options) {
70
- if (options.required) {
71
- assertRequired(obj, prefix, name);
72
- }
73
- else {
74
- try {
75
- assertRequired(obj, prefix, name);
76
- }
77
- catch (e) {
78
- return;
79
- }
80
- }
81
- assert(typeof obj === options.type, "".concat(prefix, ": ").concat(name, " must be ").concat(options.type));
82
- }
83
- function assertNumber(obj, prefix, name, options) {
84
- assertType(obj, prefix, name, { required: options.required, type: "number" });
85
- if (!options.required && [null, undefined].includes(obj)) {
86
- return;
87
- }
88
- if (typeof options.max === "number") {
89
- assert(obj <= options.max, "".concat(prefix, ": ").concat(name, " must be \u2264 ").concat(options.max));
90
- }
91
- if (typeof options.min === "number") {
92
- assert(obj >= options.min, "".concat(prefix, ": ").concat(name, " must be \u2265 ").concat(options.min));
93
- }
94
- }
95
- function assertColor(color, prefix, name) {
96
- assert(nullOr(color, (0, utils_1.asArray)(color).every(function (c) { return exports.colorList.includes(c); })), "".concat(prefix, ": ").concat(name, " must be string or array of strings. Accepted values: ") + exports.colorList.join(", "));
97
- }
98
- function assertAliases(def, allDefs, prefix) {
99
- assert(!def.aliases || def.aliases.every(function (a) { return !allDefs.find(function (opt) { var _a; return __spreadArray([opt.name], __read(((_a = opt.aliases) !== null && _a !== void 0 ? _a : [])), false).includes(a); }); }), "".concat(prefix, ": Aliases must be unique"));
100
- }
101
- function assertHelp(help) {
102
- assertType(help.binName, "Help", "Binary Name", { type: "string" });
103
- assertColor(help.normalColors, "Help", "Normal colors");
104
- assertColor(help.bodyColors, "Help", "Body colors");
105
- assertColor(help.titleColors, "Help", "Title colors");
106
- assertColor(help.subtitleColors, "Help", "Subtitle colors");
107
- assertColor(help.highlightColors, "Help", "Highlight colors");
108
- assertType(help.footer, "Help", "Footer", { type: "string" });
109
- assertType(help.header, "Help", "Header", { type: "string" });
110
- assertType(help.optionNameSeparator, "Help", "Option Name Separator", { type: "string" });
111
- assertType(help.commandNameSeparator, "Help", "Command Name Separator", { type: "string" });
112
- assertNumber(help.printWidth, "Help", "Print Width", { min: 0 });
113
- assertType(help.exampleInputPrefix, "Help", "Example Input Prefix", { type: "string" });
114
- assertType(help.exampleOutputPrefix, "Help", "Example Output Prefix", { type: "string" });
115
- assertType(help.usageExample, "Help", "Usage Example", { type: "string" });
116
- assertType(help.useGlobalColumns, "Help", "Use Global Columns", { type: "boolean" });
117
- assertType(help.includeDefaults, "Help", "Include Defaults", { type: "boolean" });
118
- assertType(help.useColors, "Help", "Use Colors", { type: "boolean" });
119
- }
120
- exports.assertHelp = assertHelp;
121
- function assertCommand(command, allCommands) {
122
- assertType(command.name, "Command", "Name", { required: true, type: "string" });
123
- assertAliases(command, allCommands, "Command");
124
- assertType(command.run, "Command", "Run", { required: true, type: "function" });
125
- }
126
- exports.assertCommand = assertCommand;
127
- function assertOption(option, allOptions) {
128
- assert(option.name, "Option: Name must be provided");
129
- assert(typeof option.name === "string", "Option: Name must be string");
130
- assertAliases(option, allOptions, "Option");
131
- assertType(option.boolean, "Option", "Default Value", { type: "boolean" });
132
- assertType(option.parse, "Option", "Parse", { type: "function" });
133
- }
134
- exports.assertOption = assertOption;
135
- function assertExample(example) {
136
- assertType(example.input, "Example", "Input", { required: true, type: "string" });
137
- assertType(example.output, "Example", "Output", { type: "string" });
138
- assertType(example.description, "Example", "Description", { type: "string" });
139
- }
140
- exports.assertExample = assertExample;
141
- function assertMain(run) {
142
- assertType(run, "Main", "Main", { required: true, type: "function" });
143
- }
144
- exports.assertMain = assertMain;
145
- //# sourceMappingURL=assertions.js.map