@clerc/utils
Advanced tools
Comparing version 0.41.0 to 0.42.0
import * as _clerc_core from '@clerc/core'; | ||
import { I18N, Commands, CommandType, TranslateFn, Command, RootType, Root } from '@clerc/core'; | ||
import { I18N, Commands, CommandType, TranslateFunction, Command, RootType, Root } from '@clerc/core'; | ||
@@ -18,6 +18,6 @@ type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false; | ||
declare const gracefulVersion: (v: string) => string; | ||
declare function arrayEquals<T>(arr1: T[], arr2: T[]): boolean; | ||
declare function arrayStartsWith<T>(arr: T[], start: T[]): boolean; | ||
declare function semanticArray(arr: string[], { add, t }: I18N): string; | ||
declare function resolveCommandStrict(commands: Commands, name: CommandType | string[], t: TranslateFn): [Command<string | RootType> | undefined, string[] | RootType | undefined]; | ||
declare function arrayEquals<T>(array1: T[], array2: T[]): boolean; | ||
declare function arrayStartsWith<T>(array: T[], start: T[]): boolean; | ||
declare function semanticArray(array: string[], { add, t }: I18N): string; | ||
declare function resolveCommandStrict(commands: Commands, name: CommandType | string[], t: TranslateFunction): [Command<string | RootType> | undefined, string[] | RootType | undefined]; | ||
declare function resolveSubcommandsByParent(commands: Commands, parent: string | string[], depth?: number): Command<string, _clerc_core.CommandOptions<string[], MaybeArray<string | typeof Root>, _clerc_core.Flags>>[]; | ||
@@ -24,0 +24,0 @@ declare const resolveRootCommands: (commands: Commands) => Command<string, _clerc_core.CommandOptions<string[], MaybeArray<string | typeof Root>, _clerc_core.Flags>>[]; |
@@ -17,20 +17,24 @@ import { Root, resolveFlattenCommands } from '@clerc/core'; | ||
const gracefulVersion = (v) => v.length === 0 ? "" : v.startsWith("v") ? v : `v${v}`; | ||
function arrayEquals(arr1, arr2) { | ||
if (arr2.length !== arr1.length) { | ||
function arrayEquals(array1, array2) { | ||
if (array2.length !== array1.length) { | ||
return false; | ||
} | ||
return arr1.every((item, i) => item === arr2[i]); | ||
return array1.every((item, index) => item === array2[index]); | ||
} | ||
function arrayStartsWith(arr, start) { | ||
if (start.length > arr.length) { | ||
function arrayStartsWith(array, start) { | ||
if (start.length > array.length) { | ||
return false; | ||
} | ||
return arrayEquals(arr.slice(0, start.length), start); | ||
return arrayEquals(array.slice(0, start.length), start); | ||
} | ||
function semanticArray(arr, { add, t }) { | ||
function semanticArray(array, { add, t }) { | ||
add(locales); | ||
if (arr.length <= 1) { | ||
return arr[0]; | ||
if (array.length <= 1) { | ||
return array[0]; | ||
} | ||
return t("utils.and", arr.slice(0, -1).join(", "), arr[arr.length - 1]); | ||
return t( | ||
"utils.and", | ||
array.slice(0, -1).join(", "), | ||
array[array.length - 1] | ||
); | ||
} | ||
@@ -41,3 +45,3 @@ function resolveCommandStrict(commands, name, t) { | ||
} | ||
const nameArr = toArray(name); | ||
const nameArray = toArray(name); | ||
const commandsMap = resolveFlattenCommands(commands, t); | ||
@@ -50,3 +54,3 @@ let current; | ||
} | ||
if (arrayEquals(nameArr, k)) { | ||
if (arrayEquals(nameArray, k)) { | ||
current = v; | ||
@@ -59,6 +63,6 @@ currentName = k; | ||
function resolveSubcommandsByParent(commands, parent, depth = Infinity) { | ||
const parentArr = parent === "" ? [] : Array.isArray(parent) ? parent : parent.split(" "); | ||
const parentArray = parent === "" ? [] : Array.isArray(parent) ? parent : parent.split(" "); | ||
return Object.values(commands).filter((c) => { | ||
const commandNameArr = c.name.split(" "); | ||
return arrayStartsWith(commandNameArr, parentArr) && commandNameArr.length - parentArr.length <= depth; | ||
const commandNameArray = c.name.split(" "); | ||
return arrayStartsWith(commandNameArray, parentArray) && commandNameArray.length - parentArray.length <= depth; | ||
}); | ||
@@ -65,0 +69,0 @@ } |
{ | ||
"name": "@clerc/utils", | ||
"version": "0.41.0", | ||
"version": "0.42.0", | ||
"author": "Ray <i@mk1.io> (https://github.com/so1ve)", | ||
@@ -18,10 +18,10 @@ "type": "module", | ||
], | ||
"homepage": "https://github.com/so1ve/clerc/tree/main/packages/utils#readme", | ||
"homepage": "https://github.com/clercjs/clerc/tree/main/packages/utils#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/so1ve/clerc.git", | ||
"url": "git+https://github.com/clercjs/clerc.git", | ||
"directory": "/" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/so1ve/clerc/issues" | ||
"url": "https://github.com/clercjs/clerc/issues" | ||
}, | ||
@@ -46,3 +46,3 @@ "license": "MIT", | ||
"devDependencies": { | ||
"type-fest": "^3.12.0" | ||
"type-fest": "^4.0.0" | ||
}, | ||
@@ -49,0 +49,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6845
88