@zwa73/utils 1.0.285 → 1.0.287

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.
@@ -1,4 +1,4 @@
1
- import type { DataStore, JObject } from '@zwa73/js-utils';
1
+ import { type DataStore, type JObject } from '@zwa73/js-utils';
2
2
  /**JSON文件存储实现 */
3
3
  export declare class JsonStore<T extends JObject> implements DataStore<T> {
4
4
  /**存储的数据 */
@@ -9,8 +9,7 @@ export declare class JsonStore<T extends JObject> implements DataStore<T> {
9
9
  private _filepath;
10
10
  /**是否检查数据变更 */
11
11
  private _checkChange;
12
- /**
13
- * 构造函数
12
+ /**构造函数
14
13
  * @param opt 配置选项
15
14
  */
16
15
  constructor(opt: {
@@ -18,8 +18,7 @@ class JsonStore {
18
18
  _filepath;
19
19
  /**是否检查数据变更 */
20
20
  _checkChange;
21
- /**
22
- * 构造函数
21
+ /**构造函数
23
22
  * @param opt 配置选项
24
23
  */
25
24
  constructor(opt) {
@@ -1,18 +1,24 @@
1
+ import type { DataStore } from "@zwa73/js-utils";
1
2
  import { JsFunc } from "@zwa73/js-utils";
2
- import type { LogLevel } from "./UtilInterfaces";
3
+ import type { AnyString, LogLevel } from "./UtilInterfaces";
3
4
  declare const HashAlgorithmList: readonly ["RSA-MD5", "RSA-RIPEMD160", "RSA-SHA1", "RSA-SHA1-2", "RSA-SHA224", "RSA-SHA256", "RSA-SHA3-224", "RSA-SHA3-256", "RSA-SHA3-384", "RSA-SHA3-512", "RSA-SHA384", "RSA-SHA512", "RSA-SHA512/224", "RSA-SHA512/256", "RSA-SM3", "blake2b512", "blake2s256", "id-rsassa-pkcs1-v1_5-with-sha3-224", "id-rsassa-pkcs1-v1_5-with-sha3-256", "id-rsassa-pkcs1-v1_5-with-sha3-384", "id-rsassa-pkcs1-v1_5-with-sha3-512", "md5", "md5-sha1", "md5WithRSAEncryption", "ripemd", "ripemd160", "ripemd160WithRSA", "rmd160", "sha1", "sha1WithRSAEncryption", "sha224", "sha224WithRSAEncryption", "sha256", "sha256WithRSAEncryption", "sha3-224", "sha3-256", "sha3-384", "sha3-512", "sha384", "sha384WithRSAEncryption", "sha512", "sha512-224", "sha512-224WithRSAEncryption", "sha512-256", "sha512-256WithRSAEncryption", "sha512WithRSAEncryption", "shake128", "shake256", "sm3", "sm3WithRSAEncryption", "ssl3-md5", "ssl3-sha1"];
4
5
  export type HashAlgorithm = typeof HashAlgorithmList[number];
5
6
  /**执行选项 */
6
7
  type ExecOpt = Partial<{
7
8
  outlvl: LogLevel | ((arg: string) => any);
8
9
  errlvl: LogLevel | ((arg: string) => any);
9
- /**node_modules文件夹目录, 用于设定环境变量 */
10
- nodeModules: string;
10
+ /**node_modules文件夹目录, 用于设定环境变量 默认无
11
+ * undefined 时自动向上级查找
12
+ * 为‘None’ 时不使用
13
+ */
14
+ nodeModules: AnyString | 'None';
11
15
  /**工作路径 */
12
16
  cwd: string;
13
17
  /**额外环境变量 */
14
18
  env: string;
15
19
  }>;
20
+ /**可解析的数据存储源 */
21
+ export type ParseableDataStore<T> = string | T | DataStore<T>;
16
22
  /**常用函数 */
17
23
  declare class _UtilFunc {
18
24
  /**计算Hash
@@ -45,7 +51,12 @@ declare class _UtilFunc {
45
51
  * 依赖于 public-ip@6.0.2 但不会自动安装
46
52
  */
47
53
  static getPublicIpv4(): Promise<string>;
54
+ /**解析数据存储器源
55
+ * @param source 数据存储源
56
+ * @returns 数据存储对象
57
+ */
58
+ static resolveDataStore<T>(source: ParseableDataStore<T>): DataStore<T>;
48
59
  }
49
- export declare const UtilFunc: import("@zwa73/modular-mixer").ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "match" | "prototype" | "preset" | "assignOption" | "genUUID" | "getTime" | "initField" | "initObject" | "afterward" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "sortJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getStack" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "lazyFunction" | "splitToChunk" | "mergeFromChunk" | "structEqual" | "concurrent" | "dynamicImport" | "createInjectable" | "createAsyncProxy" | "checkSharpSchema" | "unwarpReadonly" | "outcome" | "extractOutcome" | "success" | "failed" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "range" | "s2l" | "l2s">;
60
+ export declare const UtilFunc: import("@zwa73/modular-mixer").ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "prototype" | "preset" | "assignOption" | "genUUID" | "getTime" | "initField" | "initObject" | "afterward" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "sortJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getStack" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "lazyFunction" | "splitToChunk" | "mergeFromChunk" | "structEqual" | "concurrent" | "dynamicImport" | "createInjectable" | "createAsyncProxy" | "checkSharpSchema" | "unwarpReadonly" | "outcome" | "extractOutcome" | "success" | "failed" | "match" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "range" | "s2l" | "l2s">;
50
61
  export type UtilFunc = typeof UtilFunc;
51
62
  export {};
@@ -34,6 +34,7 @@ const js_utils_1 = require("@zwa73/js-utils");
34
34
  const modular_mixer_1 = require("@zwa73/modular-mixer");
35
35
  const UtilSymbol_1 = require("./UtilSymbol");
36
36
  const Constant_1 = require("./Constant");
37
+ const UtilClass_1 = require("./UtilClass");
37
38
  const UtilFileTools_1 = require("./UtilFileTools");
38
39
  const UtilLogger_1 = require("./UtilLogger");
39
40
  const HashAlgorithmList = [
@@ -80,9 +81,10 @@ class _UtilFunc {
80
81
  // 创建一个新的环境变量对象,并将项目的 node_modules/.bin 目录添加到 PATH 环境变量中
81
82
  const env = Object.assign(Object.create(process.env), opt?.env ?? {});
82
83
  const penv = opt?.nodeModules
83
- ? path_1.default.join(UtilFileTools_1.UtilFT.currosizePath(opt.nodeModules), '.bin')
84
+ ? opt.nodeModules == 'None' ? ''
85
+ : path_1.default.join(UtilFileTools_1.UtilFT.currosizePath(opt.nodeModules), '.bin')
84
86
  : UtilFileTools_1.UtilFT.currosizePath(await exports.UtilFunc.memoize(UtilFileTools_1.UtilFT.findNodeModulesDir)(process.cwd(), '.bin') ?? '');
85
- if (_UtilFunc.checkEnv && (penv == "" || !await UtilFileTools_1.UtilFT.pathExists(penv))) {
87
+ if (opt?.nodeModules != "None" && (_UtilFunc.checkEnv && (penv == "" || !await UtilFileTools_1.UtilFT.pathExists(penv)))) {
86
88
  UtilLogger_1.SLogger.warn(`UtilFunc.exec 错误, 没有检测到 node_modules/.bin 环境 penv:${penv}`);
87
89
  _UtilFunc.checkEnv = false;
88
90
  }
@@ -137,6 +139,18 @@ class _UtilFunc {
137
139
  });
138
140
  return pip.publicIpv4();
139
141
  }
142
+ /**解析数据存储器源
143
+ * @param source 数据存储源
144
+ * @returns 数据存储对象
145
+ */
146
+ static resolveDataStore(source) {
147
+ if (typeof source == 'string')
148
+ return new UtilClass_1.JsonStore({ filepath: source });
149
+ if (typeof source == 'object' && source != null && 'save' in source &&
150
+ typeof source.save == 'function')
151
+ return source;
152
+ return new js_utils_1.ObjectStore({ data: source });
153
+ }
140
154
  }
141
155
  const key = '__jsUtils';
142
156
  const fieldList = Object.getOwnPropertyNames(js_utils_1.JsFunc).filter(k => !['length', 'prototype', 'name'].includes(k));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.285",
3
+ "version": "1.0.287",
4
4
  "description": "my utils",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {