@herowcode/utils 1.1.4 → 1.1.5
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 +18 -0
- package/dist/files/file-delete.d.ts +2 -0
- package/dist/files/file-delete.d.ts.map +1 -0
- package/dist/files/file-delete.esm.js +12 -0
- package/dist/files/file-delete.js +12 -0
- package/dist/files/file-delete.js.map +1 -0
- package/dist/files/file-exists.d.ts +2 -0
- package/dist/files/file-exists.d.ts.map +1 -0
- package/dist/files/file-exists.esm.js +10 -0
- package/dist/files/file-exists.js +10 -0
- package/dist/files/file-exists.js.map +1 -0
- package/dist/files/index.d.ts +2 -0
- package/dist/files/index.d.ts.map +1 -1
- package/dist/files/index.esm.js +2 -0
- package/dist/files/index.js +2 -0
- package/dist/files/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -167,6 +167,24 @@ Formats a byte count as a human-readable string (e.g., "1.23 MB").
|
|
|
167
167
|
formatBytes(1234567); // "1.18 MB"
|
|
168
168
|
```
|
|
169
169
|
|
|
170
|
+
#### `fileExists(filePath: string): Promise<boolean>`
|
|
171
|
+
Checks whether a file exists on the filesystem (Node.js). Resolves to `true` when the file can be accessed, otherwise `false`.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
const exists = await fileExists('/tmp/my-file.txt');
|
|
175
|
+
if (exists) {
|
|
176
|
+
console.log('File exists');
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### `fileDelete(filePath: string): Promise<void>`
|
|
181
|
+
Deletes a file if it exists. Errors are caught and logged (useful for cleanup tasks where failures should not throw).
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
await fileDelete('/tmp/old-file.txt');
|
|
185
|
+
// If deletion fails it will be logged but will not throw.
|
|
186
|
+
```
|
|
187
|
+
|
|
170
188
|
### Function Utilities
|
|
171
189
|
|
|
172
190
|
#### `debounce<T>(fn: T, delay: number): (...args: Parameters<T>) => void`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-delete.d.ts","sourceRoot":"","sources":["../../src/files/file-delete.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU,GAAU,UAAU,MAAM,kBAOhD,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { fileExists } from "./file-exists";
|
|
3
|
+
export const fileDelete = async (filePath) => {
|
|
4
|
+
try {
|
|
5
|
+
if (await fileExists(filePath))
|
|
6
|
+
await fs.rm(filePath);
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
// Log but don't throw during cleanup
|
|
10
|
+
console.error(`Error deleting file at ${filePath}:`, err);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { fileExists } from "./file-exists";
|
|
3
|
+
export const fileDelete = async (filePath) => {
|
|
4
|
+
try {
|
|
5
|
+
if (await fileExists(filePath))
|
|
6
|
+
await fs.rm(filePath);
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
// Log but don't throw during cleanup
|
|
10
|
+
console.error(`Error deleting file at ${filePath}:`, err);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-delete.js","sourceRoot":"","sources":["../../src/files/file-delete.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAiC;AACjC,+CAA0C;AAEnC,MAAM,UAAU,GAAG,KAAK,EAAE,QAAgB,EAAE,EAAE;IACnD,IAAI,CAAC;QACH,IAAI,MAAM,IAAA,wBAAU,EAAC,QAAQ,CAAC;YAAE,MAAM,kBAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;IACvD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,qCAAqC;QACrC,OAAO,CAAC,KAAK,CAAC,0BAA0B,QAAQ,GAAG,EAAE,GAAG,CAAC,CAAA;IAC3D,CAAC;AACH,CAAC,CAAA;AAPY,QAAA,UAAU,cAOtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-exists.d.ts","sourceRoot":"","sources":["../../src/files/file-exists.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,GAAU,UAAU,MAAM,qBAOhD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-exists.js","sourceRoot":"","sources":["../../src/files/file-exists.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAiC;AAE1B,MAAM,UAAU,GAAG,KAAK,EAAE,QAAgB,EAAE,EAAE;IACnD,IAAI,CAAC;QACH,MAAM,kBAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QACzB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAPY,QAAA,UAAU,cAOtB"}
|
package/dist/files/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/files/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/files/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
package/dist/files/index.esm.js
CHANGED
package/dist/files/index.js
CHANGED
package/dist/files/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/files/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,iDAA8B;AAC9B,iDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/files/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,iDAA8B;AAC9B,gDAA6B;AAC7B,gDAA6B;AAC7B,iDAA8B"}
|
package/package.json
CHANGED