@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 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,2 @@
1
+ export declare const fileDelete: (filePath: string) => Promise<void>;
2
+ //# sourceMappingURL=file-delete.d.ts.map
@@ -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,2 @@
1
+ export declare const fileExists: (filePath: string) => Promise<boolean>;
2
+ //# sourceMappingURL=file-exists.d.ts.map
@@ -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,10 @@
1
+ import fs from "node:fs/promises";
2
+ export const fileExists = async (filePath) => {
3
+ try {
4
+ await fs.access(filePath);
5
+ return true;
6
+ }
7
+ catch (_a) {
8
+ return false;
9
+ }
10
+ };
@@ -0,0 +1,10 @@
1
+ import fs from "node:fs/promises";
2
+ export const fileExists = async (filePath) => {
3
+ try {
4
+ await fs.access(filePath);
5
+ return true;
6
+ }
7
+ catch (_a) {
8
+ return false;
9
+ }
10
+ };
@@ -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"}
@@ -1,4 +1,6 @@
1
1
  export * from "./compress-image";
2
2
  export * from "./download-url";
3
+ export * from "./file-delete";
4
+ export * from "./file-exists";
3
5
  export * from "./format-bytes";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -1,3 +1,5 @@
1
1
  export * from "./compress-image";
2
2
  export * from "./download-url";
3
+ export * from "./file-delete";
4
+ export * from "./file-exists";
3
5
  export * from "./format-bytes";
@@ -1,3 +1,5 @@
1
1
  export * from "./compress-image";
2
2
  export * from "./download-url";
3
+ export * from "./file-delete";
4
+ export * from "./file-exists";
3
5
  export * from "./format-bytes";
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herowcode/utils",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "A lightweight collection of utility functions for everyday JavaScript/TypeScript development",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",