creatium 0.2.1 → 0.2.2
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 +2 -3
- package/dist/index.d.mts +37 -1125
- package/dist/index.d.ts +37 -1125
- package/dist/index.mjs +240 -6217
- package/dist/shared/creatium.v0AbQ44Q.mjs +5912 -0
- package/dist/utils.d.mts +1013 -0
- package/dist/utils.d.ts +1013 -0
- package/dist/utils.mjs +2 -0
- package/package.json +8 -6
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,1013 @@
|
|
|
1
|
+
import { boxen } from '@visulima/boxen';
|
|
2
|
+
import { TableConstructorOptions } from 'cli-table3';
|
|
3
|
+
import columnify from 'columnify';
|
|
4
|
+
import * as p from '@clack/prompts';
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import { readFile as readFile$1, writeFile as writeFile$1 } from 'node:fs/promises';
|
|
7
|
+
import glob from 'tiny-glob';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
export { default as currentProcess } from 'node:process';
|
|
10
|
+
export { deepmerge, deepmergeCustom } from 'deepmerge-ts';
|
|
11
|
+
export { fileURLToPath } from 'node:url';
|
|
12
|
+
|
|
13
|
+
declare const isBrowser: boolean;
|
|
14
|
+
declare const isNode: boolean;
|
|
15
|
+
declare const isWebWorker: boolean;
|
|
16
|
+
declare const isJsDom: boolean;
|
|
17
|
+
declare const isDeno: boolean;
|
|
18
|
+
declare const isBun: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* True if the environment is a development environment.
|
|
21
|
+
*/
|
|
22
|
+
declare const isDev: boolean;
|
|
23
|
+
|
|
24
|
+
declare const env: {
|
|
25
|
+
isBrowser: boolean;
|
|
26
|
+
isWebWorker: boolean;
|
|
27
|
+
isNode: boolean;
|
|
28
|
+
isJsDom: boolean;
|
|
29
|
+
isDeno: boolean;
|
|
30
|
+
isBun: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Executes a command in the shell and waits for it to finish.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} cmd - The command to execute.
|
|
37
|
+
* @returns {Promise<void>} - A promise that resolves when the command finishes successfully.
|
|
38
|
+
* @throws {Error} - Throws an error if the command fails.
|
|
39
|
+
*/
|
|
40
|
+
declare const exec: (cmd: string) => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Executes a command in a child process and captures its output.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} cmd - The command to execute.
|
|
45
|
+
* @returns {Promise<{ stdout: string; stderr: string }>} - A promise that resolves with the output of the command.
|
|
46
|
+
* @throws {Error} - Throws an error if the command fails, along with its stdout and stderr.
|
|
47
|
+
*/
|
|
48
|
+
declare const execChild: (cmd: string) => Promise<{
|
|
49
|
+
stdout: string;
|
|
50
|
+
stderr: string;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Executes a command and captures its output.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} command - The command to execute, including any arguments.
|
|
56
|
+
* @returns {Promise<string>} A promise that resolves with the captured output (stdout).
|
|
57
|
+
* @throws Will reject with an error if the command fails.
|
|
58
|
+
* @example
|
|
59
|
+
* const [error, output] = await catchExecOutput('dovenv --help')
|
|
60
|
+
* if (error) {
|
|
61
|
+
* console.error(error);
|
|
62
|
+
* } else {
|
|
63
|
+
* await writeFile('dovenvHelp.txt', output)
|
|
64
|
+
* }
|
|
65
|
+
*/
|
|
66
|
+
declare const catchExecOutput: <Res = string>(command: string) => Promise<[Error] | [undefined, Res]>;
|
|
67
|
+
declare const existsLocalBin: (binName: string) => Promise<boolean>;
|
|
68
|
+
declare const existsLocalBins: <Bin extends string>(binaries: Bin[]) => Promise<{ [key in Bin]: boolean; }>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Prompt for number type.
|
|
72
|
+
*
|
|
73
|
+
* @param {NumberParams} opts - NumberOptions.
|
|
74
|
+
* @returns {Promise<number | symbol>} - Promise resolving the answer.
|
|
75
|
+
* @example
|
|
76
|
+
* const age = await number({
|
|
77
|
+
* message: 'What is your age?',
|
|
78
|
+
* errorText: 'Failed getting age',
|
|
79
|
+
* });
|
|
80
|
+
* console.log(age)
|
|
81
|
+
*/
|
|
82
|
+
declare function number(opts: NumberParams): Promise<number | symbol>;
|
|
83
|
+
|
|
84
|
+
type GradientColors = string[] | {
|
|
85
|
+
color: string;
|
|
86
|
+
pos: number;
|
|
87
|
+
}[];
|
|
88
|
+
type GradientOpts = {
|
|
89
|
+
/**
|
|
90
|
+
The gradient can be generated using RGB or HSV interpolation. HSV usually produces brighter colors. Interpolation can be set to rgb for RGB interpolation, orhsv for HSV interpolation.
|
|
91
|
+
Defaults to rgb. Case insentitive.
|
|
92
|
+
*/
|
|
93
|
+
interpolation?: 'rgb' | 'hsv';
|
|
94
|
+
/**
|
|
95
|
+
Used only in the case of HSV interpolation.
|
|
96
|
+
Because hue can be considered as a circle, there are two ways to go from a color to another color.
|
|
97
|
+
HsvSpin can be either short or long, depending on if you want to take the shortest or the longest way between two colors.
|
|
98
|
+
Defaults to short. Case insensitive.
|
|
99
|
+
*/
|
|
100
|
+
hsvSpin?: 'short' | 'long';
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Provides colors for terminal output.
|
|
105
|
+
*
|
|
106
|
+
* @type {object}
|
|
107
|
+
* @example
|
|
108
|
+
* console.log(color.green('This text is green'));
|
|
109
|
+
*/
|
|
110
|
+
declare const color: Record<"black" | "blackBright" | "blue" | "blueBright" | "cyan" | "cyanBright" | "gray" | "green" | "greenBright" | "grey" | "magenta" | "magentaBright" | "red" | "redBright" | "white" | "whiteBright" | "yellow" | "yellowBright" | "bgBlack" | "bgBlackBright" | "bgBlue" | "bgBlueBright" | "bgCyan" | "bgCyanBright" | "bgGray" | "bgGreen" | "bgGreenBright" | "bgGrey" | "bgMagenta" | "bgMagentaBright" | "bgRed" | "bgRedBright" | "bgWhite" | "bgWhiteBright" | "bgYellow" | "bgYellowBright" | "blink" | "bold" | "dim" | "doubleunderline" | "framed" | "hidden" | "inverse" | "italic" | "overlined" | "reset" | "strikethrough" | "underline", (v: string) => string>;
|
|
111
|
+
/**
|
|
112
|
+
* Generates a gradient string with the specified colors.
|
|
113
|
+
*
|
|
114
|
+
* @param {string} txt - The text to apply the gradient to.
|
|
115
|
+
* @param {GradientColors} colors - An array of color names or hex values.
|
|
116
|
+
* @param {GradientOpts} [opts] - Custom opts.
|
|
117
|
+
* @returns {string} - The text with the applied gradient.
|
|
118
|
+
* @example
|
|
119
|
+
* // Example usage:
|
|
120
|
+
* const gradientText = gradient('Gradient Text', ['red', 'yellow', 'green']);
|
|
121
|
+
* console.log(gradientText);
|
|
122
|
+
*/
|
|
123
|
+
declare const gradient: (txt: string, colors: GradientColors, opts?: GradientOpts) => string;
|
|
124
|
+
|
|
125
|
+
declare const line: ({ title, lineChar, align, }: {
|
|
126
|
+
title?: string;
|
|
127
|
+
lineChar?: string;
|
|
128
|
+
align?: "left" | "center" | "right";
|
|
129
|
+
}) => string;
|
|
130
|
+
|
|
131
|
+
type TableData = string[][];
|
|
132
|
+
type BoxOpts = Parameters<typeof boxen>[1];
|
|
133
|
+
type ColumnOpts = columnify.GlobalOptions;
|
|
134
|
+
type ColumnData = Record<string, unknown> | Record<string, unknown>[];
|
|
135
|
+
/**
|
|
136
|
+
* Generates a text-based table from the provided data array.
|
|
137
|
+
*
|
|
138
|
+
* @param {TableData} data - The data to display in the table.
|
|
139
|
+
* @param {TableOpts} [options] - Optional configuration options for the table.
|
|
140
|
+
* @returns {string} - The text-based table.
|
|
141
|
+
* @see https://www.npmjs.com/package/table
|
|
142
|
+
* @example
|
|
143
|
+
* const data = [
|
|
144
|
+
* ['Name', 'Age', 'Country'],
|
|
145
|
+
* ['John', 30, 'USA'],
|
|
146
|
+
* ['Alice', 25, 'UK'],
|
|
147
|
+
* ['Bob', 35, 'Canada'],
|
|
148
|
+
* ];
|
|
149
|
+
* const tableText = table(data);
|
|
150
|
+
* console.log(tableText);
|
|
151
|
+
*/
|
|
152
|
+
declare const table: (data: TableData, options?: TableConstructorOptions) => string;
|
|
153
|
+
/**
|
|
154
|
+
* Creates a styled box around the provided text.
|
|
155
|
+
*
|
|
156
|
+
* @param {string} text - The text to display inside the box.
|
|
157
|
+
* @param {BoxOpts} [options] - Optional configuration options for the box.
|
|
158
|
+
* @returns {string} - The text with the styled box around it.
|
|
159
|
+
* @see https://www.npmjs.com/package/boxen
|
|
160
|
+
* @example
|
|
161
|
+
* const boxedText = box('This is a boxed text', { padding: 1 });
|
|
162
|
+
* console.log(boxedText);
|
|
163
|
+
*/
|
|
164
|
+
declare const box: (text: string, options?: BoxOpts) => string;
|
|
165
|
+
/**
|
|
166
|
+
* Formats data into aligned columns for better readability.
|
|
167
|
+
*
|
|
168
|
+
* @param {ColumnData} data - The data to format into columns.
|
|
169
|
+
* @param {ColumnOpts} [options] - Optional configuration options for column formatting.
|
|
170
|
+
* @returns {string} - The text with the data formatted into columns.
|
|
171
|
+
* @see https://www.npmjs.com/package/columnify
|
|
172
|
+
* @example
|
|
173
|
+
* // data for columns
|
|
174
|
+
* const data = [
|
|
175
|
+
* {
|
|
176
|
+
* name: 'mod1',
|
|
177
|
+
* description: 'some description which happens to be far larger than the max',
|
|
178
|
+
* version: '0.0.1',
|
|
179
|
+
* },
|
|
180
|
+
* {
|
|
181
|
+
* name: 'module-two',
|
|
182
|
+
* description: 'another description larger than the max',
|
|
183
|
+
* version: '0.2.0',
|
|
184
|
+
* }
|
|
185
|
+
* ];
|
|
186
|
+
*
|
|
187
|
+
* // set columns with custom config
|
|
188
|
+
* const columnText = columns(data, {
|
|
189
|
+
* showHeaders: false,
|
|
190
|
+
* minWidth: 20,
|
|
191
|
+
* config: {
|
|
192
|
+
* description: {
|
|
193
|
+
* maxWidth: 30
|
|
194
|
+
* }
|
|
195
|
+
* }
|
|
196
|
+
* });
|
|
197
|
+
*
|
|
198
|
+
* // print columns
|
|
199
|
+
* console.log(columnText);
|
|
200
|
+
*/
|
|
201
|
+
declare const columns: <Data extends ColumnData>(data: Data, options?: ColumnOpts) => string;
|
|
202
|
+
|
|
203
|
+
type EmptyObject = {};
|
|
204
|
+
/**
|
|
205
|
+
* Any Array type
|
|
206
|
+
* Same as `any[]` type. Used only for prevent ts errors
|
|
207
|
+
*/
|
|
208
|
+
type AnyArray = any[];
|
|
209
|
+
/**
|
|
210
|
+
* Any type
|
|
211
|
+
* Same as `any` type. Used only for prevent ts errors
|
|
212
|
+
*/
|
|
213
|
+
type Any = any;
|
|
214
|
+
/**
|
|
215
|
+
* Values of Object
|
|
216
|
+
*/
|
|
217
|
+
type ObjectValues<Values> = Values[keyof Values];
|
|
218
|
+
/**
|
|
219
|
+
* Keys of Object
|
|
220
|
+
*/
|
|
221
|
+
type ObjectKeys<Values> = keyof Values;
|
|
222
|
+
/**
|
|
223
|
+
* DeepPartial
|
|
224
|
+
*/
|
|
225
|
+
type DeepPartial<T> = T extends object ? {
|
|
226
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
227
|
+
} : T;
|
|
228
|
+
/**
|
|
229
|
+
* Prettify your type for better readability
|
|
230
|
+
*/
|
|
231
|
+
type Prettify<T> = {
|
|
232
|
+
[K in keyof T]: T[K];
|
|
233
|
+
} & {};
|
|
234
|
+
/**
|
|
235
|
+
* NonUndefined
|
|
236
|
+
*
|
|
237
|
+
* @description Exclude undefined from set `A`
|
|
238
|
+
* @example
|
|
239
|
+
* // Expect: "string | null"
|
|
240
|
+
* SymmetricDifference<string | null | undefined>;
|
|
241
|
+
*/
|
|
242
|
+
type NonUndefined<A> = A extends undefined ? never : A;
|
|
243
|
+
/**
|
|
244
|
+
* FunctionKeys
|
|
245
|
+
*
|
|
246
|
+
* @description Get union type of keys that are functions in object type `T`
|
|
247
|
+
* @example
|
|
248
|
+
* type MixedProps = {name: string; setName: (name: string) => void; someKeys?: string; someFn?: (...args: any) => any;};
|
|
249
|
+
*
|
|
250
|
+
* // Expect: "setName | someFn"
|
|
251
|
+
* type Keys = FunctionKeys<MixedProps>;
|
|
252
|
+
*/
|
|
253
|
+
type FunctionKeys<T extends object> = {
|
|
254
|
+
[K in keyof T]-?: NonUndefined<T[K]> extends Function ? K : never;
|
|
255
|
+
}[keyof T];
|
|
256
|
+
/**
|
|
257
|
+
* NonFunctionKeys
|
|
258
|
+
*
|
|
259
|
+
* @description Get union type of keys that are non-functions in object type `T`
|
|
260
|
+
* @example
|
|
261
|
+
* type MixedProps = {name: string; setName: (name: string) => void; someKeys?: string; someFn?: (...args: any) => any;};
|
|
262
|
+
*
|
|
263
|
+
* // Expect: "name | someKey"
|
|
264
|
+
* type Keys = NonFunctionKeys<MixedProps>;
|
|
265
|
+
*/
|
|
266
|
+
type NonFunctionKeys<T extends object> = {
|
|
267
|
+
[K in keyof T]-?: NonUndefined<T[K]> extends Function ? never : K;
|
|
268
|
+
}[keyof T];
|
|
269
|
+
/**
|
|
270
|
+
* AssertEqual
|
|
271
|
+
*
|
|
272
|
+
* @description Checks if two types `T` and `U` are equal.
|
|
273
|
+
* @example
|
|
274
|
+
* type Test = AssertEqual<string, string>; // Expected: true
|
|
275
|
+
* type TestFail = AssertEqual<string, number>; // Expected: false
|
|
276
|
+
*/
|
|
277
|
+
type AssertEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends (<V>() => V extends U ? 1 : 2) ? true : false;
|
|
278
|
+
/**
|
|
279
|
+
* ExpectEqual
|
|
280
|
+
*
|
|
281
|
+
* @description Returns the type `T` if `T` and `U` are equal; otherwise, returns `never`.
|
|
282
|
+
* @example
|
|
283
|
+
* type Test = ExpectEqual<string, string>; // Expected: string
|
|
284
|
+
* type TestFail = ExpectEqual<string, number>; // Expected: never
|
|
285
|
+
*/
|
|
286
|
+
type ExpectEqual<T, U> = AssertEqual<T, U> extends true ? T : never;
|
|
287
|
+
type SingleChar<T extends string = string> = T extends `${infer First}${infer Rest}` ? Rest extends '' ? First : never : never;
|
|
288
|
+
type ObjectToArray<T extends Record<string, Any>, Key extends string = 'type'> = {
|
|
289
|
+
[K in keyof T]: T[K] & {
|
|
290
|
+
[k in Key]: K;
|
|
291
|
+
};
|
|
292
|
+
}[keyof T][];
|
|
293
|
+
|
|
294
|
+
declare const promptLineMethods: {
|
|
295
|
+
readonly message: "message";
|
|
296
|
+
readonly info: "info";
|
|
297
|
+
readonly success: "success";
|
|
298
|
+
readonly step: "step";
|
|
299
|
+
readonly warn: "warn";
|
|
300
|
+
readonly warning: "warning";
|
|
301
|
+
readonly error: "error";
|
|
302
|
+
};
|
|
303
|
+
type PromptLineMethod = typeof promptLineMethods[keyof typeof promptLineMethods];
|
|
304
|
+
/**
|
|
305
|
+
* NUMBER.
|
|
306
|
+
*
|
|
307
|
+
*/
|
|
308
|
+
type NumberParams = Prettify<p.TextOptions & {
|
|
309
|
+
errorText?: string;
|
|
310
|
+
}>;
|
|
311
|
+
/**
|
|
312
|
+
* Parameters of the `table` function from the `@dovenv/utils` module.
|
|
313
|
+
*
|
|
314
|
+
* [See module](https://clippo.pigeonposse.com/guide/utils/style#table).
|
|
315
|
+
*/
|
|
316
|
+
type TableParams = Parameters<typeof table>;
|
|
317
|
+
/**
|
|
318
|
+
* Parameters of the `columns` function from the `@dovenv/utils` module.
|
|
319
|
+
*
|
|
320
|
+
* [See module](https://clippo.pigeonposse.com/guide/utils/styles#columns).
|
|
321
|
+
*/
|
|
322
|
+
type ColumnsParams = Parameters<typeof columns>;
|
|
323
|
+
/**
|
|
324
|
+
* Parameters of the `box` function from the `@dovenv/utils` module.
|
|
325
|
+
*
|
|
326
|
+
* [See module](https://clippo.pigeonposse.com/guide/utils/styles#box).
|
|
327
|
+
*/
|
|
328
|
+
type BoxParams = Parameters<typeof box>;
|
|
329
|
+
|
|
330
|
+
declare const prompt: {
|
|
331
|
+
table: (opts: {
|
|
332
|
+
value: TableParams[0];
|
|
333
|
+
opts?: TableParams[1];
|
|
334
|
+
type?: PromptLineMethod;
|
|
335
|
+
}) => void;
|
|
336
|
+
columns: (opts: {
|
|
337
|
+
value: ColumnsParams[0];
|
|
338
|
+
opts?: ColumnsParams[1];
|
|
339
|
+
type?: PromptLineMethod;
|
|
340
|
+
}) => void;
|
|
341
|
+
box: (opts: {
|
|
342
|
+
value: BoxParams[0];
|
|
343
|
+
opts?: BoxParams[1];
|
|
344
|
+
type?: PromptLineMethod;
|
|
345
|
+
}) => void;
|
|
346
|
+
number: typeof number;
|
|
347
|
+
isCancel: typeof p.isCancel;
|
|
348
|
+
updateSettings: typeof p.updateSettings;
|
|
349
|
+
cancel: (message?: string) => void;
|
|
350
|
+
confirm: (opts: p.ConfirmOptions) => Promise<boolean | symbol>;
|
|
351
|
+
group: <T>(prompts: p.PromptGroup<T>, opts?: p.PromptGroupOptions<T> | undefined) => Promise<{ [P in keyof p.PromptGroupAwaitedReturn<T>]: p.PromptGroupAwaitedReturn<T>[P]; }>;
|
|
352
|
+
groupMultiselect: <Value>(opts: p.GroupMultiSelectOptions<Value>) => Promise<symbol | Value[]>;
|
|
353
|
+
intro: (title?: string) => void;
|
|
354
|
+
log: {
|
|
355
|
+
message: (message?: string, { symbol }?: p.LogMessageOptions) => void;
|
|
356
|
+
info: (message: string) => void;
|
|
357
|
+
success: (message: string) => void;
|
|
358
|
+
step: (message: string) => void;
|
|
359
|
+
warn: (message: string) => void;
|
|
360
|
+
warning: (message: string) => void;
|
|
361
|
+
error: (message: string) => void;
|
|
362
|
+
};
|
|
363
|
+
multiselect: <Value>(opts: p.MultiSelectOptions<Value>) => Promise<symbol | Value[]>;
|
|
364
|
+
note: (message?: string, title?: string) => void;
|
|
365
|
+
outro: (message?: string) => void;
|
|
366
|
+
password: (opts: p.PasswordOptions) => Promise<string | symbol>;
|
|
367
|
+
select: <Value>(opts: p.SelectOptions<Value>) => Promise<symbol | Value>;
|
|
368
|
+
selectKey: <Value extends string>(opts: p.SelectOptions<Value>) => Promise<symbol | Value>;
|
|
369
|
+
spinner: ({ indicator }?: p.SpinnerOptions) => {
|
|
370
|
+
start: (msg?: string) => void;
|
|
371
|
+
stop: (msg?: string, code?: number) => void;
|
|
372
|
+
message: (msg?: string) => void;
|
|
373
|
+
};
|
|
374
|
+
stream: {
|
|
375
|
+
message: (iterable: Iterable<string> | AsyncIterable<string>, { symbol }?: p.LogMessageOptions) => Promise<void>;
|
|
376
|
+
info: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
|
|
377
|
+
success: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
|
|
378
|
+
step: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
|
|
379
|
+
warn: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
|
|
380
|
+
warning: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
|
|
381
|
+
error: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
|
|
382
|
+
};
|
|
383
|
+
tasks: (tasks: p.Task[]) => Promise<void>;
|
|
384
|
+
text: (opts: p.TextOptions) => Promise<string | symbol>;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
type ParamFn = (arg: string) => Promise<string>;
|
|
388
|
+
type ParamsValue = string | number | Record<string, unknown> | unknown[] | unknown;
|
|
389
|
+
type Params = Record<string, ParamsValue>;
|
|
390
|
+
type Props = {
|
|
391
|
+
/** Content to be replaced */
|
|
392
|
+
content: string;
|
|
393
|
+
/**
|
|
394
|
+
* Parameters
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* const params = {
|
|
398
|
+
* name: 'Antonio',
|
|
399
|
+
* lastName : 'Resines'
|
|
400
|
+
* }
|
|
401
|
+
*/
|
|
402
|
+
params: Params;
|
|
403
|
+
/**
|
|
404
|
+
* Transform parameters insde placeholders.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* const transform = async ( param: string ) => {
|
|
408
|
+
* if ( param === 'url' ) return 'https://pigeonposse.com',
|
|
409
|
+
* else if ( param === 'http://pigeonposse.com' ) return 'https://pigeonposse.com'
|
|
410
|
+
* return param
|
|
411
|
+
* }
|
|
412
|
+
*/
|
|
413
|
+
transform?: ParamFn;
|
|
414
|
+
/** Options */
|
|
415
|
+
opts?: {
|
|
416
|
+
/**
|
|
417
|
+
* Throw an error if a placeholder is not found.
|
|
418
|
+
*
|
|
419
|
+
* @default false
|
|
420
|
+
*/
|
|
421
|
+
throw?: boolean;
|
|
422
|
+
/**
|
|
423
|
+
* Throw an error if a parameter is not found.
|
|
424
|
+
*
|
|
425
|
+
* @default
|
|
426
|
+
* {
|
|
427
|
+
* prefix : '{{',
|
|
428
|
+
* suffix : '}}',
|
|
429
|
+
* }
|
|
430
|
+
*/
|
|
431
|
+
mark?: {
|
|
432
|
+
prefix: string;
|
|
433
|
+
suffix: string;
|
|
434
|
+
};
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
/**
|
|
438
|
+
* Replace placeholders in a string with their corresponding values.
|
|
439
|
+
*
|
|
440
|
+
* The function takes a string with placeholders, an object with parameter values,
|
|
441
|
+
* and an optional custom parameter function.
|
|
442
|
+
*
|
|
443
|
+
* The function returns a Promise that resolves to the string with all placeholders
|
|
444
|
+
* replaced.
|
|
445
|
+
*
|
|
446
|
+
* @param {Props} props - Props for the function.
|
|
447
|
+
* @param {Props['content']} props.content - The string with placeholders.
|
|
448
|
+
* @param {Props['params']} props.params - An object with parameter values.
|
|
449
|
+
* @param {Props['transform']} [props.transform] - An optional custom parameter function.
|
|
450
|
+
* @param {Props['opts']} [props.opts] - Options to customize the behavior of the function.
|
|
451
|
+
* @returns {Promise<string>} - A Promise that resolves to the string with all placeholders replaced.
|
|
452
|
+
*/
|
|
453
|
+
declare const replacePlaceholders: (props: Props) => Promise<string>;
|
|
454
|
+
|
|
455
|
+
declare const getStringType: (value: string) => "text" | "url" | "path";
|
|
456
|
+
/**
|
|
457
|
+
* Joins the given URL parts into a single string.
|
|
458
|
+
*
|
|
459
|
+
* @param {string[]} parts - The URL parts to join.
|
|
460
|
+
* @returns {string} - The joined URL string.
|
|
461
|
+
*/
|
|
462
|
+
declare const joinUrl: (...parts: string[]) => string;
|
|
463
|
+
/**
|
|
464
|
+
* Converts an object to a JSON string.
|
|
465
|
+
*
|
|
466
|
+
* @param {unknown} data - The data to convert to a string.
|
|
467
|
+
* @returns {string} - The JSON string representation of the data.
|
|
468
|
+
*/
|
|
469
|
+
declare const object2string: (data: unknown) => string;
|
|
470
|
+
/**
|
|
471
|
+
* Truncates a given string to a maximum length and adds an ellipsis (...) at the end.
|
|
472
|
+
*
|
|
473
|
+
* @param {string} text - The string to truncate.
|
|
474
|
+
* @param {number} maxLength - The maximum length of the string.
|
|
475
|
+
* @param {string} [ellipsis] - The ellipsis to add at the end of the truncated string (default is '…').
|
|
476
|
+
* @returns {string} - The truncated string.
|
|
477
|
+
*/
|
|
478
|
+
declare const truncate: (text: string, maxLength: number, ellipsis?: string) => string;
|
|
479
|
+
|
|
480
|
+
declare const resolvePath: (...paths: string[]) => string;
|
|
481
|
+
declare const relativePath: (from: string, to: string) => string;
|
|
482
|
+
declare const getExtName: (path: string) => string;
|
|
483
|
+
declare const getDirName: (path: string) => string;
|
|
484
|
+
declare const getBaseName: (path: string, suffix?: string) => string;
|
|
485
|
+
declare const isAbsolutePath: (path: string) => boolean;
|
|
486
|
+
declare const normalizePath: (path: string) => string;
|
|
487
|
+
|
|
488
|
+
declare const writeFile: typeof writeFile$1;
|
|
489
|
+
/**
|
|
490
|
+
* Find files and directories using glob patterns.
|
|
491
|
+
*
|
|
492
|
+
*/
|
|
493
|
+
declare const getPaths: typeof glob;
|
|
494
|
+
/**
|
|
495
|
+
* Checks if two file paths are equal after normalization.
|
|
496
|
+
* Normalization ensures that differences like trailing slashes or redundant path segments are ignored.
|
|
497
|
+
*
|
|
498
|
+
* ---
|
|
499
|
+
*
|
|
500
|
+
* @param {string} path1 - The first file path to compare.
|
|
501
|
+
* @param {string} path2 - The second file path to compare.
|
|
502
|
+
* @returns {boolean} `true` if the paths are equal, `false` otherwise.
|
|
503
|
+
*/
|
|
504
|
+
declare const arePathsEqual: (path1: string, path2: string) => boolean;
|
|
505
|
+
/**
|
|
506
|
+
* Check if a string is a valid path.
|
|
507
|
+
*
|
|
508
|
+
* @param {string} str - The string to test.
|
|
509
|
+
* @returns {boolean} True if the string is a valid path.
|
|
510
|
+
* @example
|
|
511
|
+
* isPath('..') // true
|
|
512
|
+
* isPath('foo bar') // false
|
|
513
|
+
* isPath('C:\\') // true
|
|
514
|
+
* isPath('foo\\bar') // true
|
|
515
|
+
* isPath('foo/bar') // true
|
|
516
|
+
* isPath('foo bar/baz') // false
|
|
517
|
+
*/
|
|
518
|
+
declare const isPath: (str: string) => boolean;
|
|
519
|
+
/**
|
|
520
|
+
* Creates a directory if it does not exist.
|
|
521
|
+
*
|
|
522
|
+
* @param {string} path - Path to the directory to create.
|
|
523
|
+
* @returns {Promise<void>} - A promise that resolves when the directory has been created.
|
|
524
|
+
* @example
|
|
525
|
+
* await ensureDir('./path/to/directory')
|
|
526
|
+
*/
|
|
527
|
+
declare const ensureDir: (path: string) => Promise<void>;
|
|
528
|
+
/**
|
|
529
|
+
* Reads the contents of a directory.
|
|
530
|
+
*
|
|
531
|
+
* @param {string} path - Path to the directory to read.
|
|
532
|
+
* @returns {Promise<import('node:fs').Dirent[]>} - A promise that resolves to an array of {@link https://nodejs.org/api/fs.html#class-fs-dirent | fs.Dirent} objects.
|
|
533
|
+
* @example
|
|
534
|
+
* const dirItems = await readDir('./path/to/directory')
|
|
535
|
+
*/
|
|
536
|
+
declare const readDir: (path: string) => Promise<fs.Dirent<string>[]>;
|
|
537
|
+
/**
|
|
538
|
+
* Gets the file names in a directory and filters them by extension.
|
|
539
|
+
*
|
|
540
|
+
* @param {object} props - Function props.
|
|
541
|
+
* @param {string} props.path - Path to the directory.
|
|
542
|
+
* @param {string[]} props.extensions - Array of extensions to filter by, e.g., ['.md', '.txt'].
|
|
543
|
+
* @returns {Promise<string[]>} - A promise that resolves with an array of file names without extensions.
|
|
544
|
+
*/
|
|
545
|
+
declare function getFilteredFileNames({ path, extensions, }: {
|
|
546
|
+
path: string;
|
|
547
|
+
extensions: string[];
|
|
548
|
+
}): Promise<string[]>;
|
|
549
|
+
/**
|
|
550
|
+
* Gets the current directory.
|
|
551
|
+
*
|
|
552
|
+
* @param {string} [path] - An optional path to resolve the directory from.
|
|
553
|
+
* @returns {string} - The current directory.
|
|
554
|
+
* @example getCurrentDir()
|
|
555
|
+
*/
|
|
556
|
+
declare const getCurrentDir: (path?: string) => string;
|
|
557
|
+
/**
|
|
558
|
+
* Joins path segments.
|
|
559
|
+
*
|
|
560
|
+
* @param {...string} paths - Path segments to join.
|
|
561
|
+
* @returns {string} - The joined path.
|
|
562
|
+
* @example joinPath('user', 'pigeonposse')
|
|
563
|
+
*/
|
|
564
|
+
declare function joinPath(...paths: string[]): string;
|
|
565
|
+
/**
|
|
566
|
+
* Resolves path segments into an absolute path.
|
|
567
|
+
*
|
|
568
|
+
* @param {...string} paths - Path segments to resolve.
|
|
569
|
+
* @returns {string} - The resolved absolute path.
|
|
570
|
+
*/
|
|
571
|
+
declare const getAbsolutePath: (...paths: string[]) => string;
|
|
572
|
+
/**
|
|
573
|
+
* Validates and resolves a path with home directory replacement.
|
|
574
|
+
*
|
|
575
|
+
* @param {string} path - The path to validate and resolve.
|
|
576
|
+
* @returns {string} - The validated and resolved absolute path.
|
|
577
|
+
* @example
|
|
578
|
+
* import { validateHomeDir } from '@dovenv/utils'
|
|
579
|
+
*
|
|
580
|
+
* const path = validateHomeDir('~/Documents')
|
|
581
|
+
*
|
|
582
|
+
* console.log(path) // returns: /users/{username}/Documents
|
|
583
|
+
*
|
|
584
|
+
* const path = validateHomeDir('/Home')
|
|
585
|
+
*
|
|
586
|
+
* console.log(path) // returns same: /Home
|
|
587
|
+
*/
|
|
588
|
+
declare function validateHomeDir(path: string): string;
|
|
589
|
+
/**
|
|
590
|
+
* Reads the content of a file at the specified path.
|
|
591
|
+
*
|
|
592
|
+
* @param {string} path - The path of the file to read.
|
|
593
|
+
* @returns {Promise<string | Buffer>} - A promise that resolves to the content of the file as a string or buffer.
|
|
594
|
+
* @throws {Error} If an error occurs while reading the file.
|
|
595
|
+
* @example import { readFile } from '@dovenv/utils'
|
|
596
|
+
*
|
|
597
|
+
* try {
|
|
598
|
+
* const content = await readFile('./example.txt');
|
|
599
|
+
* console.log(content);
|
|
600
|
+
* } catch (error) {
|
|
601
|
+
* console.error('Error reading file:', error);
|
|
602
|
+
* }
|
|
603
|
+
*/
|
|
604
|
+
declare const readFile: typeof readFile$1;
|
|
605
|
+
/**
|
|
606
|
+
* Removes a directory and its contents if it exists.
|
|
607
|
+
*
|
|
608
|
+
* @param {string} path - The path of the directory to remove.
|
|
609
|
+
* @throws {Error} If an error occurs while removing the directory.
|
|
610
|
+
* @example import { removeDir } from '@dovenv/utils'
|
|
611
|
+
*
|
|
612
|
+
* try {
|
|
613
|
+
* await removeDir('./my/path')
|
|
614
|
+
* } catch (e) {
|
|
615
|
+
* console.log(e)
|
|
616
|
+
* }
|
|
617
|
+
*/
|
|
618
|
+
declare function removeDir(path: string): Promise<void>;
|
|
619
|
+
/**
|
|
620
|
+
* Removes a directory and its contents if it exists.
|
|
621
|
+
*
|
|
622
|
+
* @param {string} path - The path of the directory to remove.
|
|
623
|
+
* @throws {Error} If an error occurs while removing the directory.
|
|
624
|
+
* @example import { removeDirIfExist } from '@dovenv/utils'
|
|
625
|
+
*
|
|
626
|
+
* await removeDirIfExist('./my/path')
|
|
627
|
+
*/
|
|
628
|
+
declare function removeDirIfExist(path: string): Promise<void>;
|
|
629
|
+
/**
|
|
630
|
+
* Removes a file or directory if it exists.
|
|
631
|
+
*
|
|
632
|
+
* @param {string} path - The path of the file or directory to remove.
|
|
633
|
+
* @throws {Error} If an error occurs while removing the file or directory.
|
|
634
|
+
* @example
|
|
635
|
+
* try {
|
|
636
|
+
* await removePathIfExist('./my/path')
|
|
637
|
+
* } catch (e) {
|
|
638
|
+
* console.log(e)
|
|
639
|
+
* }
|
|
640
|
+
*/
|
|
641
|
+
declare function removePathIfExist(path: string): Promise<void>;
|
|
642
|
+
/**
|
|
643
|
+
* Removes a file if it exists.
|
|
644
|
+
*
|
|
645
|
+
* @param {string} path - The path of the file to remove.
|
|
646
|
+
* @throws {Error} If an error occurs while removing the file.
|
|
647
|
+
* @example
|
|
648
|
+
* try {
|
|
649
|
+
* await removeFile('./my/path')
|
|
650
|
+
* } catch (e) {
|
|
651
|
+
* console.log(e)
|
|
652
|
+
* }
|
|
653
|
+
*/
|
|
654
|
+
declare function removeFileIfExist(path: string): Promise<void>;
|
|
655
|
+
/**
|
|
656
|
+
* Removes a file.
|
|
657
|
+
*
|
|
658
|
+
* @param {string} path - The path of the file to remove.
|
|
659
|
+
* @throws {Error} If an error occurs while removing the file.
|
|
660
|
+
* @example
|
|
661
|
+
* try {
|
|
662
|
+
* await removeFile('./my/path')
|
|
663
|
+
* } catch (e) {
|
|
664
|
+
* console.log(e)
|
|
665
|
+
* }
|
|
666
|
+
*/
|
|
667
|
+
declare function removeFile(path: string): Promise<void>;
|
|
668
|
+
/**
|
|
669
|
+
* Checks if the given path points to a directory.
|
|
670
|
+
*
|
|
671
|
+
* @param {string} path - The path to check.
|
|
672
|
+
* @returns {Promise<boolean>} - A promise that resolves to true if the path points to a directory, otherwise false.
|
|
673
|
+
* @example import { isDirectory } from '@dovenv/utils'
|
|
674
|
+
*
|
|
675
|
+
* const isDir = await isDirectory('./my/path')
|
|
676
|
+
*/
|
|
677
|
+
declare function isDirectory(path: string): Promise<boolean>;
|
|
678
|
+
/**
|
|
679
|
+
* Creates a directory at the specified path.
|
|
680
|
+
*
|
|
681
|
+
* @param {string} path - The path of the directory to create.
|
|
682
|
+
* @throws {Error} If an error occurs while creating the directory.
|
|
683
|
+
* @example import { createDir } from '@dovenv/utils'
|
|
684
|
+
* await createDir('./my/dir')
|
|
685
|
+
*/
|
|
686
|
+
declare function createDir(path: string): Promise<void>;
|
|
687
|
+
/**
|
|
688
|
+
* Checks if a directory exists at the specified path.
|
|
689
|
+
*
|
|
690
|
+
* @param {string} path - The path to check.
|
|
691
|
+
* @returns {Promise<boolean>} - A promise that resolves to true if a directory exists at the specified path, otherwise false.
|
|
692
|
+
* @example import { existsDir } from '@dovenv/utils'
|
|
693
|
+
* const exist = await existsDir('./my/dir')
|
|
694
|
+
*/
|
|
695
|
+
declare function existsDir(path: string): Promise<boolean>;
|
|
696
|
+
/**
|
|
697
|
+
* Checks if a file exists at the specified path.
|
|
698
|
+
*
|
|
699
|
+
* @param {string} path - The path to the file.
|
|
700
|
+
* @returns {Promise<boolean>} - A promise that resolves to true if the file exists, otherwise false.
|
|
701
|
+
* @throws {Error} If an error occurs while checking the existence of the file.
|
|
702
|
+
* @example import { existsFile } from '@dovenv/utils'
|
|
703
|
+
*
|
|
704
|
+
* const existPKG = await existsFile('./package.json')
|
|
705
|
+
*/
|
|
706
|
+
declare function existsFile(path: string): Promise<boolean>;
|
|
707
|
+
/**
|
|
708
|
+
* Writes content to a file at the specified path.
|
|
709
|
+
*
|
|
710
|
+
* @param {string} path - The path of the file to write to.
|
|
711
|
+
* @param {string | Buffer} content - The content to write to the file.
|
|
712
|
+
* @throws {Error} If an error occurs while writing to the file.
|
|
713
|
+
* @example import { writeFileContent } from '@dovenv/utils'
|
|
714
|
+
*
|
|
715
|
+
* await writeFileContent('./greetFile.txt', 'Hello')
|
|
716
|
+
*/
|
|
717
|
+
declare function writeFileContent(path: string, content: string | Buffer): Promise<void>;
|
|
718
|
+
/**
|
|
719
|
+
* Checks if a file or directory exists at the specified path.
|
|
720
|
+
*
|
|
721
|
+
* @param {string} path - The path to check.
|
|
722
|
+
* @returns {Promise<boolean>} - A promise that resolves to true if a file or directory exists at the specified path, otherwise false.
|
|
723
|
+
* @throws {Error} If an error occurs while checking the existence of the path.
|
|
724
|
+
* @example import { existsPath } from '@dovenv/utils'
|
|
725
|
+
*
|
|
726
|
+
* const existPKG = await existsPath('./package.json')
|
|
727
|
+
*/
|
|
728
|
+
declare function existsPath(path: string): Promise<boolean>;
|
|
729
|
+
/**
|
|
730
|
+
* Creates a symbolic link from the input path to the output path.
|
|
731
|
+
*
|
|
732
|
+
* @param {{input: string, output: string}} options - Options object with input and output paths.
|
|
733
|
+
* @returns {Promise<void>} - Resolves when the symbolic link has been created.
|
|
734
|
+
* @throws {Error} If there is an error creating the symbolic link.
|
|
735
|
+
* @example import { createSymlink } from '@dovenv/utils'
|
|
736
|
+
*
|
|
737
|
+
* const symlinkResult = await createSymlink({
|
|
738
|
+
* input : '/path/to/source',
|
|
739
|
+
* output: '/path/to/destination',
|
|
740
|
+
* })
|
|
741
|
+
*/
|
|
742
|
+
declare const createSymlink: ({ input, output, }: {
|
|
743
|
+
input: string;
|
|
744
|
+
output: string;
|
|
745
|
+
}) => Promise<void>;
|
|
746
|
+
|
|
747
|
+
type ContentInput = {
|
|
748
|
+
/**
|
|
749
|
+
* The name of the file
|
|
750
|
+
*
|
|
751
|
+
* @example 'index.html'
|
|
752
|
+
* @example 'src/index.js'
|
|
753
|
+
*/
|
|
754
|
+
path: string;
|
|
755
|
+
content: string | Buffer;
|
|
756
|
+
};
|
|
757
|
+
type CopyDirOptions = {
|
|
758
|
+
/**
|
|
759
|
+
* The path of the directory to copy or an array of files and directories to copy.
|
|
760
|
+
*/
|
|
761
|
+
input: ContentInput[] | string;
|
|
762
|
+
/**
|
|
763
|
+
* The path of the destination directory.
|
|
764
|
+
*/
|
|
765
|
+
output: string;
|
|
766
|
+
};
|
|
767
|
+
declare const getContentDir: (input: string, opts?: Omit<Parameters<typeof getPaths>[1], "cwd" | "filesOnly"> & {
|
|
768
|
+
pattern?: string;
|
|
769
|
+
encoding?: Parameters<typeof readFile>[1];
|
|
770
|
+
}) => Promise<ContentInput[]>;
|
|
771
|
+
/**
|
|
772
|
+
* Copy a file from input path to output path.
|
|
773
|
+
*
|
|
774
|
+
* @param {{input: string, output: string}} options - Options object with input and output paths.
|
|
775
|
+
* @returns {Promise<void>} - Resolves when the file has been copied.
|
|
776
|
+
* @throws {Error} If there is an error copying the file.
|
|
777
|
+
* @example import { copyFile } from '@dovenv/utils'
|
|
778
|
+
*
|
|
779
|
+
* const copyResult = await copyFile({
|
|
780
|
+
* input : '/path/to/source.txt',
|
|
781
|
+
* output: '/path/to/destination.txt',
|
|
782
|
+
* })
|
|
783
|
+
*/
|
|
784
|
+
declare const copyFile: ({ input, output, }: {
|
|
785
|
+
input: string;
|
|
786
|
+
output: string;
|
|
787
|
+
}) => Promise<void>;
|
|
788
|
+
/**
|
|
789
|
+
* Copy a directory from input path to output path.
|
|
790
|
+
*
|
|
791
|
+
* @param {{input: string, output: string}} options - Options object with input and output paths.
|
|
792
|
+
* @returns {Promise<void>} - Resolves when the directory has been copied.
|
|
793
|
+
* @throws {Error} If there is an error copying the directory.
|
|
794
|
+
* @example
|
|
795
|
+
*
|
|
796
|
+
* const copyResult = await copyDir({
|
|
797
|
+
* input : '/path/to/sourceDir',
|
|
798
|
+
* output: '/path/to/destinationDir',
|
|
799
|
+
* })
|
|
800
|
+
*
|
|
801
|
+
* const copyResult = await copyDir({
|
|
802
|
+
* input : [
|
|
803
|
+
* { name: 'file1.txt', content: 'Hello, world!' },
|
|
804
|
+
* { name: 'subfolder/subfile.txt', content: 'Subfolder content' } },
|
|
805
|
+
* ],
|
|
806
|
+
* output: '/path/to/destinationDir',
|
|
807
|
+
})
|
|
808
|
+
*/
|
|
809
|
+
declare const copyDir: ({ input, output, }: CopyDirOptions) => Promise<void>;
|
|
810
|
+
|
|
811
|
+
declare const getHomeDir: typeof homedir;
|
|
812
|
+
/**
|
|
813
|
+
* Returns the path to the operating system's temporary directory.
|
|
814
|
+
*
|
|
815
|
+
* @returns {string} The path to the operating system's temporary directory.
|
|
816
|
+
*/
|
|
817
|
+
declare const getTempDir: () => string;
|
|
818
|
+
/**
|
|
819
|
+
* Determines the operating system.
|
|
820
|
+
*
|
|
821
|
+
* @returns {'windows' | 'macos' | 'linux' | 'unknown'} - The operating system. Possible values are 'linux', 'macos', or 'windows'.
|
|
822
|
+
*/
|
|
823
|
+
declare const getPlatform: () => Promise<"windows" | "macos" | "linux" | "unknown">;
|
|
824
|
+
/**
|
|
825
|
+
* Returns the operating system CPU architecture.
|
|
826
|
+
*
|
|
827
|
+
* @returns {'arm64' | 'x64' | 'unknown'} - The operating system CPU architecture.
|
|
828
|
+
*/
|
|
829
|
+
declare function getArch(): 'arm64' | 'x64' | 'unknown';
|
|
830
|
+
|
|
831
|
+
declare const getSystemEnvPaths: ({ name, suffix, }: {
|
|
832
|
+
name: string;
|
|
833
|
+
suffix?: string;
|
|
834
|
+
}) => {
|
|
835
|
+
data: string;
|
|
836
|
+
config: string;
|
|
837
|
+
cache: string;
|
|
838
|
+
log: string;
|
|
839
|
+
temp: string;
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
type CacheOptions<Values extends Record<string, unknown>> = {
|
|
843
|
+
/**
|
|
844
|
+
* Project name for search cache.
|
|
845
|
+
* You can reuse the same cache for multiple instances.
|
|
846
|
+
*/
|
|
847
|
+
projectName: string;
|
|
848
|
+
/**
|
|
849
|
+
* Identifier for the values.
|
|
850
|
+
*/
|
|
851
|
+
id: string;
|
|
852
|
+
/**
|
|
853
|
+
* Cache Default Values.
|
|
854
|
+
*/
|
|
855
|
+
values: Values;
|
|
856
|
+
/**
|
|
857
|
+
* Directory to save cache file.
|
|
858
|
+
* Default: System default user config directory.
|
|
859
|
+
* You most likely don't need this. Please don't use it unless you really have to.
|
|
860
|
+
*/
|
|
861
|
+
cwd?: string;
|
|
862
|
+
/**
|
|
863
|
+
* Suffix for cache directory.
|
|
864
|
+
*/
|
|
865
|
+
suffix?: string;
|
|
866
|
+
};
|
|
867
|
+
/**
|
|
868
|
+
* Creates a caching mechanism for storing and retrieving values.
|
|
869
|
+
*
|
|
870
|
+
* @param {object} opts - Parameters for configuring the cache.
|
|
871
|
+
* @returns {object} - An object with methods to interact with the cache.
|
|
872
|
+
* @throws {Error} If the cache value is unexpected or not found.
|
|
873
|
+
* @example
|
|
874
|
+
*
|
|
875
|
+
* const { get, set } = await cache({
|
|
876
|
+
* projectName: 'myApp',
|
|
877
|
+
* id: 'userSettings',
|
|
878
|
+
* values: {
|
|
879
|
+
* theme: 'dark',
|
|
880
|
+
* language: 'en'
|
|
881
|
+
* },
|
|
882
|
+
* });
|
|
883
|
+
*
|
|
884
|
+
* // Set a new value in the cache
|
|
885
|
+
* set({ theme: 'light' });
|
|
886
|
+
*
|
|
887
|
+
* // Retrieve a value from the cache
|
|
888
|
+
* const theme = get('theme');
|
|
889
|
+
* console.log(theme); // Output: 'light'
|
|
890
|
+
*
|
|
891
|
+
* // Retrieve all cached values
|
|
892
|
+
* const allValues = get();
|
|
893
|
+
* console.log(allValues); // Output: { theme: 'light', language: 'en' }
|
|
894
|
+
*
|
|
895
|
+
* // Handle unexpected cache value
|
|
896
|
+
* try {
|
|
897
|
+
* const nonExistentValue = get('nonExistent');
|
|
898
|
+
* } catch (error) {
|
|
899
|
+
* console.error('Error:', error.message); // Output: Cache value is unexpected: nonExistent
|
|
900
|
+
* }
|
|
901
|
+
*/
|
|
902
|
+
declare const cache: <Values extends Record<string, unknown>>(opts: CacheOptions<Values>) => Promise<{
|
|
903
|
+
/**
|
|
904
|
+
* The default values for the cache.
|
|
905
|
+
*/
|
|
906
|
+
defaultValues: Values;
|
|
907
|
+
/**
|
|
908
|
+
* Retrieve a value from the cache.
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* const theme = get('theme');
|
|
912
|
+
* console.log(theme); // Output: 'light'
|
|
913
|
+
*/
|
|
914
|
+
get: <ID extends string | undefined = undefined>(v?: ID) => Promise<ID extends keyof Values ? Values[ID] : ID extends string ? undefined : Values>;
|
|
915
|
+
/**
|
|
916
|
+
* Updates the cache with the provided values.
|
|
917
|
+
*
|
|
918
|
+
* Merges the existing cached values with the new partial values and updates the cache.
|
|
919
|
+
*/
|
|
920
|
+
set: (obj: Partial<Values>) => Promise<void>;
|
|
921
|
+
/**
|
|
922
|
+
* Resets the cache to its default values.
|
|
923
|
+
*
|
|
924
|
+
* @example
|
|
925
|
+
* reset();
|
|
926
|
+
*/
|
|
927
|
+
reset: () => Promise<void>;
|
|
928
|
+
/**
|
|
929
|
+
* The path to the cache file.
|
|
930
|
+
*/
|
|
931
|
+
path: string;
|
|
932
|
+
}>;
|
|
933
|
+
|
|
934
|
+
type CommonObj = Record<string, unknown> | Record<string, unknown>[] | unknown[];
|
|
935
|
+
declare const getObjectFromJSONFile: <Res extends CommonObj = CommonObj>(path: string) => Promise<Res>;
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* Finds the closest package.json by traversing up the directory tree.
|
|
939
|
+
*
|
|
940
|
+
* @param {string} [startDir] - Directory to start searching from.
|
|
941
|
+
* @returns {string} Absolute path to the closest package.json.
|
|
942
|
+
* @throws {Error} If no package.json is found.
|
|
943
|
+
*/
|
|
944
|
+
declare const getClosestPackageJson: (startDir?: string) => Promise<string>;
|
|
945
|
+
/**
|
|
946
|
+
* Finds the closest package directory by traversing up the directory tree.
|
|
947
|
+
*
|
|
948
|
+
* @param {string} [startDir] - Directory to start searching from.
|
|
949
|
+
* @returns {string} Absolute path to the closest package directory.
|
|
950
|
+
*/
|
|
951
|
+
declare const getClosestPackageDir: (startDir?: string) => Promise<string>;
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* DeepNonNullable
|
|
955
|
+
*
|
|
956
|
+
* @description NonNullable that works for deeply nested structure
|
|
957
|
+
* @example
|
|
958
|
+
* type NestedProps = {
|
|
959
|
+
* first?: null | {
|
|
960
|
+
* second?: null | {
|
|
961
|
+
* name?: string | null |
|
|
962
|
+
* undefined;
|
|
963
|
+
* };
|
|
964
|
+
* };
|
|
965
|
+
* };
|
|
966
|
+
* type RequiredNestedProps = DeepNonNullable<NestedProps>;
|
|
967
|
+
* // Expect: {
|
|
968
|
+
* // first: {
|
|
969
|
+
* // second: {
|
|
970
|
+
* // name: string;
|
|
971
|
+
* // };
|
|
972
|
+
* // };
|
|
973
|
+
* // }
|
|
974
|
+
*/
|
|
975
|
+
type DeepNonNullable<T> = Prettify<_DeepNonNullable<T>>;
|
|
976
|
+
type _DeepNonNullable<T> = T extends (...args: AnyArray) => Any ? T : T extends AnyArray ? Prettify<Array<_DeepNonNullable<NonNullable<T[number]>>>> : T extends object ? Prettify<{
|
|
977
|
+
[P in keyof T]-?: _DeepNonNullable<NonNullable<T[P]>>;
|
|
978
|
+
}> : Prettify<NonNullable<T>>;
|
|
979
|
+
|
|
980
|
+
type ReturnAwaitedType<T extends (...args: Any) => Any> = Awaited<ReturnType<T>>;
|
|
981
|
+
type Response<V> = Promise<V> | V;
|
|
982
|
+
type GetResponse<T> = T extends (...args: Any[]) => infer R ? Awaited<R> : T;
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* DeepRequired
|
|
986
|
+
*
|
|
987
|
+
* @description Required that works for deeply nested structure
|
|
988
|
+
* @example
|
|
989
|
+
* type NestedProps = {
|
|
990
|
+
* first?: {
|
|
991
|
+
* second?: {
|
|
992
|
+
* name?: string;
|
|
993
|
+
* };
|
|
994
|
+
* };
|
|
995
|
+
* };
|
|
996
|
+
* type RequiredNestedProps = DeepRequired<NestedProps>
|
|
997
|
+
* // Expect: {
|
|
998
|
+
* // first: {
|
|
999
|
+
* // second: {
|
|
1000
|
+
* // name: string;
|
|
1001
|
+
* // };
|
|
1002
|
+
* // };
|
|
1003
|
+
* // }
|
|
1004
|
+
*/
|
|
1005
|
+
type DeepRequired<T> = Prettify<_DeepRequired<T>>;
|
|
1006
|
+
type _DeepRequired<T> = T extends (...args: AnyArray) => Any ? T : T extends AnyArray ? Prettify<_DeepRequiredArray<T[number]>> : T extends object ? Prettify<_DeepRequiredObject<T>> : T;
|
|
1007
|
+
type _DeepRequiredArray<T> = Array<_DeepRequired<NonUndefined<T>>>;
|
|
1008
|
+
type _DeepRequiredObject<T> = {
|
|
1009
|
+
[P in keyof T]-?: _DeepRequired<NonUndefined<T[P]>>;
|
|
1010
|
+
};
|
|
1011
|
+
|
|
1012
|
+
export { arePathsEqual, box, cache, catchExecOutput, color, columns, copyDir, copyFile, createDir, createSymlink, ensureDir, env, exec, execChild, existsDir, existsFile, existsLocalBin, existsLocalBins, existsPath, getAbsolutePath, getArch, getBaseName, getClosestPackageDir, getClosestPackageJson, getContentDir, getCurrentDir, getDirName, getExtName, getFilteredFileNames, getHomeDir, getObjectFromJSONFile, getPaths, getPlatform, getStringType, getSystemEnvPaths, getTempDir, gradient, isAbsolutePath, isBrowser, isBun, isDeno, isDev, isDirectory, isJsDom, isNode, isPath, isWebWorker, joinPath, joinUrl, line, normalizePath, object2string, prompt, readDir, readFile, relativePath, removeDir, removeDirIfExist, removeFile, removeFileIfExist, removePathIfExist, replacePlaceholders, resolvePath, table, truncate, validateHomeDir, writeFile, writeFileContent };
|
|
1013
|
+
export type { Any, AnyArray, AssertEqual, CommonObj, ContentInput, CopyDirOptions, DeepNonNullable, DeepPartial, DeepRequired, EmptyObject, ExpectEqual, FunctionKeys, GetResponse, NonFunctionKeys, NonUndefined, ObjectKeys, ObjectToArray, ObjectValues, Prettify, Response, ReturnAwaitedType, SingleChar };
|