@zwa73/utils 1.0.109 → 1.0.110

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.
@@ -30,6 +30,7 @@ const UtilLogger_1 = require("./UtilLogger");
30
30
  const JSON5 = __importStar(require("json5"));
31
31
  const glob_1 = require("glob");
32
32
  const UtilFunctions_1 = require("./UtilFunctions");
33
+ const QuickFunction_1 = require("./QuickFunction");
33
34
  /**文件工具 */
34
35
  var UtilFT;
35
36
  (function (UtilFT) {
@@ -221,9 +222,11 @@ var UtilFT;
221
222
  return outArray.map((filePath) => {
222
223
  if (opt?.normalize === undefined)
223
224
  return filePath;
224
- return path[opt.normalize].normalize(filePath);
225
+ return (0, QuickFunction_1.matchProc)(opt.normalize, {
226
+ posix: (nor) => path[nor].normalize(filePath.replaceAll("\\", "/")),
227
+ win32: (nor) => path[nor].normalize(filePath.replaceAll("/", "\\")),
228
+ });
225
229
  });
226
- ;
227
230
  }
228
231
  UtilFT.fileSearchRegex = fileSearchRegex;
229
232
  /**搜索符合Glob匹配的文件
@@ -238,10 +241,14 @@ var UtilFT;
238
241
  const fixedPath = typeof globPattern === "string"
239
242
  ? path.join(dir, path.posix.normalize(globPattern))
240
243
  : globPattern.map((p) => path.join(dir, path.posix.normalize(p)));
241
- return (0, glob_1.globSync)(fixedPath, { ignore: opt?.ingore, absolute: true }).map((filePath) => {
244
+ return (0, glob_1.globSync)(fixedPath, { ignore: opt?.ingore, absolute: true })
245
+ .map((filePath) => {
242
246
  if (opt?.normalize === undefined)
243
247
  return filePath;
244
- return path[opt.normalize].normalize(filePath);
248
+ return (0, QuickFunction_1.matchProc)(opt.normalize, {
249
+ posix: (nor) => path[nor].normalize(filePath.replaceAll("\\", "/")),
250
+ win32: (nor) => path[nor].normalize(filePath.replaceAll("/", "\\")),
251
+ });
245
252
  });
246
253
  }
247
254
  UtilFT.fileSearchGlob = fileSearchGlob;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.109",
3
+ "version": "1.0.110",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,6 +5,7 @@ import { SLogger } from "@src/UtilLogger";
5
5
  import * as JSON5 from 'json5';
6
6
  import { globSync } from "glob";
7
7
  import { UtilFunc } from "./UtilFunctions";
8
+ import { matchProc } from "./QuickFunction";
8
9
 
9
10
  /**创建文件选项 */
10
11
  type CreatePathOpt = Partial<{
@@ -242,22 +243,26 @@ export async function writeJSONFile(
242
243
  export function fileSearchRegex(dir: string, traitRegex: string, opt?:FileSearchRegexOpt) {
243
244
  const relative = opt?.relative ?? true;
244
245
  const outArray: string[] = [];
245
- const subFiles = fs.readdirSync(dir,{withFileTypes:true});
246
+ const subFiles = fs.readdirSync(dir, { withFileTypes: true });
246
247
  //如果使用 g 会导致 RegExp.lastIndex 更改, 将会导致匹配错误
247
248
  const regex = new RegExp(traitRegex);
248
249
  for (const subFile of subFiles) {
249
250
  const subFilePath = path.join(dir, subFile.name);
250
251
  //判断是否是文件夹,递归调用
251
252
  if (subFile.isDirectory()) {
252
- if(relative) outArray.push(...fileSearchRegex(path.join(subFilePath, path.sep), traitRegex));
253
+ if (relative)
254
+ outArray.push(...fileSearchRegex(path.join(subFilePath, path.sep), traitRegex));
253
255
  continue;
254
256
  }
255
257
  if (regex.test(subFilePath)) outArray.push(subFilePath);
256
258
  }
257
- return outArray.map((filePath)=>{
258
- if(opt?.normalize===undefined) return filePath;
259
- return path[opt.normalize].normalize(filePath);
260
- });;
259
+ return outArray.map((filePath) => {
260
+ if (opt?.normalize === undefined) return filePath;
261
+ return matchProc(opt.normalize, {
262
+ posix: (nor) => path[nor].normalize(filePath.replaceAll("\\", "/")),
263
+ win32: (nor) => path[nor].normalize(filePath.replaceAll("/", "\\")),
264
+ });
265
+ });
261
266
  }
262
267
  /**搜索符合Glob匹配的文件
263
268
  * @param dir - 起始目录
@@ -271,9 +276,13 @@ export function fileSearchGlob(dir: string, globPattern:string|string[],opt?:Fil
271
276
  const fixedPath = typeof globPattern === "string"
272
277
  ? path.join(dir,path.posix.normalize(globPattern))
273
278
  : globPattern.map((p)=>path.join(dir,path.posix.normalize(p)));
274
- return globSync(fixedPath,{ignore:opt?.ingore,absolute:true}).map((filePath)=>{
275
- if(opt?.normalize===undefined) return filePath;
276
- return path[opt.normalize].normalize(filePath);
279
+ return globSync(fixedPath, { ignore: opt?.ingore, absolute: true })
280
+ .map((filePath) => {
281
+ if (opt?.normalize === undefined) return filePath;
282
+ return matchProc(opt.normalize, {
283
+ posix: (nor) => path[nor].normalize(filePath.replaceAll("\\", "/")),
284
+ win32: (nor) => path[nor].normalize(filePath.replaceAll("/", "\\")),
285
+ });
277
286
  });
278
287
  }
279
288
  /**