@clerc/utils 0.41.0 → 0.42.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Ray <https://github.com/so1ve>
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Ray <https://github.com/so1ve>
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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _clerc_core from '@clerc/core';
2
- import { I18N, Commands, CommandType, TranslateFn, Command, RootType, Root } from '@clerc/core';
2
+ import { I18N, Commands, CommandType, TranslateFunction, Command, RootType, Root } from '@clerc/core';
3
3
 
4
4
  type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
5
5
  type Dict<T> = Record<string, T>;
@@ -15,10 +15,10 @@ type KebabCase<T extends string, A extends string = ""> = T extends `${infer Pre
15
15
  declare const kebabCase: <T extends string>(s: T) => KebabCase<T, "">;
16
16
  declare const gracefulFlagName: (n: string) => string;
17
17
  declare const gracefulVersion: (v: string) => string;
18
- declare function arrayEquals<T>(arr1: T[], arr2: T[]): boolean;
19
- declare function arrayStartsWith<T>(arr: T[], start: T[]): boolean;
20
- declare function semanticArray(arr: string[], { add, t }: I18N): string;
21
- declare function resolveCommandStrict(commands: Commands, name: CommandType | string[], t: TranslateFn): [Command<string | RootType> | undefined, string[] | RootType | undefined];
18
+ declare function arrayEquals<T>(array1: T[], array2: T[]): boolean;
19
+ declare function arrayStartsWith<T>(array: T[], start: T[]): boolean;
20
+ declare function semanticArray(array: string[], { add, t }: I18N): string;
21
+ declare function resolveCommandStrict(commands: Commands, name: CommandType | string[], t: TranslateFunction): [Command<string | RootType> | undefined, string[] | RootType | undefined];
22
22
  declare function resolveSubcommandsByParent(commands: Commands, parent: string | string[], depth?: number): Command<string, _clerc_core.CommandOptions<string[], MaybeArray<string | typeof Root>, _clerc_core.Flags>>[];
23
23
  declare const resolveRootCommands: (commands: Commands) => Command<string, _clerc_core.CommandOptions<string[], MaybeArray<string | typeof Root>, _clerc_core.Flags>>[];
24
24
 
package/dist/index.js CHANGED
@@ -14,30 +14,34 @@ const camelCase = (word) => word.replace(/[\W_]([a-z\d])?/gi, (_, c) => c ? c.to
14
14
  const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
15
15
  const gracefulFlagName = (n) => n.length <= 1 ? `-${n}` : `--${kebabCase(n)}`;
16
16
  const gracefulVersion = (v) => v.length === 0 ? "" : v.startsWith("v") ? v : `v${v}`;
17
- function arrayEquals(arr1, arr2) {
18
- if (arr2.length !== arr1.length) {
17
+ function arrayEquals(array1, array2) {
18
+ if (array2.length !== array1.length) {
19
19
  return false;
20
20
  }
21
- return arr1.every((item, i) => item === arr2[i]);
21
+ return array1.every((item, index) => item === array2[index]);
22
22
  }
23
- function arrayStartsWith(arr, start) {
24
- if (start.length > arr.length) {
23
+ function arrayStartsWith(array, start) {
24
+ if (start.length > array.length) {
25
25
  return false;
26
26
  }
27
- return arrayEquals(arr.slice(0, start.length), start);
27
+ return arrayEquals(array.slice(0, start.length), start);
28
28
  }
29
- function semanticArray(arr, { add, t }) {
29
+ function semanticArray(array, { add, t }) {
30
30
  add(locales);
31
- if (arr.length <= 1) {
32
- return arr[0];
31
+ if (array.length <= 1) {
32
+ return array[0];
33
33
  }
34
- return t("utils.and", arr.slice(0, -1).join(", "), arr[arr.length - 1]);
34
+ return t(
35
+ "utils.and",
36
+ array.slice(0, -1).join(", "),
37
+ array[array.length - 1]
38
+ );
35
39
  }
36
40
  function resolveCommandStrict(commands, name, t) {
37
41
  if (name === Root) {
38
42
  return [commands[Root], Root];
39
43
  }
40
- const nameArr = toArray(name);
44
+ const nameArray = toArray(name);
41
45
  const commandsMap = resolveFlattenCommands(commands, t);
42
46
  let current;
43
47
  let currentName;
@@ -45,7 +49,7 @@ function resolveCommandStrict(commands, name, t) {
45
49
  if (k === Root || currentName === Root) {
46
50
  continue;
47
51
  }
48
- if (arrayEquals(nameArr, k)) {
52
+ if (arrayEquals(nameArray, k)) {
49
53
  current = v;
50
54
  currentName = k;
51
55
  }
@@ -53,10 +57,10 @@ function resolveCommandStrict(commands, name, t) {
53
57
  return [current, currentName];
54
58
  }
55
59
  function resolveSubcommandsByParent(commands, parent, depth = Infinity) {
56
- const parentArr = parent === "" ? [] : Array.isArray(parent) ? parent : parent.split(" ");
60
+ const parentArray = parent === "" ? [] : Array.isArray(parent) ? parent : parent.split(" ");
57
61
  return Object.values(commands).filter((c) => {
58
- const commandNameArr = c.name.split(" ");
59
- return arrayStartsWith(commandNameArr, parentArr) && commandNameArr.length - parentArr.length <= depth;
62
+ const commandNameArray = c.name.split(" ");
63
+ return arrayStartsWith(commandNameArray, parentArray) && commandNameArray.length - parentArray.length <= depth;
60
64
  });
61
65
  }
62
66
  const resolveRootCommands = (commands) => resolveSubcommandsByParent(commands, "", 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/utils",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "type": "module",
6
6
  "description": "Clerc utils",
@@ -15,14 +15,14 @@
15
15
  "utils",
16
16
  "utils"
17
17
  ],
18
- "homepage": "https://github.com/so1ve/clerc/tree/main/packages/utils#readme",
18
+ "homepage": "https://github.com/clercjs/clerc/tree/main/packages/utils#readme",
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "git+https://github.com/so1ve/clerc.git",
21
+ "url": "git+https://github.com/clercjs/clerc.git",
22
22
  "directory": "/"
23
23
  },
24
24
  "bugs": {
25
- "url": "https://github.com/so1ve/clerc/issues"
25
+ "url": "https://github.com/clercjs/clerc/issues"
26
26
  },
27
27
  "license": "MIT",
28
28
  "sideEffects": false,
@@ -42,7 +42,7 @@
42
42
  "access": "public"
43
43
  },
44
44
  "devDependencies": {
45
- "type-fest": "^3.12.0"
45
+ "type-fest": "^4.0.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@clerc/core": "*"