@reliverse/relifso 1.2.4 → 1.2.6

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,2 +1,7 @@
1
- export declare function mkdirsSync(dir: string): string | undefined;
2
- export declare function mkdirs(dir: string): Promise<string | undefined>;
1
+ interface MakeDirectoryOptions {
2
+ recursive?: boolean;
3
+ mode?: number | string;
4
+ }
5
+ export declare function mkdirsSync(dir: string, options?: MakeDirectoryOptions): string | undefined;
6
+ export declare function mkdirs(dir: string, options?: MakeDirectoryOptions): Promise<string | undefined>;
7
+ export {};
@@ -1,19 +1,21 @@
1
1
  import { mkdirSync, existsSync } from "node:fs";
2
2
  import { mkdir, stat } from "node:fs/promises";
3
- export function mkdirsSync(dir) {
3
+ export function mkdirsSync(dir, options) {
4
4
  if (existsSync(dir)) {
5
5
  return;
6
6
  }
7
- return mkdirSync(dir, { recursive: true });
7
+ return mkdirSync(dir, { recursive: true, mode: options?.mode });
8
8
  }
9
- export async function mkdirs(dir) {
9
+ export async function mkdirs(dir, options) {
10
10
  try {
11
- await stat(dir);
12
- return void 0;
11
+ const dirStat = await stat(dir);
12
+ if (dirStat.isDirectory()) {
13
+ return void 0;
14
+ }
13
15
  } catch (error) {
14
- if (error.code === "ENOENT") {
15
- return mkdir(dir, { recursive: true });
16
+ if (error.code !== "ENOENT") {
17
+ throw error;
16
18
  }
17
- throw error;
18
19
  }
20
+ return mkdir(dir, { recursive: true, mode: options?.mode });
19
21
  }
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @param file - The path to the file.
5
5
  * @param data - The JSON data to write.
6
- * @param options - Options for writing the JSON file (e.g., replacer, space).
6
+ * @param options - Options for writing the JSON file (e.g., replacer, spaces).
7
7
  */
8
8
  export declare function outputJsonSync(file: string, data: unknown, options?: unknown): void;
9
9
  /**
@@ -11,6 +11,6 @@ export declare function outputJsonSync(file: string, data: unknown, options?: un
11
11
  *
12
12
  * @param file - The path to the file.
13
13
  * @param data - The JSON data to write.
14
- * @param options - Options for writing the JSON file (e.g., replacer, space).
14
+ * @param options - Options for writing the JSON file (e.g., replacer, spaces).
15
15
  */
16
16
  export declare function outputJson(file: string, data: unknown, options?: unknown): Promise<void>;
@@ -1,14 +1,14 @@
1
1
  import type { Mode, OpenMode } from "node:fs";
2
2
  export interface JsonStringifyOptions {
3
3
  replacer?: (key: string, value: unknown) => unknown | (number | string)[] | null;
4
- space?: string | number;
4
+ spaces?: string | number;
5
5
  }
6
6
  export interface WriteJsonOptions {
7
7
  encoding?: BufferEncoding | null;
8
8
  mode?: Mode;
9
9
  flag?: OpenMode;
10
10
  replacer?: (key: string, value: unknown) => unknown | (number | string)[] | null;
11
- space?: string | number;
11
+ spaces?: string | number;
12
12
  }
13
13
  /**
14
14
  * Synchronously writes an object to a JSON file.
@@ -2,21 +2,21 @@ import { writeFileSync } from "./write-file.js";
2
2
  import { writeFile } from "./write-file.js";
3
3
  export function writeJsonSync(file, object, options = {}) {
4
4
  const replacer = options.replacer === void 0 ? null : options.replacer;
5
- const space = options.space === void 0 ? 2 : options.space;
5
+ const spaces = options.spaces === void 0 ? 2 : options.spaces;
6
6
  const fileWriteOpts = {};
7
7
  if (options.encoding !== void 0) fileWriteOpts.encoding = options.encoding;
8
8
  if (options.mode !== void 0) fileWriteOpts.mode = options.mode;
9
9
  if (options.flag !== void 0) fileWriteOpts.flag = options.flag.toString();
10
- const str = JSON.stringify(object, replacer, space);
10
+ const str = JSON.stringify(object, replacer, spaces);
11
11
  writeFileSync(file, str, fileWriteOpts);
12
12
  }
13
13
  export async function writeJson(file, object, options = {}) {
14
14
  const replacer = options.replacer === void 0 ? null : options.replacer;
15
- const space = options.space === void 0 ? 2 : options.space;
15
+ const spaces = options.spaces === void 0 ? 2 : options.spaces;
16
16
  const fileWriteOpts = {};
17
17
  if (options.encoding !== void 0) fileWriteOpts.encoding = options.encoding;
18
18
  if (options.mode !== void 0) fileWriteOpts.mode = options.mode;
19
19
  if (options.flag !== void 0) fileWriteOpts.flag = options.flag.toString();
20
- const str = JSON.stringify(object, replacer, space);
20
+ const str = JSON.stringify(object, replacer, spaces);
21
21
  await writeFile(file, str, fileWriteOpts);
22
22
  }
package/bin/mod.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Stats } from "node:fs";
2
- import { accessSync, constants, readdirSync, statSync } from "node:fs";
3
- import { readdir as nodeReaddirInternal, stat as nodeStatInternal, readdir, stat, access } from "node:fs/promises";
2
+ import { accessSync, constants, readdirSync, statSync, copyFileSync } from "node:fs";
3
+ import { readdir as nodeReaddirInternal, stat as nodeStatInternal, readdir, stat, access, copyFile } from "node:fs/promises";
4
4
  import type { DiveOptions } from "./impl/dive.js";
5
5
  import { copy, copySync } from "./impl/copy.js";
6
6
  import { createFile, createFileSync } from "./impl/create-file.js";
@@ -34,13 +34,19 @@ declare const unlink: typeof remove;
34
34
  declare const unlinkSync: typeof removeSync;
35
35
  declare const rename: typeof move;
36
36
  declare const renameSync: typeof moveSync;
37
+ declare const readJSON: typeof readJson;
38
+ declare const readJSONSync: typeof readJsonSync;
39
+ declare const writeJSON: typeof writeJson;
40
+ declare const writeJSONSync: typeof writeJsonSync;
41
+ declare const outputJSON: typeof outputJson;
42
+ declare const outputJSONSync: typeof outputJsonSync;
37
43
  export type { CopyOptions } from "./impl/copy.js";
38
44
  export type { MoveOptions } from "./impl/move.js";
39
45
  export type { ReadFileOptions } from "./impl/read-file.js";
40
46
  export type { ReadJsonOptions } from "./impl/read-json.js";
41
47
  export type { JsonStringifyOptions } from "./impl/write-json.js";
42
48
  export type { WriteJsonOptions } from "./impl/write-json.js";
43
- export { readJson, writeJson, createFile, writeFile, readFile, mkdirs, emptyDir, pathExists, copy, move, remove, readdir, stat, access, readJsonSync, writeJsonSync, createFileSync, writeFileSync, readFileSync, mkdirsSync, emptyDirSync, pathExistsSync, copySync, moveSync, removeSync, readdirSync, statSync, accessSync, constants, mkdirp, mkdirpSync, rimraf, rimrafSync, ncp, ncpSync, ensureDir, ensureDirSync, ensureFile, ensureFileSync, outputJson, outputJsonSync, outputFile, outputFileSync, diveSync, mkdir, mkdirSync, unlink, unlinkSync, rename, renameSync, };
49
+ export { readJson, writeJson, createFile, writeFile, readFile, mkdirs, emptyDir, pathExists, copy, move, remove, readdir, stat, access, copyFile, readJsonSync, writeJsonSync, createFileSync, writeFileSync, readFileSync, mkdirsSync, emptyDirSync, pathExistsSync, copySync, moveSync, removeSync, readdirSync, statSync, accessSync, constants, copyFileSync, mkdirp, mkdirpSync, rimraf, rimrafSync, ncp, ncpSync, ensureDir, ensureDirSync, ensureFile, ensureFileSync, outputJson, outputJsonSync, outputFile, outputFileSync, diveSync, mkdir, mkdirSync, unlink, unlinkSync, rename, renameSync, readJSON, readJSONSync, writeJSON, writeJSONSync, outputJSON, outputJSONSync, };
44
50
  declare const fs: {
45
51
  readJson: typeof readJson;
46
52
  writeJson: typeof writeJson;
@@ -56,6 +62,7 @@ declare const fs: {
56
62
  readdir: typeof nodeReaddirInternal;
57
63
  stat: typeof nodeStatInternal;
58
64
  access: typeof access;
65
+ copyFile: typeof copyFile;
59
66
  readJsonSync: typeof readJsonSync;
60
67
  writeJsonSync: typeof writeJsonSync;
61
68
  createFileSync: typeof createFileSync;
@@ -71,6 +78,7 @@ declare const fs: {
71
78
  statSync: import("fs").StatSyncFn;
72
79
  accessSync: typeof accessSync;
73
80
  constants: typeof constants;
81
+ copyFileSync: typeof copyFileSync;
74
82
  mkdirp: typeof mkdirs;
75
83
  mkdirpSync: typeof mkdirsSync;
76
84
  rimraf: typeof remove;
@@ -93,5 +101,11 @@ declare const fs: {
93
101
  unlinkSync: typeof removeSync;
94
102
  rename: typeof move;
95
103
  renameSync: typeof moveSync;
104
+ readJSON: typeof readJson;
105
+ readJSONSync: typeof readJsonSync;
106
+ writeJSON: typeof writeJson;
107
+ writeJSONSync: typeof writeJsonSync;
108
+ outputJSON: typeof outputJson;
109
+ outputJSONSync: typeof outputJsonSync;
96
110
  };
97
111
  export default fs;
package/bin/mod.js CHANGED
@@ -1,5 +1,12 @@
1
- import { accessSync, constants, readdirSync, statSync } from "node:fs";
2
- import { readdir as nodeReaddirInternal, stat as nodeStatInternal, readdir, stat, access } from "node:fs/promises";
1
+ import { accessSync, constants, readdirSync, statSync, copyFileSync } from "node:fs";
2
+ import {
3
+ readdir as nodeReaddirInternal,
4
+ stat as nodeStatInternal,
5
+ readdir,
6
+ stat,
7
+ access,
8
+ copyFile
9
+ } from "node:fs/promises";
3
10
  import { join as pathJoin } from "node:path";
4
11
  import { copy, copySync } from "./impl/copy.js";
5
12
  import { createFile, createFileSync } from "./impl/create-file.js";
@@ -108,6 +115,12 @@ const unlink = remove;
108
115
  const unlinkSync = removeSync;
109
116
  const rename = move;
110
117
  const renameSync = moveSync;
118
+ const readJSON = readJson;
119
+ const readJSONSync = readJsonSync;
120
+ const writeJSON = writeJson;
121
+ const writeJSONSync = writeJsonSync;
122
+ const outputJSON = outputJson;
123
+ const outputJSONSync = outputJsonSync;
111
124
  export {
112
125
  readJson,
113
126
  writeJson,
@@ -123,6 +136,7 @@ export {
123
136
  readdir,
124
137
  stat,
125
138
  access,
139
+ copyFile,
126
140
  readJsonSync,
127
141
  writeJsonSync,
128
142
  createFileSync,
@@ -138,6 +152,7 @@ export {
138
152
  statSync,
139
153
  accessSync,
140
154
  constants,
155
+ copyFileSync,
141
156
  mkdirp,
142
157
  mkdirpSync,
143
158
  rimraf,
@@ -158,7 +173,13 @@ export {
158
173
  unlink,
159
174
  unlinkSync,
160
175
  rename,
161
- renameSync
176
+ renameSync,
177
+ readJSON,
178
+ readJSONSync,
179
+ writeJSON,
180
+ writeJSONSync,
181
+ outputJSON,
182
+ outputJSONSync
162
183
  };
163
184
  const fs = {
164
185
  // async methods
@@ -176,6 +197,7 @@ const fs = {
176
197
  readdir,
177
198
  stat,
178
199
  access,
200
+ copyFile,
179
201
  // sync methods
180
202
  readJsonSync,
181
203
  writeJsonSync,
@@ -192,6 +214,7 @@ const fs = {
192
214
  statSync,
193
215
  accessSync,
194
216
  constants,
217
+ copyFileSync,
195
218
  // alias
196
219
  mkdirp,
197
220
  mkdirpSync,
@@ -214,6 +237,13 @@ const fs = {
214
237
  unlink,
215
238
  unlinkSync,
216
239
  rename,
217
- renameSync
240
+ renameSync,
241
+ // ADDED JSON Aliases
242
+ readJSON,
243
+ readJSONSync,
244
+ writeJSON,
245
+ writeJSONSync,
246
+ outputJSON,
247
+ outputJSONSync
218
248
  };
219
249
  export default fs;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "license": "MIT",
6
6
  "name": "@reliverse/relifso",
7
7
  "type": "module",
8
- "version": "1.2.4",
8
+ "version": "1.2.6",
9
9
  "keywords": [
10
10
  "fs",
11
11
  "file",