@clerc/utils 1.0.0-beta.1 → 1.0.0-beta.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 +4 -2
- package/dist/index.js +6 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,17 +8,19 @@ type UnknownArray = readonly unknown[];
|
|
|
8
8
|
type MapsSetsOrArrays = ReadonlyMap<unknown, unknown> | WeakMap<WeakKey, unknown> | ReadonlySet<unknown> | WeakSet<WeakKey> | UnknownArray;
|
|
9
9
|
type ConditionalDeepPrettify<T, E = never, I$1 = unknown> = T extends E ? T : T extends I$1 ? { [TypeKey in keyof T]: ConditionalDeepPrettify<T[TypeKey], E, I$1> } : T;
|
|
10
10
|
type DeepPrettify<T, E = never> = ConditionalDeepPrettify<T, E | NonRecursiveType | MapsSetsOrArrays, object>;
|
|
11
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
11
12
|
//#endregion
|
|
12
13
|
//#region src/types/index.d.ts
|
|
13
14
|
type ToArray<T> = T extends any[] ? T : [T];
|
|
14
15
|
type MaybeArray<T> = T | T[];
|
|
15
16
|
type PartialRequired<T, K$1 extends keyof T> = T & { [P in K$1]-?: T[P] };
|
|
16
17
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
18
|
+
type CamelCase<S extends string> = S extends `${infer Head} ${infer Tail}` ? `${Head}${Capitalize<CamelCase<Tail>>}` : S extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelCase<Tail>>}` : S;
|
|
17
19
|
//#endregion
|
|
18
20
|
//#region src/index.d.ts
|
|
19
21
|
declare const toArray: <T>(a: MaybeArray<T>) => T[];
|
|
20
22
|
/**
|
|
21
|
-
* Converts a dash-separated string to camelCase.
|
|
23
|
+
* Converts a dash- or space-separated string to camelCase.
|
|
22
24
|
* Not using regexp for better performance, because this function is used in parser.
|
|
23
25
|
*/
|
|
24
26
|
declare function camelCase(str: string): string;
|
|
@@ -29,4 +31,4 @@ declare const formatVersion: (v: string) => string;
|
|
|
29
31
|
declare const isTruthy: <T>(item: T) => item is Exclude<T, false | null | undefined>;
|
|
30
32
|
declare const objectIsEmpty: (obj: Record<string, any>) => boolean;
|
|
31
33
|
//#endregion
|
|
32
|
-
export { DeepPrettify, LiteralUnion, MaybeArray, PartialRequired, Prettify, ToArray, UnionToIntersection, camelCase, formatFlagName, formatVersion, isTruthy, joinWithAnd, kebabCase, objectIsEmpty, toArray };
|
|
34
|
+
export { CamelCase, DeepPrettify, IsAny, LiteralUnion, MaybeArray, PartialRequired, Prettify, ToArray, UnionToIntersection, camelCase, formatFlagName, formatVersion, isTruthy, joinWithAnd, kebabCase, objectIsEmpty, toArray };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
//#region src/index.ts
|
|
2
2
|
const toArray = (a) => Array.isArray(a) ? a : [a];
|
|
3
3
|
/**
|
|
4
|
-
* Converts a dash-separated string to camelCase.
|
|
4
|
+
* Converts a dash- or space-separated string to camelCase.
|
|
5
5
|
* Not using regexp for better performance, because this function is used in parser.
|
|
6
6
|
*/
|
|
7
7
|
function camelCase(str) {
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
let result = str.slice(0,
|
|
11
|
-
for (let i =
|
|
8
|
+
const firstIdx = Math.min(str.includes("-") ? str.indexOf("-") : Infinity, str.includes(" ") ? str.indexOf(" ") : Infinity);
|
|
9
|
+
if (firstIdx === Infinity) return str;
|
|
10
|
+
let result = str.slice(0, firstIdx);
|
|
11
|
+
for (let i = firstIdx; i < str.length; i++) if ((str[i] === "-" || str[i] === " ") && i + 1 < str.length) {
|
|
12
12
|
const nextChar = str.charCodeAt(i + 1);
|
|
13
13
|
if (nextChar >= 97 && nextChar <= 122) {
|
|
14
14
|
result += String.fromCharCode(nextChar - 32);
|
|
@@ -17,7 +17,7 @@ function camelCase(str) {
|
|
|
17
17
|
result += str[i + 1];
|
|
18
18
|
i++;
|
|
19
19
|
}
|
|
20
|
-
} else if (str[i] !== "-") result += str[i];
|
|
20
|
+
} else if (str[i] !== "-" && str[i] !== " ") result += str[i];
|
|
21
21
|
return result;
|
|
22
22
|
}
|
|
23
23
|
function joinWithAnd(values) {
|