@reliverse/relifso 1.3.1 → 1.4.1
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/LICENSES +16 -0
- package/README.md +106 -20
- package/bin/impl/bun.d.ts +11 -0
- package/bin/impl/bun.js +23 -0
- package/bin/impl/{node/copy.d.ts → copy.d.ts} +15 -3
- package/bin/impl/copy.js +229 -0
- package/bin/impl/create.d.ts +34 -0
- package/bin/impl/create.js +54 -0
- package/bin/impl/{node/dive.d.ts → dive.d.ts} +10 -0
- package/bin/impl/dive.js +145 -0
- package/bin/impl/empty.d.ts +28 -0
- package/bin/impl/empty.js +75 -0
- package/bin/impl/extras.d.ts +35 -0
- package/bin/impl/extras.js +112 -0
- package/bin/impl/json-utils.d.ts +30 -0
- package/bin/impl/json-utils.js +46 -0
- package/bin/impl/{node/mkdirs.js → mkdirs.js} +10 -3
- package/bin/impl/{node/move.d.ts → move.d.ts} +10 -0
- package/bin/impl/move.js +140 -0
- package/bin/impl/{node/output-file.d.ts → output-file.d.ts} +3 -2
- package/bin/impl/{node/output-json.d.ts → output-json.d.ts} +7 -2
- package/bin/impl/output-json.js +77 -0
- package/bin/impl/read-file.d.ts +31 -0
- package/bin/impl/read-file.js +165 -0
- package/bin/impl/{node/read-json.d.ts → read-json.d.ts} +9 -0
- package/bin/impl/read-json.js +241 -0
- package/bin/impl/stats.d.ts +31 -0
- package/bin/impl/stats.js +141 -0
- package/bin/impl/write-file.d.ts +31 -0
- package/bin/impl/write-file.js +257 -0
- package/bin/impl/write-json.d.ts +41 -0
- package/bin/impl/write-json.js +135 -0
- package/bin/mod.d.ts +89 -57
- package/bin/mod.js +131 -164
- package/bin/utils/json/helpers/JSONRepairError.d.ts +4 -0
- package/bin/utils/json/helpers/JSONRepairError.js +7 -0
- package/bin/utils/json/helpers/JsonSchemaError.d.ts +6 -0
- package/bin/utils/json/helpers/JsonSchemaError.js +6 -0
- package/bin/utils/json/helpers/stringUtils.d.ts +64 -0
- package/bin/utils/json/helpers/stringUtils.js +87 -0
- package/bin/utils/json/regular/jsonc.d.ts +45 -0
- package/bin/utils/json/regular/jsonc.js +88 -0
- package/bin/utils/json/regular/jsonrepair.d.ts +17 -0
- package/bin/utils/json/regular/jsonrepair.js +576 -0
- package/bin/utils/json/regular/validate.d.ts +22 -0
- package/bin/utils/json/regular/validate.js +52 -0
- package/bin/utils/json/stream/JsonStreamError.d.ts +6 -0
- package/bin/utils/json/stream/JsonStreamError.js +6 -0
- package/bin/utils/json/stream/buffer/InputBuffer.d.ts +13 -0
- package/bin/utils/json/stream/buffer/InputBuffer.js +68 -0
- package/bin/utils/json/stream/buffer/OutputBuffer.d.ts +17 -0
- package/bin/utils/json/stream/buffer/OutputBuffer.js +101 -0
- package/bin/utils/json/stream/core.d.ts +10 -0
- package/bin/utils/json/stream/core.js +695 -0
- package/bin/utils/json/stream/jsonl.d.ts +21 -0
- package/bin/utils/json/stream/jsonl.js +55 -0
- package/bin/utils/json/stream/parser.d.ts +14 -0
- package/bin/utils/json/stream/parser.js +81 -0
- package/bin/utils/json/stream/stack.d.ts +19 -0
- package/bin/utils/json/stream/stack.js +43 -0
- package/bin/utils/json/stream/stream.d.ts +6 -0
- package/bin/utils/json/stream/stream.js +30 -0
- package/bin/utils/json/stream/writer.d.ts +14 -0
- package/bin/utils/json/stream/writer.js +44 -0
- package/bin/utils/log.d.ts +1 -0
- package/bin/utils/log.js +7 -0
- package/package.json +4 -3
- package/bin/impl/node/copy.js +0 -94
- package/bin/impl/node/create-file.d.ts +0 -2
- package/bin/impl/node/create-file.js +0 -21
- package/bin/impl/node/dive.js +0 -56
- package/bin/impl/node/empty-dir.d.ts +0 -2
- package/bin/impl/node/empty-dir.js +0 -24
- package/bin/impl/node/move.js +0 -93
- package/bin/impl/node/output-json.js +0 -15
- package/bin/impl/node/read-file.d.ts +0 -30
- package/bin/impl/node/read-file.js +0 -30
- package/bin/impl/node/read-json.js +0 -50
- package/bin/impl/node/write-file.d.ts +0 -20
- package/bin/impl/node/write-file.js +0 -23
- package/bin/impl/node/write-json.d.ts +0 -28
- package/bin/impl/node/write-json.js +0 -22
- package/bin/impl/utils/additional.d.ts +0 -15
- package/bin/impl/utils/additional.js +0 -47
- /package/bin/impl/{node/mkdirs.d.ts → mkdirs.d.ts} +0 -0
- /package/bin/impl/{node/output-file.js → output-file.js} +0 -0
- /package/bin/impl/{node/path-exists.d.ts → path-exists.d.ts} +0 -0
- /package/bin/impl/{node/path-exists.js → path-exists.js} +0 -0
- /package/bin/impl/{node/remove.d.ts → remove.d.ts} +0 -0
- /package/bin/impl/{node/remove.js → remove.js} +0 -0
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export interface ReadFileOptions {
|
|
2
|
-
encoding?: BufferEncoding | null;
|
|
3
|
-
flag?: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Reads the entire contents of a file.
|
|
7
|
-
*
|
|
8
|
-
* @param path - The path to the file.
|
|
9
|
-
* @param options - Options for reading the file. Can be an encoding string or an object.
|
|
10
|
-
* @returns The file content as a string or Buffer.
|
|
11
|
-
*/
|
|
12
|
-
export declare function readFileSync(path: string, options: BufferEncoding | (ReadFileOptions & {
|
|
13
|
-
encoding: BufferEncoding;
|
|
14
|
-
})): string;
|
|
15
|
-
export declare function readFileSync(path: string, options?: (ReadFileOptions & {
|
|
16
|
-
encoding?: null;
|
|
17
|
-
}) | null): Buffer;
|
|
18
|
-
/**
|
|
19
|
-
* Asynchronously reads the entire contents of a file.
|
|
20
|
-
*
|
|
21
|
-
* @param path - The path to the file.
|
|
22
|
-
* @param options - Options for reading the file. Can be an encoding string or an object.
|
|
23
|
-
* @returns A promise that resolves with the file content as a string or Buffer.
|
|
24
|
-
*/
|
|
25
|
-
export declare function readFile(path: string, options: BufferEncoding | (ReadFileOptions & {
|
|
26
|
-
encoding: BufferEncoding;
|
|
27
|
-
})): Promise<string>;
|
|
28
|
-
export declare function readFile(path: string, options?: (ReadFileOptions & {
|
|
29
|
-
encoding?: null;
|
|
30
|
-
}) | null): Promise<Buffer>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { readFileSync as nodeReadFileSync } from "node:fs";
|
|
2
|
-
import { readFile as nodeReadFileAsync } from "node:fs/promises";
|
|
3
|
-
export function readFileSync(path, options) {
|
|
4
|
-
let encoding;
|
|
5
|
-
let flag;
|
|
6
|
-
if (typeof options === "string") {
|
|
7
|
-
encoding = options;
|
|
8
|
-
} else if (options) {
|
|
9
|
-
encoding = options.encoding;
|
|
10
|
-
flag = options.flag;
|
|
11
|
-
}
|
|
12
|
-
if (encoding) {
|
|
13
|
-
return nodeReadFileSync(path, { encoding, flag });
|
|
14
|
-
}
|
|
15
|
-
return nodeReadFileSync(path, { encoding: null, flag });
|
|
16
|
-
}
|
|
17
|
-
export async function readFile(path, options) {
|
|
18
|
-
let encoding;
|
|
19
|
-
let flag;
|
|
20
|
-
if (typeof options === "string") {
|
|
21
|
-
encoding = options;
|
|
22
|
-
} else if (options) {
|
|
23
|
-
encoding = options.encoding;
|
|
24
|
-
flag = options.flag;
|
|
25
|
-
}
|
|
26
|
-
if (encoding) {
|
|
27
|
-
return nodeReadFileAsync(path, { encoding, flag });
|
|
28
|
-
}
|
|
29
|
-
return nodeReadFileAsync(path, { encoding: null, flag });
|
|
30
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
export function readJsonSync(file, options) {
|
|
4
|
-
let encoding = "utf8";
|
|
5
|
-
let reviver;
|
|
6
|
-
let throws = true;
|
|
7
|
-
if (typeof options === "string") {
|
|
8
|
-
encoding = options;
|
|
9
|
-
} else if (options) {
|
|
10
|
-
encoding = options.encoding ?? encoding;
|
|
11
|
-
reviver = options.reviver;
|
|
12
|
-
if (options.throws !== void 0) {
|
|
13
|
-
throws = options.throws;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
const data = readFileSync(file, { encoding });
|
|
18
|
-
return JSON.parse(data, reviver);
|
|
19
|
-
} catch (err) {
|
|
20
|
-
if (throws) {
|
|
21
|
-
throw err;
|
|
22
|
-
}
|
|
23
|
-
return void 0;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export async function readJson(file, options) {
|
|
27
|
-
let encoding = "utf8";
|
|
28
|
-
let reviver;
|
|
29
|
-
let throws = true;
|
|
30
|
-
let flag;
|
|
31
|
-
if (typeof options === "string") {
|
|
32
|
-
encoding = options;
|
|
33
|
-
} else if (options) {
|
|
34
|
-
encoding = options.encoding ?? encoding;
|
|
35
|
-
reviver = options.reviver;
|
|
36
|
-
flag = options.flag;
|
|
37
|
-
if (options.throws !== void 0) {
|
|
38
|
-
throws = options.throws;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
const data = await readFile(file, { encoding, flag });
|
|
43
|
-
return JSON.parse(data, reviver);
|
|
44
|
-
} catch (err) {
|
|
45
|
-
if (throws) {
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
return void 0;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type PathLike } from "node:fs";
|
|
2
|
-
export type WriteFileOptions = import("node:fs").WriteFileOptions;
|
|
3
|
-
/**
|
|
4
|
-
* Synchronously writes data to a file, replacing the file if it already exists.
|
|
5
|
-
* Ensures the directory exists before writing.
|
|
6
|
-
*
|
|
7
|
-
* @param file - Path to the file.
|
|
8
|
-
* @param data - The data to write. If something other than a Buffer or Uint8Array is provided, it is converted to a string.
|
|
9
|
-
* @param options - Options for writing the file. Can be an encoding string or an object.
|
|
10
|
-
*/
|
|
11
|
-
export declare function writeFileSync(file: PathLike | number, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): void;
|
|
12
|
-
/**
|
|
13
|
-
* Asynchronously writes data to a file, replacing the file if it already exists.
|
|
14
|
-
* Ensures the directory exists before writing.
|
|
15
|
-
*
|
|
16
|
-
* @param file - Path to the file.
|
|
17
|
-
* @param data - The data to write. If something other than a Buffer or Uint8Array is provided, it is converted to a string.
|
|
18
|
-
* @param options - Options for writing the file. Can be an encoding string or an object.
|
|
19
|
-
*/
|
|
20
|
-
export declare function writeFile(file: PathLike | number, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<void>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync as nodeWriteFileSync } from "node:fs";
|
|
2
|
-
import { mkdir, writeFile as nodeWriteFileAsync, stat } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
export function writeFileSync(file, data, options) {
|
|
5
|
-
const dir = path.dirname(file.toString());
|
|
6
|
-
if (!existsSync(dir)) {
|
|
7
|
-
mkdirSync(dir, { recursive: true });
|
|
8
|
-
}
|
|
9
|
-
nodeWriteFileSync(file, data, options);
|
|
10
|
-
}
|
|
11
|
-
export async function writeFile(file, data, options) {
|
|
12
|
-
const dir = path.dirname(file.toString());
|
|
13
|
-
try {
|
|
14
|
-
await stat(dir);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
if (error.code === "ENOENT") {
|
|
17
|
-
await mkdir(dir, { recursive: true });
|
|
18
|
-
} else {
|
|
19
|
-
throw error;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return nodeWriteFileAsync(file, data, options);
|
|
23
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Mode, OpenMode } from "node:fs";
|
|
2
|
-
export interface JsonStringifyOptions {
|
|
3
|
-
replacer?: (key: string, value: unknown) => unknown | (number | string)[] | null;
|
|
4
|
-
spaces?: string | number;
|
|
5
|
-
}
|
|
6
|
-
export interface WriteJsonOptions {
|
|
7
|
-
encoding?: BufferEncoding | null;
|
|
8
|
-
mode?: Mode;
|
|
9
|
-
flag?: OpenMode;
|
|
10
|
-
replacer?: (key: string, value: unknown) => unknown | (number | string)[] | null;
|
|
11
|
-
spaces?: string | number;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Synchronously writes an object to a JSON file.
|
|
15
|
-
*
|
|
16
|
-
* @param file - The path to the file.
|
|
17
|
-
* @param object - The object to stringify and write.
|
|
18
|
-
* @param options - Options for stringifying JSON or writing the file.
|
|
19
|
-
*/
|
|
20
|
-
export declare function writeJsonSync(file: string, object: unknown, options?: WriteJsonOptions): void;
|
|
21
|
-
/**
|
|
22
|
-
* Asynchronously writes an object to a JSON file.
|
|
23
|
-
*
|
|
24
|
-
* @param file - The path to the file.
|
|
25
|
-
* @param object - The object to stringify and write.
|
|
26
|
-
* @param options - Options for stringifying JSON or writing the file.
|
|
27
|
-
*/
|
|
28
|
-
export declare function writeJson(file: string, object: unknown, options?: WriteJsonOptions): Promise<void>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { writeFileSync } from "./write-file.js";
|
|
2
|
-
import { writeFile } from "./write-file.js";
|
|
3
|
-
export function writeJsonSync(file, object, options = {}) {
|
|
4
|
-
const replacer = options.replacer === void 0 ? null : options.replacer;
|
|
5
|
-
const spaces = options.spaces === void 0 ? 2 : options.spaces;
|
|
6
|
-
const fileWriteOpts = {};
|
|
7
|
-
if (options.encoding !== void 0) fileWriteOpts.encoding = options.encoding;
|
|
8
|
-
if (options.mode !== void 0) fileWriteOpts.mode = options.mode;
|
|
9
|
-
if (options.flag !== void 0) fileWriteOpts.flag = options.flag.toString();
|
|
10
|
-
const str = JSON.stringify(object, replacer, spaces);
|
|
11
|
-
writeFileSync(file, str, fileWriteOpts);
|
|
12
|
-
}
|
|
13
|
-
export async function writeJson(file, object, options = {}) {
|
|
14
|
-
const replacer = options.replacer === void 0 ? null : options.replacer;
|
|
15
|
-
const spaces = options.spaces === void 0 ? 2 : options.spaces;
|
|
16
|
-
const fileWriteOpts = {};
|
|
17
|
-
if (options.encoding !== void 0) fileWriteOpts.encoding = options.encoding;
|
|
18
|
-
if (options.mode !== void 0) fileWriteOpts.mode = options.mode;
|
|
19
|
-
if (options.flag !== void 0) fileWriteOpts.flag = options.flag.toString();
|
|
20
|
-
const str = JSON.stringify(object, replacer, spaces);
|
|
21
|
-
await writeFile(file, str, fileWriteOpts);
|
|
22
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { exec } from "node:child_process";
|
|
2
|
-
export declare const execAsync: typeof exec.__promisify__;
|
|
3
|
-
export declare function setHiddenAttributeOnWindows(folderPath: string): Promise<void>;
|
|
4
|
-
export declare function isHidden(filePath: string): Promise<boolean>;
|
|
5
|
-
/**
|
|
6
|
-
* Checks if a directory is empty
|
|
7
|
-
* @param directory Path to the directory
|
|
8
|
-
* @returns Boolean indicating if the directory is empty
|
|
9
|
-
*/
|
|
10
|
-
export declare function isDirectoryEmpty(directory: string): Promise<boolean>;
|
|
11
|
-
/**
|
|
12
|
-
* Removes the specified directory if it exists and then ensures it exists.
|
|
13
|
-
* @param dir - The directory to remove and ensure.
|
|
14
|
-
*/
|
|
15
|
-
export declare function rmEnsureDir(dir: string): Promise<void>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ensuredir } from "@reliverse/relifso";
|
|
2
|
-
import { exec } from "node:child_process";
|
|
3
|
-
import { readdir } from "node:fs/promises";
|
|
4
|
-
import { promisify } from "node:util";
|
|
5
|
-
import { pathExists } from "../node/path-exists.js";
|
|
6
|
-
import { remove } from "../node/remove.js";
|
|
7
|
-
export const execAsync = promisify(exec);
|
|
8
|
-
export async function setHiddenAttributeOnWindows(folderPath) {
|
|
9
|
-
if (process.platform === "win32") {
|
|
10
|
-
try {
|
|
11
|
-
if (await pathExists(folderPath)) {
|
|
12
|
-
const isAlreadyHidden = await isHidden(folderPath);
|
|
13
|
-
if (!isAlreadyHidden) {
|
|
14
|
-
await execAsync(`attrib +h "${folderPath}"`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
} catch (error) {
|
|
18
|
-
console.warn("Failed to set hidden attribute:", String(error));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export async function isHidden(filePath) {
|
|
23
|
-
if (process.platform === "win32") {
|
|
24
|
-
const attributes = await execAsync(`attrib "${filePath}"`);
|
|
25
|
-
return attributes.stdout.includes("H");
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
export async function isDirectoryEmpty(directory) {
|
|
30
|
-
try {
|
|
31
|
-
const files = await readdir(directory);
|
|
32
|
-
return files.length === 0;
|
|
33
|
-
} catch (_error) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export async function rmEnsureDir(dir) {
|
|
38
|
-
try {
|
|
39
|
-
if (await pathExists(dir)) {
|
|
40
|
-
await remove(dir);
|
|
41
|
-
}
|
|
42
|
-
await ensuredir(dir);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error(`Error while removing/ensuring directory ${dir}: ${error}`);
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|