@jeniex/utils 1.2.0 → 1.3.0
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/node/index.cjs +65 -1
- package/node/index.d.ts +13 -1
- package/node/index.js +61 -3
- package/package.json +1 -1
package/node/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var fs = require('node:fs');
|
|
4
3
|
var fsp = require('node:fs/promises');
|
|
4
|
+
var fs = require('node:fs');
|
|
5
5
|
var path = require('node:path');
|
|
6
6
|
|
|
7
7
|
function noop() { }
|
|
@@ -134,6 +134,64 @@ function capitalize(sentence) {
|
|
|
134
134
|
return capitalizeWord(sentence);
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
async function exists(path) {
|
|
138
|
+
try {
|
|
139
|
+
await fsp.access(path);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function existsFile(path) {
|
|
148
|
+
try {
|
|
149
|
+
const stats = await fsp.stat(path);
|
|
150
|
+
return stats.isFile();
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function existsFileSync(path) {
|
|
158
|
+
try {
|
|
159
|
+
return fs.statSync(path).isFile();
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function existsFolder(path) {
|
|
167
|
+
try {
|
|
168
|
+
const stats = await fsp.stat(path);
|
|
169
|
+
return stats.isDirectory();
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function existsFolderSync(path) {
|
|
177
|
+
try {
|
|
178
|
+
return fs.statSync(path).isDirectory();
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function existsSync(path) {
|
|
186
|
+
try {
|
|
187
|
+
fs.accessSync(path);
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
137
195
|
/**
|
|
138
196
|
* Lists the files that are present in the provided folder path.
|
|
139
197
|
* @throws an error if the provided folder path does not exist.
|
|
@@ -317,6 +375,12 @@ function rq(url, options) {
|
|
|
317
375
|
|
|
318
376
|
exports.asserted = asserted;
|
|
319
377
|
exports.capitalize = capitalize;
|
|
378
|
+
exports.exists = exists;
|
|
379
|
+
exports.existsFile = existsFile;
|
|
380
|
+
exports.existsFileSync = existsFileSync;
|
|
381
|
+
exports.existsFolder = existsFolder;
|
|
382
|
+
exports.existsFolderSync = existsFolderSync;
|
|
383
|
+
exports.existsSync = existsSync;
|
|
320
384
|
exports.isBoolean = isBoolean;
|
|
321
385
|
exports.isFalsy = isFalsy;
|
|
322
386
|
exports.isFunction = isFunction;
|
package/node/index.d.ts
CHANGED
|
@@ -56,6 +56,18 @@ type Prettify<T> = {
|
|
|
56
56
|
[KeyType in keyof T]: T[KeyType];
|
|
57
57
|
} & {};
|
|
58
58
|
|
|
59
|
+
declare function exists(path: string): Promise<boolean>;
|
|
60
|
+
|
|
61
|
+
declare function existsFile(path: string): Promise<boolean>;
|
|
62
|
+
|
|
63
|
+
declare function existsFileSync(path: string): boolean;
|
|
64
|
+
|
|
65
|
+
declare function existsFolder(path: string): Promise<boolean>;
|
|
66
|
+
|
|
67
|
+
declare function existsFolderSync(path: string): boolean;
|
|
68
|
+
|
|
69
|
+
declare function existsSync(path: string): boolean;
|
|
70
|
+
|
|
59
71
|
interface ListBaseOpt {
|
|
60
72
|
/** The absolute path of the target folder. */
|
|
61
73
|
folderPath: string;
|
|
@@ -134,4 +146,4 @@ declare function rq(url: string, options?: RequestInit): RqRequest;
|
|
|
134
146
|
|
|
135
147
|
declare function createRequest<TOptions>(transport: Transport<TOptions>, url: string, options?: TOptions): RqRequest;
|
|
136
148
|
|
|
137
|
-
export { Fn, Nullable, Prettify, asserted, capitalize, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, listFiles, listFolders, listFoldersSync, noop, padZeros, readJSON, remove, removeFiles, rq, createRequest as rqc, sleep, stringOrThrow, toString };
|
|
149
|
+
export { Fn, Nullable, Prettify, asserted, capitalize, exists, existsFile, existsFileSync, existsFolder, existsFolderSync, existsSync, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, listFiles, listFolders, listFoldersSync, noop, padZeros, readJSON, remove, removeFiles, rq, createRequest as rqc, sleep, stringOrThrow, toString };
|
package/node/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import fsp, { access, stat } from 'node:fs/promises';
|
|
2
|
+
import fs, { statSync, accessSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
|
|
5
5
|
function noop() { }
|
|
@@ -132,6 +132,64 @@ function capitalize(sentence) {
|
|
|
132
132
|
return capitalizeWord(sentence);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
async function exists(path) {
|
|
136
|
+
try {
|
|
137
|
+
await access(path);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function existsFile(path) {
|
|
146
|
+
try {
|
|
147
|
+
const stats = await stat(path);
|
|
148
|
+
return stats.isFile();
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function existsFileSync(path) {
|
|
156
|
+
try {
|
|
157
|
+
return statSync(path).isFile();
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function existsFolder(path) {
|
|
165
|
+
try {
|
|
166
|
+
const stats = await stat(path);
|
|
167
|
+
return stats.isDirectory();
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function existsFolderSync(path) {
|
|
175
|
+
try {
|
|
176
|
+
return statSync(path).isDirectory();
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function existsSync(path) {
|
|
184
|
+
try {
|
|
185
|
+
accessSync(path);
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
135
193
|
/**
|
|
136
194
|
* Lists the files that are present in the provided folder path.
|
|
137
195
|
* @throws an error if the provided folder path does not exist.
|
|
@@ -313,4 +371,4 @@ function rq(url, options) {
|
|
|
313
371
|
return createRequest(fetchTransport, url, options);
|
|
314
372
|
}
|
|
315
373
|
|
|
316
|
-
export { asserted, capitalize, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, listFiles, listFolders, listFoldersSync, noop, padZeros, readJSON, remove, removeFiles, rq, createRequest as rqc, sleep, stringOrThrow, toString };
|
|
374
|
+
export { asserted, capitalize, exists, existsFile, existsFileSync, existsFolder, existsFolderSync, existsSync, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, listFiles, listFolders, listFoldersSync, noop, padZeros, readJSON, remove, removeFiles, rq, createRequest as rqc, sleep, stringOrThrow, toString };
|