@ruan-cat/utils 1.0.1

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/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@ruan-cat/utils",
3
+ "version": "1.0.1",
4
+ "description": "工具集合,预期是一个纯ts库,提供ts类型和ts的函数",
5
+ "type": "module",
6
+ "_main": "./src/index.ts",
7
+ "_types": "./src/index.ts",
8
+ "_module": "./src",
9
+ "main": "./src/index.ts",
10
+ "types": "./src/index.ts",
11
+ "exports": {
12
+ ".": {
13
+ "_import": "./src/index.ts",
14
+ "_default": "./src/index.ts",
15
+ "import": "./src/index.ts",
16
+ "types": "./src/index.ts"
17
+ },
18
+ "./*": "./src/*"
19
+ },
20
+ "keywords": [],
21
+ "author": "ruan-cat",
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "registry": "https://registry.npmjs.org/",
25
+ "tag": "beta"
26
+ },
27
+ "files": [
28
+ "src",
29
+ "tsconfig.json"
30
+ ],
31
+ "scripts": {
32
+ "test": "echo \"Error: no test specified\" && exit 1"
33
+ }
34
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `Prettify` 帮助程序是一种实用程序类型,它采用对象类型并使悬停叠加更具可读性。
3
+ * @see https://www.totaltypescript.com/concepts/the-prettify-helper
4
+ */
5
+ export type Prettify<T> = {
6
+ [K in keyof T]: T[K];
7
+ // 本行忽略报错 改类型工具依赖该写法
8
+ // eslint-disable-next-line ts/ban-types
9
+ } & {};
10
+
11
+ /**
12
+ * 转换成 NumberLike 类型
13
+ * @author f1-阮喵喵
14
+ * @description
15
+ * ### *设计理由*
16
+ * 期望让一个数值类型的联合类型 变成`NumberLike`形式的类型
17
+ */
18
+ export type ToNumberLike<T extends number> = T | `${T}`;
@@ -0,0 +1,23 @@
1
+ export type Conditions = Array<(...args: unknown[]) => boolean>;
2
+
3
+ /**
4
+ * 是否每一个条件函数都满足?
5
+ * @description
6
+ * ### 设计理由
7
+ * 旨在于封装这样的代码段
8
+ * ```js
9
+ * const conditions = [
10
+ * () => !isEqual(nAssetRecord, oAssetRecord),
11
+ * () => !isEqual(nAssetRecord, defPropsAssets),
12
+ * () => isEdit.value || isInfo.value,
13
+ * ];
14
+ * conditions.every((condition) => condition())
15
+ * ```
16
+ */
17
+ export function isConditionsEvery(conditions: Conditions) {
18
+ return conditions.every((condition) => condition());
19
+ }
20
+
21
+ export function isConditionsSome(conditions: Conditions) {
22
+ return conditions.some((condition) => condition());
23
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ // https://stackoverflow.com/a/42731800/18167453
2
+ // FIXME: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './conditions.js'?
3
+ export * from "./conditions";
4
+ export * from "./Prettify";