@weapp-core/shared 3.0.0 → 3.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/README.md +41 -0
- package/dist/index.d.ts +25 -1
- package/dist/index.js +6 -3
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @weapp-core/shared
|
|
2
|
+
|
|
3
|
+
## 简介
|
|
4
|
+
|
|
5
|
+
`@weapp-core/shared` 汇总 weapp-vite 生态内的通用工具函数与依赖封装,供多个包复用。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- 常用字符串与路径处理工具
|
|
10
|
+
- 对象合并与判定工具
|
|
11
|
+
- 统一导出常用第三方工具(`defu`、`get`、`set`、`object-hash`)
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @weapp-core/shared
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 使用
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import {
|
|
23
|
+
addExtension,
|
|
24
|
+
defu,
|
|
25
|
+
escapeStringRegexp,
|
|
26
|
+
objectHash,
|
|
27
|
+
removeExtension,
|
|
28
|
+
} from '@weapp-core/shared'
|
|
29
|
+
|
|
30
|
+
const name = addExtension('pages/index/index')
|
|
31
|
+
const cleaned = removeExtension('app.json')
|
|
32
|
+
const hash = objectHash({ foo: 'bar' })
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 配置
|
|
36
|
+
|
|
37
|
+
暂无额外配置。
|
|
38
|
+
|
|
39
|
+
## 相关链接
|
|
40
|
+
|
|
41
|
+
- 仓库:https://github.com/weapp-vite/weapp-vite
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,30 @@ export { default as objectHash } from 'object-hash';
|
|
|
4
4
|
export { default as get } from 'get-value';
|
|
5
5
|
export { default as set } from 'set-value';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @description 转义字符串中的正则特殊字符
|
|
9
|
+
*/
|
|
7
10
|
declare function escapeStringRegexp(str: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* @description 移除文件名的最后一个扩展名
|
|
13
|
+
*/
|
|
8
14
|
declare function removeExtension(file: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* @description 移除文件名的所有扩展名(多重后缀)
|
|
17
|
+
*/
|
|
9
18
|
declare function removeExtensionDeep(file: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* @description 若缺少扩展名则追加(默认 .js)
|
|
21
|
+
*/
|
|
10
22
|
declare function addExtension(filename: string, ext?: string): string;
|
|
11
|
-
|
|
23
|
+
/**
|
|
24
|
+
* @description 将单个值转换为数组
|
|
25
|
+
*/
|
|
26
|
+
declare function arrify<T>(val: T | readonly T[]): T[];
|
|
12
27
|
|
|
28
|
+
/**
|
|
29
|
+
* @description defu 合并策略:当目标/来源为数组时直接覆盖
|
|
30
|
+
*/
|
|
13
31
|
declare const defuOverrideArray: <Source extends {
|
|
14
32
|
[x: string]: any;
|
|
15
33
|
[x: number]: any;
|
|
@@ -19,7 +37,13 @@ declare const defuOverrideArray: <Source extends {
|
|
|
19
37
|
[x: number]: any;
|
|
20
38
|
[x: symbol]: any;
|
|
21
39
|
} | (number | boolean | any[] | Record<never, any> | null | undefined)>>(source: Source, ...defaults: Defaults) => defu.Defu<Source, Defaults>;
|
|
40
|
+
/**
|
|
41
|
+
* @description 判断是否为非 null 的对象
|
|
42
|
+
*/
|
|
22
43
|
declare function isObject(x: unknown): x is Record<string | symbol | number, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* @description 判断对象是否为空对象
|
|
46
|
+
*/
|
|
23
47
|
declare function isEmptyObject(obj: unknown): boolean;
|
|
24
48
|
|
|
25
49
|
export { addExtension, arrify, defuOverrideArray, escapeStringRegexp, isEmptyObject, isObject, removeExtension, removeExtensionDeep };
|
package/dist/index.js
CHANGED
|
@@ -27,11 +27,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
mod
|
|
28
28
|
));
|
|
29
29
|
|
|
30
|
-
// ../../node_modules/.pnpm/tsup@8.5.1_@
|
|
30
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.56.0_@types+node@25.2.0__@swc+core@1.15.11_jiti@2_1af55e4e1e3a88da689103a99e6896b3/node_modules/tsup/assets/esm_shims.js
|
|
31
31
|
import path from "path";
|
|
32
32
|
import { fileURLToPath } from "url";
|
|
33
33
|
var init_esm_shims = __esm({
|
|
34
|
-
"../../node_modules/.pnpm/tsup@8.5.1_@
|
|
34
|
+
"../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.56.0_@types+node@25.2.0__@swc+core@1.15.11_jiti@2_1af55e4e1e3a88da689103a99e6896b3/node_modules/tsup/assets/esm_shims.js"() {
|
|
35
35
|
"use strict";
|
|
36
36
|
}
|
|
37
37
|
});
|
|
@@ -398,7 +398,10 @@ function addExtension(filename, ext = ".js") {
|
|
|
398
398
|
return result;
|
|
399
399
|
}
|
|
400
400
|
function arrify(val) {
|
|
401
|
-
|
|
401
|
+
if (Array.isArray(val)) {
|
|
402
|
+
return [...val];
|
|
403
|
+
}
|
|
404
|
+
return [val];
|
|
402
405
|
}
|
|
403
406
|
var defuOverrideArray = createDefu((obj, key, value) => {
|
|
404
407
|
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|