@weapp-core/shared 3.0.0 → 3.0.2

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 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
@@ -1,25 +1,110 @@
1
- import * as defu from 'defu';
2
- export { default as defu } from 'defu';
3
- export { default as objectHash } from 'object-hash';
4
- export { default as get } from 'get-value';
5
- export { default as set } from 'set-value';
1
+ import objectHash from "object-hash";
2
+ import set from "set-value";
6
3
 
4
+ //#region ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.d.ts
5
+ type Input = Record<string | number | symbol, any>;
6
+ type IgnoredInput = boolean | number | null | any[] | Record<never, any> | undefined;
7
+ type Merger = <T extends Input, K extends keyof T>(object: T, key: keyof T, value: T[K], namespace: string) => any;
8
+ type nullish = null | undefined | void;
9
+ type MergeObjects<Destination extends Input, Defaults extends Input> = Destination extends Defaults ? Destination : Omit<Destination, keyof Destination & keyof Defaults> & Omit<Defaults, keyof Destination & keyof Defaults> & { -readonly [Key in keyof Destination & keyof Defaults]: Destination[Key] extends nullish ? Defaults[Key] extends nullish ? nullish : Defaults[Key] : Defaults[Key] extends nullish ? Destination[Key] : Merge<Destination[Key], Defaults[Key]> };
10
+ type Defu<S extends Input, D extends Array<Input | IgnoredInput>> = D extends [infer F, ...infer Rest] ? F extends Input ? Rest extends Array<Input | IgnoredInput> ? Defu<MergeObjects<S, F>, Rest> : MergeObjects<S, F> : F extends IgnoredInput ? Rest extends Array<Input | IgnoredInput> ? Defu<S, Rest> : S : S : S;
11
+ type DefuFn = <Source extends Input, Defaults extends Array<Input | IgnoredInput>>(source: Source, ...defaults: Defaults) => Defu<Source, Defaults>;
12
+ interface DefuInstance {
13
+ <Source extends Input, Defaults extends Array<Input | IgnoredInput>>(source: Source | IgnoredInput, ...defaults: Defaults): Defu<Source, Defaults>;
14
+ fn: DefuFn;
15
+ arrayFn: DefuFn;
16
+ extend(merger?: Merger): DefuFn;
17
+ }
18
+ type MergeArrays<Destination, Source> = Destination extends Array<infer DestinationType> ? Source extends Array<infer SourceType> ? Array<DestinationType | SourceType> : Source | Array<DestinationType> : Source | Destination;
19
+ type Merge<Destination extends Input, Defaults extends Input> = Destination extends nullish ? Defaults extends nullish ? nullish : Defaults : Defaults extends nullish ? Destination : Destination extends Array<any> ? Defaults extends Array<any> ? MergeArrays<Destination, Defaults> : Destination | Defaults : Destination extends Function ? Destination | Defaults : Destination extends RegExp ? Destination | Defaults : Destination extends Promise<any> ? Destination | Defaults : Defaults extends Function ? Destination | Defaults : Defaults extends RegExp ? Destination | Defaults : Defaults extends Promise<any> ? Destination | Defaults : Destination extends Input ? Defaults extends Input ? MergeObjects<Destination, Defaults> : Destination | Defaults : Destination | Defaults;
20
+ declare const defu: DefuInstance;
21
+ //#endregion
22
+ //#region ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/index.d.ts
23
+ declare function get<T>(obj: T): T;
24
+ declare function get(obj: object, key: string | string[], options?: get.Options): any;
25
+ declare namespace get {
26
+ interface Options {
27
+ /**
28
+ * The default value to return when get-value cannot result a value from the given object.
29
+ *
30
+ * default: `undefined`
31
+ */
32
+ default?: any;
33
+ /**
34
+ * If defined, this function is called on each resolved value.
35
+ * Useful if you want to do `.hasOwnProperty` or `Object.prototype.propertyIsEnumerable`.
36
+ */
37
+ isValid?: (<K extends string>(key: K, object: Record<K, any>) => boolean) | undefined;
38
+ /**
39
+ * Custom function to use for splitting the string into object path segments.
40
+ *
41
+ * default: `String.split`
42
+ */
43
+ split?: ((s: string) => string[]) | undefined;
44
+ /**
45
+ * The separator to use for spliting the string.
46
+ * (this is probably not needed when `options.split` is used).
47
+ *
48
+ * default: `"."`
49
+ */
50
+ separator?: string | RegExp | undefined;
51
+ /**
52
+ * Customize how the object path is created when iterating over path segments.
53
+ *
54
+ * default: `Array.join`
55
+ */
56
+ join?: ((segs: string[]) => string) | undefined;
57
+ /**
58
+ * The character to use when re-joining the string to check for keys
59
+ * with dots in them (this is probably not needed when `options.join` is used).
60
+ * This can be a different value than the separator, since the separator can be a string or regex.
61
+ *
62
+ * default: `"."`
63
+ */
64
+ joinChar?: string | undefined;
65
+ }
66
+ }
67
+ //#endregion
68
+ //#region src/index.d.ts
69
+ /**
70
+ * @description 转义字符串中的正则特殊字符
71
+ */
7
72
  declare function escapeStringRegexp(str: string): string;
73
+ /**
74
+ * @description 移除文件名的最后一个扩展名
75
+ */
8
76
  declare function removeExtension(file: string): string;
77
+ /**
78
+ * @description 移除文件名的所有扩展名(多重后缀)
79
+ */
9
80
  declare function removeExtensionDeep(file: string): string;
81
+ /**
82
+ * @description 若缺少扩展名则追加(默认 .js)
83
+ */
10
84
  declare function addExtension(filename: string, ext?: string): string;
11
- declare function arrify<T>(val: T): T | T[];
12
-
85
+ /**
86
+ * @description 将单个值转换为数组
87
+ */
88
+ declare function arrify<T>(val: T | readonly T[]): T[];
89
+ /**
90
+ * @description defu 合并策略:当目标/来源为数组时直接覆盖
91
+ */
13
92
  declare const defuOverrideArray: <Source extends {
14
- [x: string]: any;
15
- [x: number]: any;
16
- [x: symbol]: any;
93
+ [x: string]: any;
94
+ [x: number]: any;
95
+ [x: symbol]: any;
17
96
  }, Defaults extends Array<{
18
- [x: string]: any;
19
- [x: number]: any;
20
- [x: symbol]: any;
21
- } | (number | boolean | any[] | Record<never, any> | null | undefined)>>(source: Source, ...defaults: Defaults) => defu.Defu<Source, Defaults>;
97
+ [x: string]: any;
98
+ [x: number]: any;
99
+ [x: symbol]: any;
100
+ } | (number | boolean | any[] | Record<never, any> | null | undefined)>>(source: Source, ...defaults: Defaults) => Defu<Source, Defaults>;
101
+ /**
102
+ * @description 判断是否为非 null 的对象
103
+ */
22
104
  declare function isObject(x: unknown): x is Record<string | symbol | number, unknown>;
105
+ /**
106
+ * @description 判断对象是否为空对象
107
+ */
23
108
  declare function isEmptyObject(obj: unknown): boolean;
24
-
25
- export { addExtension, arrify, defuOverrideArray, escapeStringRegexp, isEmptyObject, isObject, removeExtension, removeExtensionDeep };
109
+ //#endregion
110
+ export { addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, get, isEmptyObject, isObject, objectHash, removeExtension, removeExtensionDeep, set };
package/dist/index.js CHANGED
@@ -1,478 +1,355 @@
1
+ import { extname } from "node:path";
2
+ import objectHash from "object-hash";
3
+ //#region \0rolldown/runtime.js
1
4
  var __create = Object.create;
2
- var __defProp = Object.defineProperty;
5
+ var __defProp$1 = Object.defineProperty;
3
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
8
  var __getProtoOf = Object.getPrototypeOf;
6
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __commonJS = (cb, mod) => function __require() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
- };
10
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
13
11
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
12
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
+ key = keys[i];
14
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp$1(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
20
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
-
30
- // ../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.8_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/esm_shims.js
31
- import path from "path";
32
- import { fileURLToPath } from "url";
33
- var init_esm_shims = __esm({
34
- "../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.8_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/esm_shims.js"() {
35
- "use strict";
36
- }
37
- });
38
-
39
- // ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
40
- var require_is_primitive = __commonJS({
41
- "../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js"(exports, module) {
42
- "use strict";
43
- init_esm_shims();
44
- module.exports = function isPrimitive(val) {
45
- if (typeof val === "object") {
46
- return val === null;
47
- }
48
- return typeof val !== "function";
49
- };
50
- }
51
- });
52
-
53
- // ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
54
- var require_isobject = __commonJS({
55
- "../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports, module) {
56
- "use strict";
57
- init_esm_shims();
58
- module.exports = function isObject3(val) {
59
- return val != null && typeof val === "object" && Array.isArray(val) === false;
60
- };
61
- }
62
- });
63
-
64
- // ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
65
- var require_is_plain_object = __commonJS({
66
- "../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js"(exports, module) {
67
- "use strict";
68
- init_esm_shims();
69
- var isObject3 = require_isobject();
70
- function isObjectObject(o) {
71
- return isObject3(o) === true && Object.prototype.toString.call(o) === "[object Object]";
72
- }
73
- module.exports = function isPlainObject2(o) {
74
- var ctor, prot;
75
- if (isObjectObject(o) === false) return false;
76
- ctor = o.constructor;
77
- if (typeof ctor !== "function") return false;
78
- prot = ctor.prototype;
79
- if (isObjectObject(prot) === false) return false;
80
- if (prot.hasOwnProperty("isPrototypeOf") === false) {
81
- return false;
82
- }
83
- return true;
84
- };
85
- }
86
- });
87
-
88
- // ../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js
89
- var require_set_value = __commonJS({
90
- "../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js"(exports, module) {
91
- "use strict";
92
- init_esm_shims();
93
- var { deleteProperty } = Reflect;
94
- var isPrimitive = require_is_primitive();
95
- var isPlainObject2 = require_is_plain_object();
96
- var isObject3 = (value) => {
97
- return typeof value === "object" && value !== null || typeof value === "function";
98
- };
99
- var isUnsafeKey = (key) => {
100
- return key === "__proto__" || key === "constructor" || key === "prototype";
101
- };
102
- var validateKey = (key) => {
103
- if (!isPrimitive(key)) {
104
- throw new TypeError("Object keys must be strings or symbols");
105
- }
106
- if (isUnsafeKey(key)) {
107
- throw new Error(`Cannot set unsafe key: "${key}"`);
108
- }
109
- };
110
- var toStringKey = (input) => {
111
- return Array.isArray(input) ? input.flat().map(String).join(",") : input;
112
- };
113
- var createMemoKey = (input, options) => {
114
- if (typeof input !== "string" || !options) return input;
115
- let key = input + ";";
116
- if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
117
- if (options.separator !== void 0) key += `separator=${options.separator};`;
118
- if (options.split !== void 0) key += `split=${options.split};`;
119
- if (options.merge !== void 0) key += `merge=${options.merge};`;
120
- if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
121
- return key;
122
- };
123
- var memoize = (input, options, fn) => {
124
- const key = toStringKey(options ? createMemoKey(input, options) : input);
125
- validateKey(key);
126
- const value = setValue.cache.get(key) || fn();
127
- setValue.cache.set(key, value);
128
- return value;
129
- };
130
- var splitString = (input, options = {}) => {
131
- const sep = options.separator || ".";
132
- const preserve = sep === "/" ? false : options.preservePaths;
133
- if (typeof input === "string" && preserve !== false && /\//.test(input)) {
134
- return [input];
135
- }
136
- const parts = [];
137
- let part = "";
138
- const push = (part2) => {
139
- let number;
140
- if (part2.trim() !== "" && Number.isInteger(number = Number(part2))) {
141
- parts.push(number);
142
- } else {
143
- parts.push(part2);
144
- }
145
- };
146
- for (let i = 0; i < input.length; i++) {
147
- const value = input[i];
148
- if (value === "\\") {
149
- part += input[++i];
150
- continue;
151
- }
152
- if (value === sep) {
153
- push(part);
154
- part = "";
155
- continue;
156
- }
157
- part += value;
158
- }
159
- if (part) {
160
- push(part);
161
- }
162
- return parts;
163
- };
164
- var split2 = (input, options) => {
165
- if (options && typeof options.split === "function") return options.split(input);
166
- if (typeof input === "symbol") return [input];
167
- if (Array.isArray(input)) return input;
168
- return memoize(input, options, () => splitString(input, options));
169
- };
170
- var assignProp = (obj, prop, value, options) => {
171
- validateKey(prop);
172
- if (value === void 0) {
173
- deleteProperty(obj, prop);
174
- } else if (options && options.merge) {
175
- const merge = options.merge === "function" ? options.merge : Object.assign;
176
- if (merge && isPlainObject2(obj[prop]) && isPlainObject2(value)) {
177
- obj[prop] = merge(obj[prop], value);
178
- } else {
179
- obj[prop] = value;
180
- }
181
- } else {
182
- obj[prop] = value;
183
- }
184
- return obj;
185
- };
186
- var setValue = (target, path2, value, options) => {
187
- if (!path2 || !isObject3(target)) return target;
188
- const keys = split2(path2, options);
189
- let obj = target;
190
- for (let i = 0; i < keys.length; i++) {
191
- const key = keys[i];
192
- const next = keys[i + 1];
193
- validateKey(key);
194
- if (next === void 0) {
195
- assignProp(obj, key, value, options);
196
- break;
197
- }
198
- if (typeof next === "number" && !Array.isArray(obj[key])) {
199
- obj = obj[key] = [];
200
- continue;
201
- }
202
- if (!isObject3(obj[key])) {
203
- obj[key] = {};
204
- }
205
- obj = obj[key];
206
- }
207
- return target;
208
- };
209
- setValue.split = split2;
210
- setValue.cache = /* @__PURE__ */ new Map();
211
- setValue.clear = () => {
212
- setValue.cache = /* @__PURE__ */ new Map();
213
- };
214
- module.exports = setValue;
215
- }
216
- });
217
-
218
- // src/index.ts
219
- init_esm_shims();
220
- import { extname } from "path";
221
-
222
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
223
- init_esm_shims();
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
22
+ value: mod,
23
+ enumerable: true
24
+ }) : target, mod));
25
+ //#endregion
26
+ //#region ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
224
27
  function isPlainObject(value) {
225
- if (value === null || typeof value !== "object") {
226
- return false;
227
- }
228
- const prototype = Object.getPrototypeOf(value);
229
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
230
- return false;
231
- }
232
- if (Symbol.iterator in value) {
233
- return false;
234
- }
235
- if (Symbol.toStringTag in value) {
236
- return Object.prototype.toString.call(value) === "[object Module]";
237
- }
238
- return true;
28
+ if (value === null || typeof value !== "object") return false;
29
+ const prototype = Object.getPrototypeOf(value);
30
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
31
+ if (Symbol.iterator in value) return false;
32
+ if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
33
+ return true;
239
34
  }
240
35
  function _defu(baseObject, defaults, namespace = ".", merger) {
241
- if (!isPlainObject(defaults)) {
242
- return _defu(baseObject, {}, namespace, merger);
243
- }
244
- const object = Object.assign({}, defaults);
245
- for (const key in baseObject) {
246
- if (key === "__proto__" || key === "constructor") {
247
- continue;
248
- }
249
- const value = baseObject[key];
250
- if (value === null || value === void 0) {
251
- continue;
252
- }
253
- if (merger && merger(object, key, value, namespace)) {
254
- continue;
255
- }
256
- if (Array.isArray(value) && Array.isArray(object[key])) {
257
- object[key] = [...value, ...object[key]];
258
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
259
- object[key] = _defu(
260
- value,
261
- object[key],
262
- (namespace ? `${namespace}.` : "") + key.toString(),
263
- merger
264
- );
265
- } else {
266
- object[key] = value;
267
- }
268
- }
269
- return object;
36
+ if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
37
+ const object = Object.assign({}, defaults);
38
+ for (const key in baseObject) {
39
+ if (key === "__proto__" || key === "constructor") continue;
40
+ const value = baseObject[key];
41
+ if (value === null || value === void 0) continue;
42
+ if (merger && merger(object, key, value, namespace)) continue;
43
+ if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
44
+ else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
45
+ else object[key] = value;
46
+ }
47
+ return object;
270
48
  }
271
49
  function createDefu(merger) {
272
- return (...arguments_) => (
273
- // eslint-disable-next-line unicorn/no-array-reduce
274
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
275
- );
50
+ return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
276
51
  }
277
- var defu = createDefu();
278
- var defuFn = createDefu((object, key, currentValue) => {
279
- if (object[key] !== void 0 && typeof currentValue === "function") {
280
- object[key] = currentValue(object[key]);
281
- return true;
282
- }
52
+ const defu = createDefu();
53
+ createDefu((object, key, currentValue) => {
54
+ if (object[key] !== void 0 && typeof currentValue === "function") {
55
+ object[key] = currentValue(object[key]);
56
+ return true;
57
+ }
283
58
  });
284
- var defuArrayFn = createDefu((object, key, currentValue) => {
285
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
286
- object[key] = currentValue(object[key]);
287
- return true;
288
- }
59
+ createDefu((object, key, currentValue) => {
60
+ if (Array.isArray(object[key]) && typeof currentValue === "function") {
61
+ object[key] = currentValue(object[key]);
62
+ return true;
63
+ }
289
64
  });
290
-
291
- // src/index.ts
292
- import objectHash from "object-hash";
293
-
294
- // ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/dist/index.mjs
295
- init_esm_shims();
296
- var __defProp2 = Object.defineProperty;
297
- var __name = (target, value) => __defProp2(target, "name", { value, configurable: true });
298
- var isObject = /* @__PURE__ */ __name((v) => v !== null && typeof v === "object", "isObject");
65
+ //#endregion
66
+ //#region ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/dist/index.mjs
67
+ var __defProp = Object.defineProperty;
68
+ var __name = (target, value) => __defProp(target, "name", {
69
+ value,
70
+ configurable: true
71
+ });
72
+ var isObject$1 = /* @__PURE__ */ __name((v) => v !== null && typeof v === "object", "isObject");
299
73
  var join = /* @__PURE__ */ __name((segs, joinChar, options) => {
300
- if (typeof options.join === "function") {
301
- return options.join(segs);
302
- }
303
- return segs[0] + joinChar + segs[1];
74
+ if (typeof options.join === "function") return options.join(segs);
75
+ return segs[0] + joinChar + segs[1];
304
76
  }, "join");
305
- var split = /* @__PURE__ */ __name((path2, splitChar, options) => {
306
- if (typeof options.split === "function") {
307
- return options.split(path2);
308
- }
309
- return path2.split(splitChar);
77
+ var split = /* @__PURE__ */ __name((path, splitChar, options) => {
78
+ if (typeof options.split === "function") return options.split(path);
79
+ return path.split(splitChar);
310
80
  }, "split");
311
81
  var isValid = /* @__PURE__ */ __name((key, target = {}, options) => {
312
- if (typeof options?.isValid === "function") {
313
- return options.isValid(key, target);
314
- }
315
- return true;
82
+ if (typeof options?.isValid === "function") return options.isValid(key, target);
83
+ return true;
316
84
  }, "isValid");
317
85
  var isValidObject = /* @__PURE__ */ __name((v) => {
318
- return isObject(v) || typeof v === "function";
86
+ return isObject$1(v) || typeof v === "function";
319
87
  }, "isValidObject");
320
- var getValue = /* @__PURE__ */ __name((target, path2, options = {}) => {
321
- if (!isObject(options)) {
322
- options = { default: options };
323
- }
324
- if (!isValidObject(target)) {
325
- return typeof options.default !== "undefined" ? options.default : target;
326
- }
327
- if (typeof path2 === "number") {
328
- path2 = String(path2);
329
- }
330
- const pathIsArray = Array.isArray(path2);
331
- const pathIsString = typeof path2 === "string";
332
- const splitChar = options.separator || ".";
333
- const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
334
- if (!pathIsString && !pathIsArray) {
335
- return target;
336
- }
337
- if (target[path2] !== void 0) {
338
- return isValid(path2, target, options) ? target[path2] : options.default;
339
- }
340
- const segs = pathIsArray ? path2 : split(path2, splitChar, options);
341
- const len = segs.length;
342
- let idx = 0;
343
- do {
344
- let prop = segs[idx];
345
- if (typeof prop !== "string") {
346
- prop = String(prop);
347
- }
348
- while (prop && prop.slice(-1) === "\\") {
349
- prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
350
- }
351
- if (target[prop] !== void 0) {
352
- if (!isValid(prop, target, options)) {
353
- return options.default;
354
- }
355
- target = target[prop];
356
- } else {
357
- let hasProp = false;
358
- let n = idx + 1;
359
- while (n < len) {
360
- prop = join([prop, segs[n++]], joinChar, options);
361
- if (hasProp = target[prop] !== void 0) {
362
- if (!isValid(prop, target, options)) {
363
- return options.default;
364
- }
365
- target = target[prop];
366
- idx = n - 1;
367
- break;
368
- }
369
- }
370
- if (!hasProp) {
371
- return options.default;
372
- }
373
- }
374
- } while (++idx < len && isValidObject(target));
375
- if (idx === len) {
376
- return target;
377
- }
378
- return options.default;
88
+ var index_default = /* @__PURE__ */ __name((target, path, options = {}) => {
89
+ if (!isObject$1(options)) options = { default: options };
90
+ if (!isValidObject(target)) return typeof options.default !== "undefined" ? options.default : target;
91
+ if (typeof path === "number") path = String(path);
92
+ const pathIsArray = Array.isArray(path);
93
+ const pathIsString = typeof path === "string";
94
+ const splitChar = options.separator || ".";
95
+ const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
96
+ if (!pathIsString && !pathIsArray) return target;
97
+ if (target[path] !== void 0) return isValid(path, target, options) ? target[path] : options.default;
98
+ const segs = pathIsArray ? path : split(path, splitChar, options);
99
+ const len = segs.length;
100
+ let idx = 0;
101
+ do {
102
+ let prop = segs[idx];
103
+ if (typeof prop !== "string") prop = String(prop);
104
+ while (prop && prop.slice(-1) === "\\") prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
105
+ if (target[prop] !== void 0) {
106
+ if (!isValid(prop, target, options)) return options.default;
107
+ target = target[prop];
108
+ } else {
109
+ let hasProp = false;
110
+ let n = idx + 1;
111
+ while (n < len) {
112
+ prop = join([prop, segs[n++]], joinChar, options);
113
+ if (hasProp = target[prop] !== void 0) {
114
+ if (!isValid(prop, target, options)) return options.default;
115
+ target = target[prop];
116
+ idx = n - 1;
117
+ break;
118
+ }
119
+ }
120
+ if (!hasProp) return options.default;
121
+ }
122
+ } while (++idx < len && isValidObject(target));
123
+ if (idx === len) return target;
124
+ return options.default;
379
125
  }, "getValue");
380
- var index_default = getValue;
381
-
382
- // src/index.ts
383
- var import_set_value = __toESM(require_set_value(), 1);
126
+ /*!
127
+ * get-value <https://github.com/jonschlinkert/get-value>
128
+ *
129
+ * Copyright (c) 2014-present, Jon Schlinkert.
130
+ * Released under the MIT License.
131
+ */
132
+ //#endregion
133
+ //#region ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
134
+ /*!
135
+ * is-primitive <https://github.com/jonschlinkert/is-primitive>
136
+ *
137
+ * Copyright (c) 2014-present, Jon Schlinkert.
138
+ * Released under the MIT License.
139
+ */
140
+ var require_is_primitive = /* @__PURE__ */ __commonJSMin(((exports, module) => {
141
+ module.exports = function isPrimitive(val) {
142
+ if (typeof val === "object") return val === null;
143
+ return typeof val !== "function";
144
+ };
145
+ }));
146
+ //#endregion
147
+ //#region ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
148
+ /*!
149
+ * isobject <https://github.com/jonschlinkert/isobject>
150
+ *
151
+ * Copyright (c) 2014-2017, Jon Schlinkert.
152
+ * Released under the MIT License.
153
+ */
154
+ var require_isobject = /* @__PURE__ */ __commonJSMin(((exports, module) => {
155
+ module.exports = function isObject(val) {
156
+ return val != null && typeof val === "object" && Array.isArray(val) === false;
157
+ };
158
+ }));
159
+ //#endregion
160
+ //#region ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
161
+ /*!
162
+ * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
163
+ *
164
+ * Copyright (c) 2014-2017, Jon Schlinkert.
165
+ * Released under the MIT License.
166
+ */
167
+ var require_is_plain_object = /* @__PURE__ */ __commonJSMin(((exports, module) => {
168
+ var isObject = require_isobject();
169
+ function isObjectObject(o) {
170
+ return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
171
+ }
172
+ module.exports = function isPlainObject(o) {
173
+ var ctor, prot;
174
+ if (isObjectObject(o) === false) return false;
175
+ ctor = o.constructor;
176
+ if (typeof ctor !== "function") return false;
177
+ prot = ctor.prototype;
178
+ if (isObjectObject(prot) === false) return false;
179
+ if (prot.hasOwnProperty("isPrototypeOf") === false) return false;
180
+ return true;
181
+ };
182
+ }));
183
+ //#endregion
184
+ //#region src/index.ts
185
+ var import_set_value = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
186
+ const { deleteProperty } = Reflect;
187
+ const isPrimitive = require_is_primitive();
188
+ const isPlainObject = require_is_plain_object();
189
+ const isObject = (value) => {
190
+ return typeof value === "object" && value !== null || typeof value === "function";
191
+ };
192
+ const isUnsafeKey = (key) => {
193
+ return key === "__proto__" || key === "constructor" || key === "prototype";
194
+ };
195
+ const validateKey = (key) => {
196
+ if (!isPrimitive(key)) throw new TypeError("Object keys must be strings or symbols");
197
+ if (isUnsafeKey(key)) throw new Error(`Cannot set unsafe key: "${key}"`);
198
+ };
199
+ const toStringKey = (input) => {
200
+ return Array.isArray(input) ? input.flat().map(String).join(",") : input;
201
+ };
202
+ const createMemoKey = (input, options) => {
203
+ if (typeof input !== "string" || !options) return input;
204
+ let key = input + ";";
205
+ if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
206
+ if (options.separator !== void 0) key += `separator=${options.separator};`;
207
+ if (options.split !== void 0) key += `split=${options.split};`;
208
+ if (options.merge !== void 0) key += `merge=${options.merge};`;
209
+ if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
210
+ return key;
211
+ };
212
+ const memoize = (input, options, fn) => {
213
+ const key = toStringKey(options ? createMemoKey(input, options) : input);
214
+ validateKey(key);
215
+ const value = setValue.cache.get(key) || fn();
216
+ setValue.cache.set(key, value);
217
+ return value;
218
+ };
219
+ const splitString = (input, options = {}) => {
220
+ const sep = options.separator || ".";
221
+ const preserve = sep === "/" ? false : options.preservePaths;
222
+ if (typeof input === "string" && preserve !== false && /\//.test(input)) return [input];
223
+ const parts = [];
224
+ let part = "";
225
+ const push = (part) => {
226
+ let number;
227
+ if (part.trim() !== "" && Number.isInteger(number = Number(part))) parts.push(number);
228
+ else parts.push(part);
229
+ };
230
+ for (let i = 0; i < input.length; i++) {
231
+ const value = input[i];
232
+ if (value === "\\") {
233
+ part += input[++i];
234
+ continue;
235
+ }
236
+ if (value === sep) {
237
+ push(part);
238
+ part = "";
239
+ continue;
240
+ }
241
+ part += value;
242
+ }
243
+ if (part) push(part);
244
+ return parts;
245
+ };
246
+ const split = (input, options) => {
247
+ if (options && typeof options.split === "function") return options.split(input);
248
+ if (typeof input === "symbol") return [input];
249
+ if (Array.isArray(input)) return input;
250
+ return memoize(input, options, () => splitString(input, options));
251
+ };
252
+ const assignProp = (obj, prop, value, options) => {
253
+ validateKey(prop);
254
+ if (value === void 0) deleteProperty(obj, prop);
255
+ else if (options && options.merge) {
256
+ const merge = options.merge === "function" ? options.merge : Object.assign;
257
+ if (merge && isPlainObject(obj[prop]) && isPlainObject(value)) obj[prop] = merge(obj[prop], value);
258
+ else obj[prop] = value;
259
+ } else obj[prop] = value;
260
+ return obj;
261
+ };
262
+ const setValue = (target, path, value, options) => {
263
+ if (!path || !isObject(target)) return target;
264
+ const keys = split(path, options);
265
+ let obj = target;
266
+ for (let i = 0; i < keys.length; i++) {
267
+ const key = keys[i];
268
+ const next = keys[i + 1];
269
+ validateKey(key);
270
+ if (next === void 0) {
271
+ assignProp(obj, key, value, options);
272
+ break;
273
+ }
274
+ if (typeof next === "number" && !Array.isArray(obj[key])) {
275
+ obj = obj[key] = [];
276
+ continue;
277
+ }
278
+ if (!isObject(obj[key])) obj[key] = {};
279
+ obj = obj[key];
280
+ }
281
+ return target;
282
+ };
283
+ setValue.split = split;
284
+ setValue.cache = /* @__PURE__ */ new Map();
285
+ setValue.clear = () => {
286
+ setValue.cache = /* @__PURE__ */ new Map();
287
+ };
288
+ module.exports = setValue;
289
+ })))(), 1);
290
+ const SPECIAL_CHARS_RE = /[|\\{}()[\]^$+*?.]/g;
291
+ const HYPHEN_RE = /-/g;
292
+ const LAST_EXT_RE = /\.[^/.]+$/;
293
+ const ALL_EXT_RE = /(\.[^/.]+)+$/;
294
+ /**
295
+ * @description 转义字符串中的正则特殊字符
296
+ */
384
297
  function escapeStringRegexp(str) {
385
- return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
298
+ return str.replace(SPECIAL_CHARS_RE, "\\$&").replace(HYPHEN_RE, "\\x2d");
386
299
  }
300
+ /**
301
+ * @description 移除文件名的最后一个扩展名
302
+ */
387
303
  function removeExtension(file) {
388
- return file.replace(/\.[^/.]+$/, "");
304
+ return file.replace(LAST_EXT_RE, "");
389
305
  }
306
+ /**
307
+ * @description 移除文件名的所有扩展名(多重后缀)
308
+ */
390
309
  function removeExtensionDeep(file) {
391
- return file.replace(/(\.[^/.]+)+$/, "");
310
+ return file.replace(ALL_EXT_RE, "");
392
311
  }
312
+ /**
313
+ * @description 若缺少扩展名则追加(默认 .js)
314
+ */
393
315
  function addExtension(filename, ext = ".js") {
394
- let result = `${filename}`;
395
- if (!extname(filename)) {
396
- result += ext;
397
- }
398
- return result;
316
+ let result = `${filename}`;
317
+ if (!extname(filename)) result += ext;
318
+ return result;
399
319
  }
320
+ /**
321
+ * @description 将单个值转换为数组
322
+ */
400
323
  function arrify(val) {
401
- return Array.isArray(val) ? val : [val];
324
+ if (Array.isArray(val)) return [...val];
325
+ return [val];
402
326
  }
403
- var defuOverrideArray = createDefu((obj, key, value) => {
404
- if (Array.isArray(obj[key]) && Array.isArray(value)) {
405
- obj[key] = value;
406
- return true;
407
- }
327
+ /**
328
+ * @description defu 合并策略:当目标/来源为数组时直接覆盖
329
+ */
330
+ const defuOverrideArray = createDefu((obj, key, value) => {
331
+ if (Array.isArray(obj[key]) && Array.isArray(value)) {
332
+ obj[key] = value;
333
+ return true;
334
+ }
408
335
  });
409
- function isObject2(x) {
410
- return typeof x === "object" && x !== null;
336
+ /**
337
+ * @description 判断是否为非 null 的对象
338
+ */
339
+ function isObject(x) {
340
+ return typeof x === "object" && x !== null;
411
341
  }
342
+ /**
343
+ * @description 判断对象是否为空对象
344
+ */
412
345
  function isEmptyObject(obj) {
413
- if (isObject2(obj)) {
414
- let name;
415
- for (name in obj) {
416
- return false;
417
- }
418
- return true;
419
- }
420
- return false;
346
+ if (isObject(obj)) {
347
+ let name;
348
+ for (name in obj) return false;
349
+ return true;
350
+ }
351
+ return false;
421
352
  }
422
- var export_set = import_set_value.default;
423
- export {
424
- addExtension,
425
- arrify,
426
- defu,
427
- defuOverrideArray,
428
- escapeStringRegexp,
429
- index_default as get,
430
- isEmptyObject,
431
- isObject2 as isObject,
432
- objectHash,
433
- removeExtension,
434
- removeExtensionDeep,
435
- export_set as set
436
- };
437
- /*! Bundled license information:
438
-
439
- is-primitive/index.js:
440
- (*!
441
- * is-primitive <https://github.com/jonschlinkert/is-primitive>
442
- *
443
- * Copyright (c) 2014-present, Jon Schlinkert.
444
- * Released under the MIT License.
445
- *)
446
-
447
- isobject/index.js:
448
- (*!
449
- * isobject <https://github.com/jonschlinkert/isobject>
450
- *
451
- * Copyright (c) 2014-2017, Jon Schlinkert.
452
- * Released under the MIT License.
453
- *)
454
-
455
- is-plain-object/index.js:
456
- (*!
457
- * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
458
- *
459
- * Copyright (c) 2014-2017, Jon Schlinkert.
460
- * Released under the MIT License.
461
- *)
462
-
463
- set-value/index.js:
464
- (*!
465
- * set-value <https://github.com/jonschlinkert/set-value>
466
- *
467
- * Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
468
- * Released under the MIT License.
469
- *)
470
-
471
- get-value/dist/index.mjs:
472
- (*!
473
- * get-value <https://github.com/jonschlinkert/get-value>
474
- *
475
- * Copyright (c) 2014-present, Jon Schlinkert.
476
- * Released under the MIT License.
477
- *)
478
- */
353
+ //#endregion
354
+ var set = import_set_value.default;
355
+ export { addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, index_default as get, isEmptyObject, isObject, objectHash, removeExtension, removeExtensionDeep, set };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-core/shared",
3
3
  "type": "module",
4
- "version": "3.0.0",
4
+ "version": "3.0.2",
5
5
  "description": "@weapp-core/shared",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -46,10 +46,11 @@
46
46
  },
47
47
  "devDependencies": {},
48
48
  "scripts": {
49
- "dev": "tsup --watch --sourcemap",
50
- "build": "tsup",
49
+ "dev": "tsdown -w --sourcemap",
50
+ "build": "tsdown",
51
51
  "test": "vitest run",
52
52
  "test:dev": "vitest",
53
+ "typecheck": "tsc --noEmit",
53
54
  "release": "pnpm publish",
54
55
  "lint": "eslint .",
55
56
  "lint:fix": "eslint . --fix",