@stryke/fs 0.5.0 → 0.6.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.
@@ -7,10 +7,12 @@ exports.createDirectory = createDirectory;
7
7
  exports.createDirectorySync = createDirectorySync;
8
8
  exports.extractFileFromTar = extractFileFromTar;
9
9
  exports.extractFileFromTarGzip = extractFileFromTarGzip;
10
- var _nodeFs = require("node:fs");
11
- var _promises = require("node:fs/promises");
10
+ exports.removeDirectory = removeDirectory;
11
+ exports.removeDirectorySync = removeDirectorySync;
12
12
  var _exists = require("@stryke/path/utilities/exists");
13
13
  var _nanotar = require("nanotar");
14
+ var _nodeFs = require("node:fs");
15
+ var _promises = require("node:fs/promises");
14
16
  function createDirectorySync(r) {
15
17
  if (!(0, _exists.existsSync)(r)) return (0, _nodeFs.mkdirSync)(r, {
16
18
  recursive: !0
@@ -21,15 +23,25 @@ async function createDirectory(r) {
21
23
  recursive: !0
22
24
  });
23
25
  }
26
+ function removeDirectorySync(r) {
27
+ if ((0, _exists.existsSync)(r)) return (0, _nodeFs.rmSync)(r, {
28
+ recursive: !0
29
+ });
30
+ }
31
+ async function removeDirectory(r) {
32
+ if ((0, _exists.existsSync)(r)) return (0, _promises.rm)(r, {
33
+ recursive: !0
34
+ });
35
+ }
24
36
  async function extractFileFromTar(r, i, t) {
25
- const e = (0, _nanotar.parseTar)(await (0, _promises.readFile)(r)).find(a => a.name === i);
37
+ const e = (0, _nanotar.parseTar)(await (0, _promises.readFile)(r)).find(n => n.name === i);
26
38
  if (!e?.data) return;
27
39
  (await (0, _exists.exists)(t)) || (await (0, _promises.mkdir)(t, {
28
40
  recursive: !0
29
41
  })), (0, _nodeFs.createWriteStream)(t).write(e.data);
30
42
  }
31
43
  async function extractFileFromTarGzip(r, i, t) {
32
- const e = (await (0, _nanotar.parseTarGzip)(await (0, _promises.readFile)(r))).find(a => a.name === i);
44
+ const e = (await (0, _nanotar.parseTarGzip)(await (0, _promises.readFile)(r))).find(n => n.name === i);
33
45
  if (!e?.data) return;
34
46
  (await (0, _exists.exists)(t)) || (await (0, _promises.mkdir)(t, {
35
47
  recursive: !0
@@ -1,17 +1,31 @@
1
1
  /**
2
2
  * Create a directory if it does not exist.
3
3
  *
4
- * @param filePath - The directory path to check
4
+ * @param path - The directory path to check
5
5
  * @returns An indicator specifying if the directory exists
6
6
  */
7
7
  export declare function createDirectorySync(path: string): string | undefined;
8
8
  /**
9
9
  * Create a directory if it does not exist.
10
10
  *
11
- * @param filePath - The directory path to check
11
+ * @param path - The directory path to check
12
12
  * @returns An indicator specifying if the directory exists
13
13
  */
14
14
  export declare function createDirectory(path: string): Promise<string | undefined>;
15
+ /**
16
+ * Remove a directory if it exists.
17
+ *
18
+ * @param path - The directory path to check
19
+ * @returns An indicator specifying if the directory exists
20
+ */
21
+ export declare function removeDirectorySync(path: string): void;
22
+ /**
23
+ * Remove a directory if it exists.
24
+ *
25
+ * @param path - The directory path to check
26
+ * @returns An indicator specifying if the directory exists
27
+ */
28
+ export declare function removeDirectory(path: string): Promise<void>;
15
29
  /**
16
30
  * Extracts a file from a given tarball to the specified destination.
17
31
  *
@@ -1 +1 @@
1
- import{createWriteStream as c,mkdirSync as f}from"node:fs";import{mkdir as n,readFile as o}from"node:fs/promises";import{exists as s,existsSync as p}from"@stryke/path/utilities/exists";import{parseTar as w,parseTarGzip as y}from"nanotar";export function createDirectorySync(r){if(!p(r))return f(r,{recursive:!0})}export async function createDirectory(r){if(!await s(r))return n(r,{recursive:!0})}export async function extractFileFromTar(r,i,t){const e=w(await o(r)).find(a=>a.name===i);if(!e?.data)return;await s(t)||await n(t,{recursive:!0}),c(t).write(e.data)}export async function extractFileFromTarGzip(r,i,t){const e=(await y(await o(r))).find(a=>a.name===i);if(!e?.data)return;await s(t)||await n(t,{recursive:!0}),c(t).write(e.data)}
1
+ import{exists as c,existsSync as s}from"@stryke/path/utilities/exists";import{parseTar as y,parseTarGzip as g}from"nanotar";import{createWriteStream as u,mkdirSync as p,rmSync as w}from"node:fs";import{mkdir as a,readFile as o,rm as x}from"node:fs/promises";export function createDirectorySync(r){if(!s(r))return p(r,{recursive:!0})}export async function createDirectory(r){if(!await c(r))return a(r,{recursive:!0})}export function removeDirectorySync(r){if(s(r))return w(r,{recursive:!0})}export async function removeDirectory(r){if(s(r))return x(r,{recursive:!0})}export async function extractFileFromTar(r,i,t){const e=y(await o(r)).find(n=>n.name===i);if(!e?.data)return;await c(t)||await a(t,{recursive:!0}),u(t).write(e.data)}export async function extractFileFromTarGzip(r,i,t){const e=(await g(await o(r))).find(n=>n.name===i);if(!e?.data)return;await c(t)||await a(t,{recursive:!0}),u(t).write(e.data)}
@@ -10,7 +10,7 @@ const removeFileSync = r => {
10
10
  if (!r || !(0, _nodeFs.existsSync)(r)) throw new Error("Invalid file path provided to remove data");
11
11
  (0, _nodeFs.rmSync)(r);
12
12
  },
13
- removeFile = r => {
13
+ removeFile = async r => {
14
14
  if (!r || !(0, _nodeFs.existsSync)(r)) throw new Error("Invalid file path provided to remove data");
15
15
  return (0, _promises.rm)(r);
16
16
  };
@@ -1 +1 @@
1
- import{existsSync as o,rmSync as e}from"node:fs";import{rm as i}from"node:fs/promises";export const removeFileSync=r=>{if(!r||!o(r))throw new Error("Invalid file path provided to remove data");e(r)},removeFile=r=>{if(!r||!o(r))throw new Error("Invalid file path provided to remove data");return i(r)};
1
+ import{existsSync as o,rmSync as e}from"node:fs";import{rm as i}from"node:fs/promises";export const removeFileSync=r=>{if(!r||!o(r))throw new Error("Invalid file path provided to remove data");e(r)},removeFile=async r=>{if(!r||!o(r))throw new Error("Invalid file path provided to remove data");return i(r)};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various file system utilities that expand the functionality of NodeJs's `fs` module.",
6
6
  "repository": {
@@ -17,9 +17,9 @@
17
17
  "chalk": "^5.4.1",
18
18
  "nanotar": "^0.2.0",
19
19
  "semver": "7.7.1",
20
- "@stryke/json": ">=0.4.1",
21
- "@stryke/path": ">=0.3.0",
22
- "@stryke/types": ">=0.5.0"
20
+ "@stryke/json": ">=0.4.2",
21
+ "@stryke/path": ">=0.3.1",
22
+ "@stryke/types": ">=0.5.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^22.13.1",