@yamato-daiwa/es-extensions-nodejs 1.8.7 → 1.9.0-alpha.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.
@@ -1,42 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
- const fs_1 = __importStar(require("fs"));
6
+ const fs_1 = __importDefault(require("fs"));
40
7
  const promises_1 = __importDefault(require("fs/promises"));
41
8
  const path_1 = __importDefault(require("path"));
42
9
  const ImprovedPath_1 = __importDefault(require("./ImprovedPath/ImprovedPath"));
@@ -47,8 +14,15 @@ class ImprovedFileSystem {
47
14
  if (synchronously) {
48
15
  return fs_1.default.existsSync(targetPath);
49
16
  }
50
- return new Promise((resolve) => {
51
- fs_1.default.access(targetPath, fs_1.constants.F_OK, (error) => { resolve((0, es_extensions_1.isNull)(error)); });
17
+ return new Promise((resolve, reject) => {
18
+ promises_1.default.access(targetPath).
19
+ then(() => { resolve(true); }).
20
+ catch((error) => {
21
+ if ((0, isErrnoException_1.default)(error) && error.code === "ENOENT") {
22
+ resolve(false);
23
+ }
24
+ reject(error);
25
+ });
52
26
  });
53
27
  }
54
28
  static createDirectory({ targetPath, mustThrowErrorIfTargetDirectoryExists, synchronously }) {
@@ -15,12 +15,18 @@ export default class ImprovedGlob {
15
15
  basicDirectoryPath: string;
16
16
  fileNamesExtensions?: ReadonlyArray<string> | ReadonlySet<string>;
17
17
  }): string;
18
- static buildAllFilesInCurrentDirectoryAndBelowGlobSelector(compoundParameter: Readonly<{
18
+ static buildAllFilesInCurrentDirectoryAndBelowGlobSelector(polymorphicParameter: string | Readonly<{
19
19
  basicDirectoryPath: string;
20
- fileNamePostfixes?: ReadonlyArray<string> | ReadonlySet<string>;
20
+ fileNamesPostfixes?: ReadonlyArray<string> | ReadonlySet<string>;
21
21
  fileNamesExtensions?: ReadonlyArray<string> | ReadonlySet<string>;
22
+ penultimateFileNamesExtensions?: ReadonlyArray<string> | ReadonlySet<string>;
23
+ }>): string;
24
+ static buildExcludingOfDirectoryWithSubdirectoriesGlobSelector(polymorphicParameter: string | Readonly<{
25
+ targetDirectoryPath: string;
26
+ fileNamesPostfixes?: ReadonlyArray<string> | ReadonlySet<string>;
27
+ fileNamesExtensions?: ReadonlyArray<string> | ReadonlySet<string>;
28
+ penultimateFileNamesExtensions?: ReadonlyArray<string> | ReadonlySet<string>;
22
29
  }>): string;
23
- static buildExcludingOfDirectoryWithSubdirectoriesGlobSelector(targetDirectoryPath: string): string;
24
30
  static buildExcludingOfFilesWithSpecificPrefixesGlobSelector(compoundParameter: Readonly<{
25
31
  basicDirectoryPath: string;
26
32
  filesNamesPrefixes: ReadonlyArray<string> | ReadonlySet<string>;
@@ -64,48 +64,72 @@ class ImprovedGlob {
64
64
  [ImprovedGlob.createMultipleFilenameExtensionsGlobPostfix(fileNamesExtensions)] : []
65
65
  ].join("");
66
66
  }
67
- static buildAllFilesInCurrentDirectoryAndBelowGlobSelector(compoundParameter) {
68
- let fileNamePostfixes;
69
- if ((0, es_extensions_1.isUndefined)(compoundParameter.fileNamePostfixes)) {
70
- fileNamePostfixes = new Set();
71
- }
72
- else if (compoundParameter.fileNamePostfixes instanceof Set) {
73
- fileNamePostfixes = compoundParameter.fileNamePostfixes;
67
+ static buildAllFilesInCurrentDirectoryAndBelowGlobSelector(polymorphicParameter) {
68
+ let basicDirectoryPath;
69
+ let fileNamesPostfixes = new Set();
70
+ let fileNamesExtensions = new Set();
71
+ let penultimateFileNamesExtensions = new Set();
72
+ if ((0, es_extensions_1.isString)(polymorphicParameter)) {
73
+ basicDirectoryPath = polymorphicParameter;
74
74
  }
75
75
  else {
76
- fileNamePostfixes = new Set(compoundParameter.fileNamePostfixes);
77
- }
78
- let fileNamesExtensions;
79
- if ((0, es_extensions_1.isUndefined)(compoundParameter.fileNamesExtensions)) {
80
- fileNamesExtensions = new Set();
81
- }
82
- else if (compoundParameter.fileNamesExtensions instanceof Set) {
83
- fileNamesExtensions = compoundParameter.fileNamesExtensions;
84
- }
85
- else {
86
- fileNamesExtensions = new Set(compoundParameter.fileNamesExtensions);
76
+ basicDirectoryPath = polymorphicParameter.basicDirectoryPath;
77
+ if (polymorphicParameter.fileNamesPostfixes instanceof Set) {
78
+ fileNamesPostfixes = polymorphicParameter.fileNamesPostfixes;
79
+ }
80
+ else if (Array.isArray(polymorphicParameter.fileNamesPostfixes)) {
81
+ fileNamesPostfixes = new Set(polymorphicParameter.fileNamesPostfixes);
82
+ }
83
+ if (polymorphicParameter.fileNamesExtensions instanceof Set) {
84
+ fileNamesExtensions = polymorphicParameter.fileNamesExtensions;
85
+ }
86
+ else if (Array.isArray(polymorphicParameter.fileNamesExtensions)) {
87
+ fileNamesExtensions = new Set(polymorphicParameter.fileNamesExtensions);
88
+ }
89
+ if (polymorphicParameter.penultimateFileNamesExtensions instanceof Set) {
90
+ penultimateFileNamesExtensions = polymorphicParameter.penultimateFileNamesExtensions;
91
+ }
92
+ else if (Array.isArray(polymorphicParameter.penultimateFileNamesExtensions)) {
93
+ penultimateFileNamesExtensions = new Set(polymorphicParameter.penultimateFileNamesExtensions);
94
+ }
87
95
  }
88
96
  return [
89
97
  (0, appendCharacterIfItDoesNotPresentInLastPosition_1.default)({
90
- targetString: (0, es_extensions_1.replaceDoubleBackslashesWithForwardSlashes)(compoundParameter.basicDirectoryPath),
98
+ targetString: (0, es_extensions_1.replaceDoubleBackslashesWithForwardSlashes)(basicDirectoryPath),
91
99
  trailingCharacter: "/"
92
100
  }),
93
101
  "**/*",
94
- ...fileNamePostfixes.size > 0 ?
95
- [`@(${Array.from(fileNamePostfixes).join("|").replace(/\./gu, "")})`] : [],
102
+ ...fileNamesPostfixes.size > 0 ?
103
+ [
104
+ `@(${Array.from(fileNamesPostfixes).
105
+ join("|").
106
+ replace(/\./gu, "")})`
107
+ ] :
108
+ [],
109
+ ...penultimateFileNamesExtensions.size > 0 ?
110
+ [
111
+ `.@(${Array.from(penultimateFileNamesExtensions).
112
+ map((penultimateFilenameExtension) => (0, es_extensions_1.removeSpecificCharacterFromCertainPosition)({
113
+ targetString: penultimateFilenameExtension,
114
+ targetCharacter: ".",
115
+ fromFirstPosition: true
116
+ })).
117
+ join("|")})`
118
+ ] :
119
+ [],
96
120
  ...fileNamesExtensions.size > 0 ?
97
121
  [ImprovedGlob.createMultipleFilenameExtensionsGlobPostfix(fileNamesExtensions)] : []
98
122
  ].join("");
99
123
  }
100
- static buildExcludingOfDirectoryWithSubdirectoriesGlobSelector(targetDirectoryPath) {
101
- return [
102
- "!",
103
- (0, appendCharacterIfItDoesNotPresentInLastPosition_1.default)({
104
- targetString: (0, es_extensions_1.replaceDoubleBackslashesWithForwardSlashes)(targetDirectoryPath),
105
- trailingCharacter: "/"
106
- }),
107
- "**/*"
108
- ].join("");
124
+ static buildExcludingOfDirectoryWithSubdirectoriesGlobSelector(polymorphicParameter) {
125
+ if ((0, es_extensions_1.isString)(polymorphicParameter)) {
126
+ return ImprovedGlob.includingGlobSelectorToExcludingOne(ImprovedGlob.buildAllFilesInCurrentDirectoryAndBelowGlobSelector(polymorphicParameter));
127
+ }
128
+ const { targetDirectoryPath, ...options } = polymorphicParameter;
129
+ return ImprovedGlob.includingGlobSelectorToExcludingOne(ImprovedGlob.buildAllFilesInCurrentDirectoryAndBelowGlobSelector({
130
+ basicDirectoryPath: targetDirectoryPath,
131
+ ...options
132
+ }));
109
133
  }
110
134
  static buildExcludingOfFilesWithSpecificPrefixesGlobSelector(compoundParameter) {
111
135
  const filesNamesPrefixes = compoundParameter.filesNamesPrefixes instanceof Set ?
@@ -218,7 +242,9 @@ class ImprovedGlob {
218
242
  ].join("");
219
243
  }
220
244
  static createMultipleFilenameExtensionsGlobPostfix(fileNamesExtensions) {
221
- return `.@(${(Array.isArray(fileNamesExtensions) ? fileNamesExtensions : Array.from(fileNamesExtensions)).join("|").replace(/\./gu, "")})`;
245
+ return `.@(${(Array.isArray(fileNamesExtensions) ?
246
+ fileNamesExtensions :
247
+ Array.from(fileNamesExtensions)).join("|").replace(/\./gu, "")})`;
222
248
  }
223
249
  static buildAbsolutePathBasedGlob(compoundParameter) {
224
250
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamato-daiwa/es-extensions-nodejs",
3
- "version": "1.8.7",
3
+ "version": "1.9.0-alpha.1",
4
4
  "description": "Additional to @yamato-daiwa/es-extensions functionality for Node.js environment. Helper functions and classes aimed to reduce the routine code. Build-in TypeScript type safety.",
5
5
  "keywords": [
6
6
  "nodejs",
@@ -32,7 +32,7 @@
32
32
  "node": ">=20.0.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "@yamato-daiwa/es-extensions": "1.8.7"
35
+ "@yamato-daiwa/es-extensions": "1.9.0-alpha.1"
36
36
  },
37
37
  "dependencies": {
38
38
  "dotenv": "17.3.1",
@@ -45,7 +45,7 @@
45
45
  "@types/json5": "0.0.30",
46
46
  "@types/node": "22.15.31",
47
47
  "@types/yamljs": "0.2.34",
48
- "@yamato-daiwa/es-extensions": "1.8.7",
48
+ "@yamato-daiwa/es-extensions": "1.9.0-alpha.1",
49
49
  "@yamato-daiwa/style_guides": "0.11.6",
50
50
  "rimraf": "6.1.3",
51
51
  "tsx": "4.21.0",