@clerc/utils 0.34.0 → 0.35.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/dist/index.d.ts CHANGED
@@ -1,23 +1,26 @@
1
1
  import * as _clerc_core from '@clerc/core';
2
- import { Command, I18N } from '@clerc/core';
2
+ import { Command, I18N, Commands, CommandType, TranslateFn, RootType, Root } from '@clerc/core';
3
3
 
4
- type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
5
- type Dict<T> = Record<string, T>;
6
- type ToArray<T> = T extends any[] ? T : [T];
7
- type MaybeArray<T> = T | T[];
8
- declare const toArray: <T>(a: MaybeArray<T>) => T[];
9
- type AlphabetLowercase = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
10
- type Numeric = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
11
- type AlphaNumeric = AlphabetLowercase | Uppercase<AlphabetLowercase> | Numeric;
12
- type CamelCase<Word extends string> = (Word extends `${infer FirstCharacter}${infer Rest}` ? (FirstCharacter extends AlphaNumeric ? `${FirstCharacter}${CamelCase<Rest>}` : Capitalize<CamelCase<Rest>>) : Word);
13
- declare const camelCase: (word: string) => string;
14
- type KebabCase<T extends string, A extends string = ""> = T extends `${infer Prefix}${infer Suffix}` ? KebabCase<Suffix, `${A}${Prefix extends Lowercase<Prefix> ? "" : "-"}${Lowercase<Prefix>}`> : A;
15
- declare const kebabCase: <T extends string>(s: T) => KebabCase<T, "">;
16
- declare const gracefulFlagName: (n: string) => string;
17
- declare const gracefulVersion: (v: string) => string;
18
- declare const arrayEquals: <T>(arr1: T[], arr2: T[]) => boolean;
19
- declare const arrayStartsWith: <T>(arr: T[], start: T[]) => boolean;
20
- declare const generateCommandsFromCommandArray: <C extends Command<string, _clerc_core.CommandOptions<string[], MaybeArray<string | typeof _clerc_core.Root>, _clerc_core.Flags>>>(commands: C[]) => Dict<C>;
4
+ type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
5
+ type Dict<T> = Record<string, T>;
6
+ type ToArray<T> = T extends any[] ? T : [T];
7
+ type MaybeArray<T> = T | T[];
8
+ declare const toArray: <T>(a: MaybeArray<T>) => T[];
9
+ type AlphabetLowercase = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
10
+ type Numeric = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
11
+ type AlphaNumeric = AlphabetLowercase | Uppercase<AlphabetLowercase> | Numeric;
12
+ type CamelCase<Word extends string> = (Word extends `${infer FirstCharacter}${infer Rest}` ? (FirstCharacter extends AlphaNumeric ? `${FirstCharacter}${CamelCase<Rest>}` : Capitalize<CamelCase<Rest>>) : Word);
13
+ declare const camelCase: (word: string) => string;
14
+ type KebabCase<T extends string, A extends string = ""> = T extends `${infer Prefix}${infer Suffix}` ? KebabCase<Suffix, `${A}${Prefix extends Lowercase<Prefix> ? "" : "-"}${Lowercase<Prefix>}`> : A;
15
+ declare const kebabCase: <T extends string>(s: T) => KebabCase<T, "">;
16
+ declare const gracefulFlagName: (n: string) => string;
17
+ declare const gracefulVersion: (v: string) => string;
18
+ declare const arrayEquals: <T>(arr1: T[], arr2: T[]) => boolean;
19
+ declare const arrayStartsWith: <T>(arr: T[], start: T[]) => boolean;
20
+ declare const generateCommandsFromCommandArray: <C extends Command>(commands: C[]) => Dict<C>;
21
21
  declare const semanticArray: (arr: string[], { add, t }: I18N) => string;
22
+ declare function resolveCommandStrict(commands: Commands, name: CommandType | string[], t: TranslateFn): [Command<string | RootType> | undefined, string[] | RootType | undefined];
23
+ declare function resolveSubcommandsByParent(commands: Commands, parent: string | string[], depth?: number): Command<string, _clerc_core.CommandOptions<string[], MaybeArray<string | typeof Root>, _clerc_core.Flags>>[];
24
+ declare const resolveRootCommands: (commands: Commands) => Command<string, _clerc_core.CommandOptions<string[], MaybeArray<string | typeof Root>, _clerc_core.Flags>>[];
22
25
 
23
- export { CamelCase, Dict, Equals, KebabCase, MaybeArray, ToArray, arrayEquals, arrayStartsWith, camelCase, generateCommandsFromCommandArray, gracefulFlagName, gracefulVersion, kebabCase, semanticArray, toArray };
26
+ export { CamelCase, Dict, Equals, KebabCase, MaybeArray, ToArray, arrayEquals, arrayStartsWith, camelCase, generateCommandsFromCommandArray, gracefulFlagName, gracefulVersion, kebabCase, resolveCommandStrict, resolveRootCommands, resolveSubcommandsByParent, semanticArray, toArray };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- const o={en:{"utils.and":"%s and %s"},"zh-CN":{"utils.and":"%s \u548C %s"}},l=e=>Array.isArray(e)?e:[e],c=e=>e.replace(/[\W_]([a-z\d])?/gi,(n,t)=>t?t.toUpperCase():""),s=e=>e.replace(/([A-Z])/g,(n,t)=>`-${t.toLowerCase()}`),g=e=>e.length<=1?`-${e}`:`--${s(e)}`,i=e=>e.length===0?"":e.startsWith("v")?e:`v${e}`,r=(e,n)=>n.length!==e.length?!1:e.every((t,a)=>t===n[a]),u=(e,n)=>n.length>e.length?!1:r(e.slice(0,n.length),n),h=e=>{const n={};for(const t of e)n[t.name]=t;return n},m=(e,{add:n,t})=>(n(o),e.length<=1?e[0]:t("utils.and",e.slice(0,-1).join(", "),e[e.length-1]));export{r as arrayEquals,u as arrayStartsWith,c as camelCase,h as generateCommandsFromCommandArray,g as gracefulFlagName,i as gracefulVersion,s as kebabCase,m as semanticArray,l as toArray};
1
+ import{Root as s,resolveFlattenCommands as d}from"@clerc/core";const y={en:{"utils.and":"%s and %s"},"zh-CN":{"utils.and":"%s \u548C %s"}},m=e=>Array.isArray(e)?e:[e],A=e=>e.replace(/[\W_]([a-z\d])?/gi,(t,n)=>n?n.toUpperCase():""),u=e=>e.replace(/([A-Z])/g,(t,n)=>`-${n.toLowerCase()}`),C=e=>e.length<=1?`-${e}`:`--${u(e)}`,p=e=>e.length===0?"":e.startsWith("v")?e:`v${e}`,i=(e,t)=>t.length!==e.length?!1:e.every((n,r)=>n===t[r]),f=(e,t)=>t.length>e.length?!1:i(e.slice(0,t.length),t),v=e=>{const t={};for(const n of e)t[n.name]=n;return t},b=(e,{add:t,t:n})=>(t(y),e.length<=1?e[0]:n("utils.and",e.slice(0,-1).join(", "),e[e.length-1]));function N(e,t,n){if(t===s)return[e[s],s];const r=m(t),a=d(e,n);let o,l;return a.forEach((h,c)=>{c===s||l===s||i(r,c)&&(o=h,l=c)}),[o,l]}function g(e,t,n=1/0){const r=t===""?[]:Array.isArray(t)?t:t.split(" ");return Object.values(e).filter(a=>{const o=a.name.split(" ");return f(o,r)&&o.length-r.length<=n})}const $=e=>g(e,"",1);export{i as arrayEquals,f as arrayStartsWith,A as camelCase,v as generateCommandsFromCommandArray,C as gracefulFlagName,p as gracefulVersion,u as kebabCase,N as resolveCommandStrict,$ as resolveRootCommands,g as resolveSubcommandsByParent,b as semanticArray,m as toArray};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/utils",
3
- "version": "0.34.0",
3
+ "version": "0.35.0",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "description": "Clerc utils",
6
6
  "keywords": [