inibase 1.0.0-rc.9 → 1.0.0-rc.90
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/LICENSE +1 -1
- package/README.md +410 -100
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +272 -0
- package/dist/file.d.ts +148 -0
- package/dist/file.js +597 -0
- package/dist/index.d.ts +192 -0
- package/dist/index.js +1350 -0
- package/dist/utils.d.ts +205 -0
- package/dist/utils.js +509 -0
- package/dist/utils.server.d.ts +83 -0
- package/dist/utils.server.js +248 -0
- package/package.json +66 -19
- package/file.ts +0 -501
- package/index.test.ts +0 -210
- package/index.ts +0 -1488
- package/tsconfig.json +0 -7
- package/utils.server.ts +0 -79
- package/utils.ts +0 -212
package/dist/cli.js
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { createInterface } from "node:readline/promises";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import Inison from "inison";
|
|
8
|
+
import { isExists } from "./file.js";
|
|
9
|
+
import Inibase, {} from "./index.js";
|
|
10
|
+
import { isJSON, isNumber, setField, unsetField } from "./utils.js";
|
|
11
|
+
const textGreen = (input) => `\u001b[1;32m${input}\u001b[0m`;
|
|
12
|
+
const textRed = (input) => `\u001b[1;31m${input}\u001b[0m`;
|
|
13
|
+
const textBlue = (input) => `\u001b[1;34m${input}\u001b[0m`;
|
|
14
|
+
const textMagenta = (input) => `\u001b[1;35m${input}\u001b[0m`;
|
|
15
|
+
let { path, version, table } = parseArgs({
|
|
16
|
+
options: {
|
|
17
|
+
path: { type: "string", short: "p" },
|
|
18
|
+
version: { type: "boolean", short: "v" },
|
|
19
|
+
table: { type: "string", short: "t" },
|
|
20
|
+
},
|
|
21
|
+
}).values;
|
|
22
|
+
if (version) {
|
|
23
|
+
console.log(JSON.parse(readFileSync("package.json", "utf8")).version);
|
|
24
|
+
process.exit();
|
|
25
|
+
}
|
|
26
|
+
const rl = createInterface({
|
|
27
|
+
input: process.stdin,
|
|
28
|
+
output: process.stdout,
|
|
29
|
+
prompt: textBlue("> "),
|
|
30
|
+
});
|
|
31
|
+
const setPath = async (firstTime) => {
|
|
32
|
+
if (!path)
|
|
33
|
+
path = await rl.question(firstTime ? "Database path: " : "Please type a valid database path: ");
|
|
34
|
+
if (!path || !(await isExists(path)))
|
|
35
|
+
await setPath();
|
|
36
|
+
};
|
|
37
|
+
console.clear();
|
|
38
|
+
await setPath(true);
|
|
39
|
+
const db = new Inibase(path);
|
|
40
|
+
process.stdout.write("\u001b[3J\u001b[2J\u001b[1J");
|
|
41
|
+
console.clear();
|
|
42
|
+
rl.prompt();
|
|
43
|
+
rl.on("line", async (input) => {
|
|
44
|
+
const splitedInput = input
|
|
45
|
+
.trim()
|
|
46
|
+
.match(/[^\s"']+|"([^"]*)"|'([^']*)'/g);
|
|
47
|
+
switch (splitedInput[0].toLocaleLowerCase()) {
|
|
48
|
+
case "clear":
|
|
49
|
+
process.stdout.write("\u001b[3J\u001b[2J\u001b[1J");
|
|
50
|
+
console.clear();
|
|
51
|
+
rl.prompt();
|
|
52
|
+
break;
|
|
53
|
+
case "exit":
|
|
54
|
+
return process.exit();
|
|
55
|
+
// biome-ignore format:
|
|
56
|
+
case "help": {
|
|
57
|
+
if (!table)
|
|
58
|
+
console.log(` ${textBlue("table")} | ${textBlue("t")} ${textRed("<")}tableName${textRed(">*")}`);
|
|
59
|
+
console.log(` ${textGreen("config")} | ${textGreen("c")}
|
|
60
|
+
${textMagenta("get")} | ${textMagenta("g")} (compression|cache|prepend)?
|
|
61
|
+
${textMagenta("set")} | ${textMagenta("s")} (compression true|false)? (cache true|false)? (prepend true|false)?
|
|
62
|
+
${textGreen("schema")} | ${textGreen("s")}
|
|
63
|
+
${textMagenta("get")} | ${textMagenta("g")} ${textRed("<")}keyName${textRed(">*")}
|
|
64
|
+
${textMagenta("set")} | ${textMagenta("s")} ${textRed("<")}keyName${textRed(">*")} {{ Inison.stringify(Field) }}
|
|
65
|
+
${textGreen("get")} | ${textGreen("g")}
|
|
66
|
+
${textGreen("delete")} | ${textGreen("d")}
|
|
67
|
+
${textGreen("post")} | ${textGreen("p")}
|
|
68
|
+
${textGreen("put")} | ${textGreen("pu")}
|
|
69
|
+
${textMagenta("--where")} | ${textMagenta("-w")} (ID|Inison.stringify(Criteria)|LineNumber)?
|
|
70
|
+
${textMagenta("--page")} | ${textMagenta("-p")} number?
|
|
71
|
+
${textMagenta("--per-page")} | ${textMagenta("-l")} number?
|
|
72
|
+
${textMagenta("--columns")} | ${textMagenta("-c")} columnName[]?
|
|
73
|
+
${textMagenta("--sort")} | ${textMagenta("-s")} (string|string[]|Inison.stringify(sortObject))?
|
|
74
|
+
${textMagenta("--data")} | ${textMagenta("-d")} Inison.stringify(Data) ${textRed("* POST & PUT")}`);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case "c":
|
|
78
|
+
case "config": {
|
|
79
|
+
if (!table) {
|
|
80
|
+
console.log(`${textRed(" Err:")} Please specify table name`);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
const config = (await db.getTable(table)).config;
|
|
84
|
+
if (!splitedInput[1]) {
|
|
85
|
+
console.log(JSON.stringify(config, undefined, 2));
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
switch (splitedInput[1].toLocaleLowerCase()) {
|
|
89
|
+
case "g":
|
|
90
|
+
case "get": {
|
|
91
|
+
if (!splitedInput[2])
|
|
92
|
+
console.log(JSON.stringify(config, undefined, 2));
|
|
93
|
+
else
|
|
94
|
+
console.log(JSON.stringify(config[splitedInput[2]], undefined, 2));
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "s":
|
|
98
|
+
case "set": {
|
|
99
|
+
const newConfigObject = {};
|
|
100
|
+
splitedInput.splice(0, 2);
|
|
101
|
+
for (let index = 0; index < splitedInput.length; index++) {
|
|
102
|
+
const configName = splitedInput[index].toLocaleLowerCase();
|
|
103
|
+
if (["true", "false"].includes(configName))
|
|
104
|
+
continue;
|
|
105
|
+
if (!["compression", "cache", "prepend"].includes(configName)) {
|
|
106
|
+
console.log(`${textRed(" Err:")} '${configName}' is not a valid config`);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
newConfigObject[configName] =
|
|
110
|
+
splitedInput[index + 1].trim() === "true";
|
|
111
|
+
}
|
|
112
|
+
await db.updateTable(table, undefined, newConfigObject);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
default:
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case "s":
|
|
121
|
+
case "schema": {
|
|
122
|
+
if (!table) {
|
|
123
|
+
console.log(`${textRed(" Err:")} Please specify table name`);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
const schema = (await db.getTable(table)).schema;
|
|
127
|
+
if (!splitedInput[1] || !splitedInput[2]) {
|
|
128
|
+
console.log(JSON.stringify(schema, undefined, 2));
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
const key = splitedInput[2];
|
|
132
|
+
if (!key) {
|
|
133
|
+
console.log(`${textRed(" Err:")} Please specify key name`);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
const field = {};
|
|
137
|
+
field.key = key;
|
|
138
|
+
switch (splitedInput[1].toLocaleLowerCase()) {
|
|
139
|
+
case "p":
|
|
140
|
+
case "push":
|
|
141
|
+
await db.updateTable(table, [...(schema ?? []), field]);
|
|
142
|
+
break;
|
|
143
|
+
case "u":
|
|
144
|
+
case "unset":
|
|
145
|
+
case "s":
|
|
146
|
+
case "set": {
|
|
147
|
+
if (!schema) {
|
|
148
|
+
console.log(`${textRed(" Err:")} Schema is empty, please push first`);
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
if (["set", "s"].includes(splitedInput[1].toLocaleLowerCase())) {
|
|
152
|
+
if (!splitedInput[2]) {
|
|
153
|
+
console.log(`${textRed(" Err:")} Give the field a schema`);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
Object.assign(field, Inison.unstringify(splitedInput[2]));
|
|
158
|
+
setField(key, schema, field);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
console.log(`${textRed(" Err:")} Give the field a valid schema`);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else
|
|
166
|
+
unsetField(key, schema);
|
|
167
|
+
await db.updateTable(table, schema);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
default:
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case "t":
|
|
176
|
+
case "table":
|
|
177
|
+
if (!splitedInput[1]) {
|
|
178
|
+
console.log(`${textRed(" Err:")} Please specify table name`);
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
if (!(await isExists(join(path, splitedInput[1]))))
|
|
182
|
+
console.log(`${textRed(" Err:")} Table doesn't exist`);
|
|
183
|
+
else {
|
|
184
|
+
table = splitedInput[1];
|
|
185
|
+
rl.setPrompt(textBlue(`${table} > `));
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
case "p":
|
|
189
|
+
case "post":
|
|
190
|
+
case "g":
|
|
191
|
+
case "get":
|
|
192
|
+
case "pu":
|
|
193
|
+
case "put":
|
|
194
|
+
case "d":
|
|
195
|
+
case "delete": {
|
|
196
|
+
if (!table) {
|
|
197
|
+
console.log(`${textRed(" Err:")} Please specify table name`);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
let where = undefined, page = undefined, perPage = undefined, columns = undefined, sort = undefined, data = undefined;
|
|
201
|
+
if (splitedInput.toSpliced(0, 1).length) {
|
|
202
|
+
const parsedArgs = parseArgs({
|
|
203
|
+
args: splitedInput.toSpliced(0, table ? 1 : 2),
|
|
204
|
+
options: {
|
|
205
|
+
where: { type: "string", short: "w" },
|
|
206
|
+
page: { type: "string", short: "p" },
|
|
207
|
+
perPage: { type: "string", short: "l" },
|
|
208
|
+
sort: { type: "string", short: "s" },
|
|
209
|
+
columns: { type: "string", short: "c", multiple: true },
|
|
210
|
+
data: { type: "string", short: "d" },
|
|
211
|
+
},
|
|
212
|
+
}).values;
|
|
213
|
+
if (parsedArgs.where) {
|
|
214
|
+
if (parsedArgs.where === "'-1'" || parsedArgs.where === '"-1"')
|
|
215
|
+
where = -1;
|
|
216
|
+
else if (isNumber(parsedArgs.where))
|
|
217
|
+
where = Number(parsedArgs.where);
|
|
218
|
+
else if (isJSON(parsedArgs.where))
|
|
219
|
+
where = Inison.unstringify(parsedArgs.where);
|
|
220
|
+
}
|
|
221
|
+
if (parsedArgs.sort) {
|
|
222
|
+
if (isJSON(parsedArgs.sort))
|
|
223
|
+
sort = Inison.unstringify(parsedArgs.sort);
|
|
224
|
+
else
|
|
225
|
+
sort = parsedArgs.sort;
|
|
226
|
+
}
|
|
227
|
+
page = Number(parsedArgs.page) ?? undefined;
|
|
228
|
+
perPage = Number(parsedArgs.perPage) ?? undefined;
|
|
229
|
+
columns = parsedArgs.columns;
|
|
230
|
+
if (parsedArgs.data && isJSON(parsedArgs.data))
|
|
231
|
+
data = Inison.unstringify(parsedArgs.data);
|
|
232
|
+
}
|
|
233
|
+
switch (splitedInput[0].toLocaleLowerCase()) {
|
|
234
|
+
case "g":
|
|
235
|
+
case "get":
|
|
236
|
+
console.log(await db.get(table, where, {
|
|
237
|
+
page: Number(page) ?? 1,
|
|
238
|
+
perPage: Number(perPage) ?? 15,
|
|
239
|
+
columns,
|
|
240
|
+
sort,
|
|
241
|
+
}));
|
|
242
|
+
break;
|
|
243
|
+
case "p":
|
|
244
|
+
case "post":
|
|
245
|
+
console.log(await db.post(table, data, {
|
|
246
|
+
page: Number(page) ?? 1,
|
|
247
|
+
perPage: Number(perPage) ?? 15,
|
|
248
|
+
columns,
|
|
249
|
+
}, true));
|
|
250
|
+
break;
|
|
251
|
+
case "pu":
|
|
252
|
+
case "put":
|
|
253
|
+
console.log(await db.put(table, data, where, {
|
|
254
|
+
page: Number(page) ?? 1,
|
|
255
|
+
perPage: Number(perPage) ?? 15,
|
|
256
|
+
columns,
|
|
257
|
+
}, true));
|
|
258
|
+
break;
|
|
259
|
+
case "d":
|
|
260
|
+
case "delete":
|
|
261
|
+
console.log(await db.delete(table, where));
|
|
262
|
+
break;
|
|
263
|
+
default:
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
default:
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
rl.prompt();
|
|
272
|
+
});
|
package/dist/file.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { ComparisonOperator, FieldType, Schema } from "./index.js";
|
|
2
|
+
export declare const lock: (folderPath: string, prefix?: string) => Promise<void>;
|
|
3
|
+
export declare const unlock: (folderPath: string, prefix?: string) => Promise<void>;
|
|
4
|
+
export declare const write: (filePath: string, data: any) => Promise<void>;
|
|
5
|
+
export declare const read: (filePath: string) => Promise<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Checks if a file or directory exists at the specified path.
|
|
8
|
+
*
|
|
9
|
+
* @param path - The path to the file or directory.
|
|
10
|
+
* @returns A Promise that resolves to true if the file/directory exists, false otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isExists: (path: string) => Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Encodes the input using 'secureString' and 'Inison.stringify' functions.
|
|
15
|
+
* If the input is an array, it is first secured and then joined into a string.
|
|
16
|
+
* If the input is a single value, it is directly secured.
|
|
17
|
+
*
|
|
18
|
+
* @param input - A value or array of values (string, number, boolean, null).
|
|
19
|
+
* @returns The secured and/or joined string.
|
|
20
|
+
*/
|
|
21
|
+
export declare const encode: (input: string | number | boolean | null | (string | number | boolean | null)[]) => string | number | boolean | null;
|
|
22
|
+
/**
|
|
23
|
+
* Decodes the input based on the specified field type(s) and an optional secret key.
|
|
24
|
+
* Handles different formats of input, including strings, numbers, and their array representations.
|
|
25
|
+
*
|
|
26
|
+
* @param input - The input to be decoded, can be a string, number, or null.
|
|
27
|
+
* @param fieldType - Optional type of the field to guide decoding (e.g., 'number', 'boolean').
|
|
28
|
+
* @param fieldChildrenType - Optional type for child elements in array inputs.
|
|
29
|
+
* @param secretKey - Optional secret key for decoding, can be a string or Buffer.
|
|
30
|
+
* @returns Decoded value as a string, number, boolean, or array of these, or null if no fieldType or input is null/empty.
|
|
31
|
+
*/
|
|
32
|
+
export declare const decode: (input: string | null | number, fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[] | Schema, secretKey?: string | Buffer) => string | number | boolean | null | (string | number | null | boolean)[];
|
|
33
|
+
/**
|
|
34
|
+
* Asynchronously reads and decodes data from a file at specified line numbers.
|
|
35
|
+
* Decodes each line based on specified field types and an optional secret key.
|
|
36
|
+
*
|
|
37
|
+
* @param filePath - Path of the file to be read.
|
|
38
|
+
* @param lineNumbers - Optional line number(s) to read from the file. If -1, reads the last line.
|
|
39
|
+
* @param fieldType - Optional type of the field to guide decoding (e.g., 'number', 'boolean').
|
|
40
|
+
* @param fieldChildrenType - Optional type for child elements in array inputs.
|
|
41
|
+
* @param secretKey - Optional secret key for decoding, can be a string or Buffer.
|
|
42
|
+
* @returns Promise resolving to a tuple:
|
|
43
|
+
* 1. Record of line numbers and their decoded content or null if no lines are read.
|
|
44
|
+
* 2. Total count of lines processed.
|
|
45
|
+
*/
|
|
46
|
+
export declare function get(filePath: string, lineNumbers?: number | number[], fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[] | Schema, secretKey?: string | Buffer, readWholeFile?: false): Promise<Record<number, string | number | boolean | null | (string | number | boolean | (string | number | boolean)[] | null)[]> | null>;
|
|
47
|
+
export declare function get(filePath: string, lineNumbers: undefined | number | number[], fieldType: undefined | FieldType | FieldType[], fieldChildrenType: undefined | FieldType | FieldType[], secretKey: undefined | string | Buffer, readWholeFile: true): Promise<[
|
|
48
|
+
Record<number, string | number | boolean | null | (string | number | boolean | (string | number | boolean)[] | null)[]> | null,
|
|
49
|
+
number
|
|
50
|
+
]>;
|
|
51
|
+
/**
|
|
52
|
+
* Asynchronously replaces specific lines in a file based on the provided replacements map or string.
|
|
53
|
+
*
|
|
54
|
+
* @param filePath - Path of the file to modify.
|
|
55
|
+
* @param replacements - Map of line numbers to replacement values, or a single replacement value for all lines.
|
|
56
|
+
* Can be a string, number, boolean, null, array of these types, or a Record/Map of line numbers to these types.
|
|
57
|
+
* @returns Promise<string[]>
|
|
58
|
+
*
|
|
59
|
+
* Note: If the file doesn't exist and replacements is an object, it creates a new file with the specified replacements.
|
|
60
|
+
*/
|
|
61
|
+
export declare const replace: (filePath: string, replacements: string | number | boolean | null | (string | number | boolean | null)[] | Record<number, string | boolean | number | null | (string | boolean | number | null)[]>) => Promise<string[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Asynchronously appends data to the end of a file.
|
|
64
|
+
*
|
|
65
|
+
* @param filePath - Path of the file to append to.
|
|
66
|
+
* @param data - Data to append. Can be a string, number, or an array of strings/numbers.
|
|
67
|
+
* @returns Promise<string[]>. Modifies the file by appending data.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
export declare const append: (filePath: string, data: string | number | (string | number)[]) => Promise<string[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Asynchronously prepends data to the beginning of a file.
|
|
73
|
+
*
|
|
74
|
+
* @param filePath - Path of the file to append to.
|
|
75
|
+
* @param data - Data to append. Can be a string, number, or an array of strings/numbers.
|
|
76
|
+
* @returns Promise<string[]>. Modifies the file by appending data.
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
export declare const prepend: (filePath: string, data: string | number | (string | number)[]) => Promise<string[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Asynchronously removes specified lines from a file.
|
|
82
|
+
*
|
|
83
|
+
* @param filePath - Path of the file from which lines are to be removed.
|
|
84
|
+
* @param linesToDelete - A single line number or an array of line numbers to be deleted.
|
|
85
|
+
* @returns Promise<string[]>. Modifies the file by removing specified lines.
|
|
86
|
+
*
|
|
87
|
+
* Note: Creates a temporary file during the process and replaces the original file with it after removing lines.
|
|
88
|
+
*/
|
|
89
|
+
export declare const remove: (filePath: string, linesToDelete: number | number[]) => Promise<string[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Asynchronously searches a file for lines matching specified criteria, using comparison and logical operators.
|
|
92
|
+
*
|
|
93
|
+
* @param filePath - Path of the file to search.
|
|
94
|
+
* @param operator - Comparison operator(s) for evaluation (e.g., '=', '!=', '>', '<').
|
|
95
|
+
* @param comparedAtValue - Value(s) to compare each line against.
|
|
96
|
+
* @param logicalOperator - Optional logical operator ('and' or 'or') for combining multiple comparisons.
|
|
97
|
+
* @param fieldType - Optional type of the field to guide comparison.
|
|
98
|
+
* @param fieldChildrenType - Optional type for child elements in array inputs.
|
|
99
|
+
* @param limit - Optional limit on the number of results to return.
|
|
100
|
+
* @param offset - Optional offset to start returning results from.
|
|
101
|
+
* @param readWholeFile - Flag to indicate whether to continue reading the file after reaching the limit.
|
|
102
|
+
* @param secretKey - Optional secret key for decoding, can be a string or Buffer.
|
|
103
|
+
* @returns Promise resolving to a tuple:
|
|
104
|
+
* 1. Record of line numbers and their content that match the criteria or null if none.
|
|
105
|
+
* 2. The count of found items or processed items based on the 'readWholeFile' flag.
|
|
106
|
+
*
|
|
107
|
+
* Note: Decodes each line for comparison and can handle complex queries with multiple conditions.
|
|
108
|
+
*/
|
|
109
|
+
export declare const search: (filePath: string, operator: ComparisonOperator | ComparisonOperator[], comparedAtValue: string | number | boolean | null | (string | number | boolean | null)[], logicalOperator?: "and" | "or", fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[] | Schema, limit?: number, offset?: number, readWholeFile?: boolean, secretKey?: string | Buffer) => Promise<[Record<number, string | number | boolean | null | (string | number | boolean | null)[]> | null, number, Set<number> | null]>;
|
|
110
|
+
/**
|
|
111
|
+
* Asynchronously counts the number of lines in a file.
|
|
112
|
+
*
|
|
113
|
+
* @param filePath - Path of the file to count lines in.
|
|
114
|
+
* @returns Promise<number>. The number of lines in the file.
|
|
115
|
+
*
|
|
116
|
+
* Note: Reads through the file line by line to count the total number of lines.
|
|
117
|
+
*/
|
|
118
|
+
export declare const count: (filePath: string) => Promise<number>;
|
|
119
|
+
/**
|
|
120
|
+
* Asynchronously calculates the sum of numerical values from specified lines in a file.
|
|
121
|
+
*
|
|
122
|
+
* @param filePath - Path of the file to read.
|
|
123
|
+
* @param lineNumbers - Optional specific line number(s) to include in the sum. If not provided, sums all lines.
|
|
124
|
+
* @returns Promise<number>. The sum of numerical values from the specified lines.
|
|
125
|
+
*
|
|
126
|
+
* Note: Decodes each line as a number using the 'decode' function. Non-numeric lines contribute 0 to the sum.
|
|
127
|
+
*/
|
|
128
|
+
export declare const sum: (filePath: string, lineNumbers?: number | number[]) => Promise<number>;
|
|
129
|
+
/**
|
|
130
|
+
* Asynchronously finds the maximum numerical value from specified lines in a file.
|
|
131
|
+
*
|
|
132
|
+
* @param filePath - Path of the file to read.
|
|
133
|
+
* @param lineNumbers - Optional specific line number(s) to consider for finding the maximum value. If not provided, considers all lines.
|
|
134
|
+
* @returns Promise<number>. The maximum numerical value found in the specified lines.
|
|
135
|
+
*
|
|
136
|
+
* Note: Decodes each line as a number using the 'decode' function. Considers only numerical values for determining the maximum.
|
|
137
|
+
*/
|
|
138
|
+
export declare const max: (filePath: string, lineNumbers?: number | number[]) => Promise<number>;
|
|
139
|
+
/**
|
|
140
|
+
* Asynchronously finds the minimum numerical value from specified lines in a file.
|
|
141
|
+
*
|
|
142
|
+
* @param filePath - Path of the file to read.
|
|
143
|
+
* @param lineNumbers - Optional specific line number(s) to consider for finding the minimum value. If not provided, considers all lines.
|
|
144
|
+
* @returns Promise<number>. The minimum numerical value found in the specified lines.
|
|
145
|
+
*
|
|
146
|
+
* Note: Decodes each line as a number using the 'decode' function. Considers only numerical values for determining the minimum.
|
|
147
|
+
*/
|
|
148
|
+
export declare const min: (filePath: string, lineNumbers?: number | number[]) => Promise<number>;
|