@clerc/utils 0.3.4

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 ADDED
@@ -0,0 +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.
package/dist/index.cjs ADDED
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const mustArray = (a) => Array.isArray(a) ? a : [a];
6
+ const camelCase = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
7
+ const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
8
+ const gracefulFlagName = (n) => n.length <= 1 ? `-${n}` : `--${n}`;
9
+ const gracefulVersion = (v) => v.length === 0 ? v.startsWith("v") ? v : `v${v}` : "";
10
+
11
+ exports.camelCase = camelCase;
12
+ exports.gracefulFlagName = gracefulFlagName;
13
+ exports.gracefulVersion = gracefulVersion;
14
+ exports.kebabCase = kebabCase;
15
+ exports.mustArray = mustArray;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copied from type-fest
3
+ */
4
+ declare type Primitive = null | undefined | string | number | boolean | symbol | bigint;
5
+ /**
6
+ * Copied from type-fest
7
+ */
8
+ declare type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
9
+ declare type Dict<T> = Record<string, T>;
10
+ declare type MustArray<T> = T extends any[] ? T : [T];
11
+ declare type MaybeArray<T> = T | T[];
12
+ declare type GetLength<T extends any[]> = T extends {
13
+ length: infer L extends number;
14
+ } ? L : never;
15
+ declare type GetTail<T extends any[]> = T extends [infer _Head, ...infer Tail] ? Tail : never;
16
+ declare type EnhanceSingle<T, E extends Dict<any>> = T & E;
17
+ declare type Enhance<T, E extends Dict<any> | Dict<any>[]> = GetLength<MustArray<E>> extends 0 ? T : Enhance<EnhanceSingle<T, MustArray<E>[0]>, GetTail<MustArray<E>>>;
18
+ declare const mustArray: <T>(a: MaybeArray<T>) => T[];
19
+ declare type CamelCase<T extends string> = T extends `${infer A}-${infer B}${infer C}` ? `${A}${Capitalize<B>}${CamelCase<C>}` : T;
20
+ declare const camelCase: <T extends string>(s: T) => CamelCase<T>;
21
+ declare type KebabCase<T extends string, A extends string = ""> = T extends `${infer F}${infer R}` ? KebabCase<R, `${A}${F extends Lowercase<F> ? "" : "-"}${Lowercase<F>}`> : A;
22
+ declare const kebabCase: <T extends string>(s: T) => KebabCase<T, "">;
23
+ declare const gracefulFlagName: (n: string) => string;
24
+ declare const gracefulVersion: (v: string) => string;
25
+
26
+ export { CamelCase, Dict, Enhance, GetLength, GetTail, KebabCase, LiteralUnion, MaybeArray, MustArray, Primitive, camelCase, gracefulFlagName, gracefulVersion, kebabCase, mustArray };
package/dist/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ const mustArray = (a) => Array.isArray(a) ? a : [a];
2
+ const camelCase = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
3
+ const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
4
+ const gracefulFlagName = (n) => n.length <= 1 ? `-${n}` : `--${n}`;
5
+ const gracefulVersion = (v) => v.length === 0 ? v.startsWith("v") ? v : `v${v}` : "";
6
+
7
+ export { camelCase, gracefulFlagName, gracefulVersion, kebabCase, mustArray };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@clerc/utils",
3
+ "version": "0.3.4",
4
+ "author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
5
+ "description": "Clerc utils",
6
+ "keywords": [
7
+ "cli",
8
+ "clerc",
9
+ "clerc-utils",
10
+ "utils",
11
+ "arguments",
12
+ "argv",
13
+ "args",
14
+ "terminal"
15
+ ],
16
+ "homepage": "https://github.com/so1ve/clerc/tree/main/packages/utils#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/so1ve/clerc.git",
20
+ "directory": "/"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/so1ve/clerc/issues"
24
+ },
25
+ "license": "MIT",
26
+ "sideEffects": false,
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "require": "./dist/index.cjs",
31
+ "import": "./dist/index.mjs"
32
+ }
33
+ },
34
+ "main": "dist/index.cjs",
35
+ "module": "dist/index.mjs",
36
+ "types": "dist/index.d.ts",
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "peerDependencies": {
44
+ "clerc": "*"
45
+ },
46
+ "scripts": {
47
+ "build": "puild",
48
+ "watch": "puild --watch"
49
+ }
50
+ }