@kikiutils/shared 18.2.0 → 19.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -7
- package/dist/buffer.d.ts +0 -2
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +1 -2
- package/dist/classes/enhanced-date.d.ts +0 -2
- package/dist/classes/enhanced-date.d.ts.map +1 -1
- package/dist/classes/enhanced-date.js +1 -2
- package/dist/classes/path.d.ts +2 -3
- package/dist/classes/path.d.ts.map +1 -1
- package/dist/classes/path.js +1 -2
- package/dist/classes/precision-number.d.ts +0 -2
- package/dist/classes/precision-number.d.ts.map +1 -1
- package/dist/classes/precision-number.js +1 -2
- package/dist/clipboard.d.ts +1 -2
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js +1 -2
- package/dist/crypto-hash.d.ts +0 -2
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +1 -2
- package/dist/datetime.d.ts +0 -2
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +1 -2
- package/dist/element-plus.d.ts +0 -2
- package/dist/element-plus.d.ts.map +1 -1
- package/dist/element-plus.js +1 -2
- package/dist/enum.d.ts +0 -2
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js +1 -2
- package/dist/env.d.ts +0 -2
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +1 -2
- package/dist/event-awaiter.d.ts +0 -2
- package/dist/event-awaiter.d.ts.map +1 -1
- package/dist/event-awaiter.js +1 -2
- package/dist/file.d.ts +25 -0
- package/dist/file.d.ts.map +1 -0
- package/dist/file.js +30 -0
- package/dist/file.js.map +1 -0
- package/dist/general.d.ts +0 -2
- package/dist/general.d.ts.map +1 -1
- package/dist/general.js +1 -2
- package/dist/hash.d.ts +0 -2
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +1 -2
- package/dist/logger/_internals/formatter.d.ts +13 -0
- package/dist/logger/_internals/formatter.d.ts.map +1 -0
- package/dist/logger/_internals/formatter.js +57 -0
- package/dist/logger/_internals/formatter.js.map +1 -0
- package/dist/logger/_internals/levels.d.ts +54 -0
- package/dist/logger/_internals/levels.d.ts.map +1 -0
- package/dist/logger/_internals/levels.js +59 -0
- package/dist/logger/_internals/levels.js.map +1 -0
- package/dist/logger/_internals/logger.d.ts +12 -0
- package/dist/logger/_internals/logger.d.ts.map +1 -0
- package/dist/logger/_internals/logger.js +147 -0
- package/dist/logger/_internals/logger.js.map +1 -0
- package/dist/logger/_internals/types.d.ts +12 -0
- package/dist/logger/_internals/types.d.ts.map +1 -0
- package/dist/logger/_internals/types.js +1 -0
- package/dist/logger/index.d.ts +10 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +25 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/node/_internals/file-writer.d.ts +11 -0
- package/dist/logger/node/_internals/file-writer.d.ts.map +1 -0
- package/dist/logger/node/_internals/file-writer.js +188 -0
- package/dist/logger/node/_internals/file-writer.js.map +1 -0
- package/dist/logger/node/_internals/formatter.d.ts +4 -0
- package/dist/logger/node/_internals/formatter.d.ts.map +1 -0
- package/dist/logger/node/_internals/formatter.js +21 -0
- package/dist/logger/node/_internals/formatter.js.map +1 -0
- package/dist/logger/node/index.d.ts +10 -0
- package/dist/logger/node/index.d.ts.map +1 -0
- package/dist/logger/node/index.js +122 -0
- package/dist/logger/node/index.js.map +1 -0
- package/dist/logger/node/types.d.ts +43 -0
- package/dist/logger/node/types.d.ts.map +1 -0
- package/dist/logger/node/types.js +1 -0
- package/dist/logger/types.d.ts +49 -0
- package/dist/logger/types.d.ts.map +1 -0
- package/dist/logger/types.js +1 -0
- package/dist/math.d.ts +1 -2
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +1 -2
- package/dist/number.d.ts +0 -2
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +1 -2
- package/dist/random.d.ts +0 -2
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js +1 -2
- package/dist/redis/script-runner.d.ts +0 -2
- package/dist/redis/script-runner.d.ts.map +1 -1
- package/dist/redis/script-runner.js +1 -2
- package/dist/storages/lru/keyed-store.d.ts +2 -2
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.js +6 -3
- package/dist/storages/lru/keyed-store.js.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +0 -2
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.js +1 -2
- package/dist/storages/redis/msgpack.d.ts +0 -2
- package/dist/storages/redis/msgpack.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.js +1 -2
- package/dist/storages/redis/types.d.ts +0 -2
- package/dist/storages/redis/types.d.ts.map +1 -1
- package/dist/string.d.ts +0 -2
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +1 -2
- package/dist/time.d.ts +0 -2
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +1 -2
- package/dist/types/filtered-key-path.d.ts +1 -2
- package/dist/types/filtered-key-path.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/vue.d.ts +0 -2
- package/dist/types/vue.d.ts.map +1 -1
- package/dist/url.d.ts +0 -2
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +1 -2
- package/dist/vue.d.ts +0 -2
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +1 -2
- package/dist/web.d.ts +0 -2
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +1 -2
- package/package.json +78 -45
- package/src/file.ts +37 -0
- package/src/logger/_internals/formatter.ts +80 -0
- package/src/logger/_internals/levels.ts +60 -0
- package/src/logger/_internals/logger.ts +224 -0
- package/src/logger/_internals/types.ts +12 -0
- package/src/logger/index.ts +34 -0
- package/src/logger/node/_internals/file-writer.ts +298 -0
- package/src/logger/node/_internals/formatter.ts +33 -0
- package/src/logger/node/index.ts +175 -0
- package/src/logger/node/types.ts +58 -0
- package/src/logger/types.ts +59 -0
- package/src/storages/lru/keyed-store.ts +4 -0
- package/src/types/index.ts +0 -10
- package/dist/classes/ssh-client.d.ts +0 -39
- package/dist/classes/ssh-client.d.ts.map +0 -1
- package/dist/classes/ssh-client.js +0 -130
- package/dist/classes/ssh-client.js.map +0 -1
- package/dist/consola.d.ts +0 -24
- package/dist/consola.d.ts.map +0 -1
- package/dist/consola.js +0 -29
- package/dist/consola.js.map +0 -1
- package/dist/object.d.ts +0 -44
- package/dist/object.d.ts.map +0 -1
- package/dist/object.js +0 -59
- package/dist/object.js.map +0 -1
- package/dist/pino.d.ts +0 -25
- package/dist/pino.d.ts.map +0 -1
- package/dist/pino.js +0 -34
- package/dist/pino.js.map +0 -1
- package/src/classes/ssh-client.ts +0 -175
- package/src/consola.ts +0 -25
- package/src/object.ts +0 -78
- package/src/pino.ts +0 -33
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { writeSync } from 'node:fs';
|
|
2
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
3
|
+
|
|
4
|
+
import { supportsLoggerColor } from '../_internals/formatter';
|
|
5
|
+
import { getLoggerStreamName } from '../_internals/levels';
|
|
6
|
+
import {
|
|
7
|
+
createDiagnosticReporter,
|
|
8
|
+
createLoggerCore,
|
|
9
|
+
} from '../_internals/logger';
|
|
10
|
+
import type { LoggerDiagnostic } from '../types';
|
|
11
|
+
|
|
12
|
+
import { createFileWriter } from './_internals/file-writer';
|
|
13
|
+
import { formatNodeLoggerRecord } from './_internals/formatter';
|
|
14
|
+
import type {
|
|
15
|
+
NodeLogger,
|
|
16
|
+
NodeLoggerOptions,
|
|
17
|
+
} from './types';
|
|
18
|
+
|
|
19
|
+
interface ConsoleStreamState {
|
|
20
|
+
onClose: () => void;
|
|
21
|
+
onError: (error: Error) => void;
|
|
22
|
+
owners: Set<object>;
|
|
23
|
+
pending: Set<(error?: Error | null) => void>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Constants/Variables
|
|
27
|
+
const consoleStreams = new WeakMap<NodeJS.WriteStream, ConsoleStreamState>();
|
|
28
|
+
|
|
29
|
+
// Functions
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates a Node.js/Bun logger with optional bounded, append-only file output and rotation.
|
|
33
|
+
*
|
|
34
|
+
* Log calls never throw or reject. Awaiting them waits for processing, not proof of successful
|
|
35
|
+
* persistence: overload drops the newest file record and failures are reported safely. Factory
|
|
36
|
+
* validation/open failures reject. Call close explicitly; no process signal handlers are installed.
|
|
37
|
+
*/
|
|
38
|
+
export async function createNodeLogger(options: NodeLoggerOptions = {}): Promise<NodeLogger> {
|
|
39
|
+
const report = createDiagnosticReporter(options.onError, (message) => writeSync(2, message));
|
|
40
|
+
let writer: Awaited<ReturnType<typeof createFileWriter>> | undefined;
|
|
41
|
+
let closed = false;
|
|
42
|
+
let closePromise: Promise<void> | undefined;
|
|
43
|
+
const consoleOwner = {};
|
|
44
|
+
const consoleTargets = new Set<NodeJS.WriteStream>();
|
|
45
|
+
const consoleWrites = new Set<Promise<void>>();
|
|
46
|
+
const logger = createLoggerCore(
|
|
47
|
+
options,
|
|
48
|
+
{
|
|
49
|
+
report,
|
|
50
|
+
write(record) {
|
|
51
|
+
if (closed) {
|
|
52
|
+
report({
|
|
53
|
+
message: 'Logger is closed.',
|
|
54
|
+
type: 'closed',
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!record.console && !writer) return;
|
|
61
|
+
const target = process[getLoggerStreamName(record.type)];
|
|
62
|
+
|
|
63
|
+
const text = formatNodeLoggerRecord(record, record.console && supportsLoggerColor(target));
|
|
64
|
+
if (record.console) {
|
|
65
|
+
const line = `${text}\n`;
|
|
66
|
+
consoleTargets.add(target);
|
|
67
|
+
const completion = writeConsole(target, line, report, consoleOwner);
|
|
68
|
+
consoleWrites.add(completion);
|
|
69
|
+
void completion.then(() => consoleWrites.delete(completion));
|
|
70
|
+
const fileCompletion = writer?.write(`${stripVTControlCharacters(text)}\n`);
|
|
71
|
+
return fileCompletion
|
|
72
|
+
? Promise.all([
|
|
73
|
+
completion,
|
|
74
|
+
fileCompletion,
|
|
75
|
+
]).then(() => {})
|
|
76
|
+
: completion;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return writer?.write(`${stripVTControlCharacters(text)}\n`);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (options.file !== undefined && options.file !== false) writer = await createFileWriter(options.file, report);
|
|
85
|
+
|
|
86
|
+
return Object.assign(
|
|
87
|
+
logger,
|
|
88
|
+
{
|
|
89
|
+
close() {
|
|
90
|
+
if (closePromise) return closePromise;
|
|
91
|
+
closed = true;
|
|
92
|
+
closePromise = (async () => {
|
|
93
|
+
await Promise.all([
|
|
94
|
+
writer?.close(),
|
|
95
|
+
...consoleWrites,
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
for (const target of consoleTargets) {
|
|
99
|
+
const state = consoleStreams.get(target);
|
|
100
|
+
if (!state) continue;
|
|
101
|
+
state.owners.delete(consoleOwner);
|
|
102
|
+
if (!state.owners.size) {
|
|
103
|
+
target.off('error', state.onError);
|
|
104
|
+
target.off('close', state.onClose);
|
|
105
|
+
consoleStreams.delete(target);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
consoleTargets.clear();
|
|
110
|
+
})();
|
|
111
|
+
return closePromise;
|
|
112
|
+
},
|
|
113
|
+
getStats: () => writer?.getStats() ?? {
|
|
114
|
+
droppedCount: 0,
|
|
115
|
+
pendingBytes: 0,
|
|
116
|
+
writeErrorCount: 0,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** One error listener per shared output stream; retained until its last owning logger calls close(). */
|
|
123
|
+
function writeConsole(
|
|
124
|
+
target: NodeJS.WriteStream,
|
|
125
|
+
text: string,
|
|
126
|
+
report: (event: LoggerDiagnostic) => void,
|
|
127
|
+
owner: object,
|
|
128
|
+
) {
|
|
129
|
+
let state = consoleStreams.get(target);
|
|
130
|
+
if (!state) {
|
|
131
|
+
const pending = new Set<(error?: Error | null) => void>();
|
|
132
|
+
const onError = (error: Error) => {
|
|
133
|
+
for (const settle of pending) settle(error);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const onClose = () => onError(new Error('Console stream closed.'));
|
|
137
|
+
state = {
|
|
138
|
+
onClose,
|
|
139
|
+
onError,
|
|
140
|
+
owners: new Set(),
|
|
141
|
+
pending,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
consoleStreams.set(target, state);
|
|
145
|
+
target.on('error', onError);
|
|
146
|
+
target.on('close', onClose);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
state.owners.add(owner);
|
|
150
|
+
const current = state;
|
|
151
|
+
return new Promise<void>((resolveWritten) => {
|
|
152
|
+
let settled = false;
|
|
153
|
+
const settle = (error?: Error | null) => {
|
|
154
|
+
if (settled) return;
|
|
155
|
+
settled = true;
|
|
156
|
+
current.pending.delete(settle);
|
|
157
|
+
if (error) {
|
|
158
|
+
report({
|
|
159
|
+
error,
|
|
160
|
+
message: 'Console output failed.',
|
|
161
|
+
type: 'console',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
resolveWritten();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
current.pending.add(settle);
|
|
169
|
+
try {
|
|
170
|
+
target.write(text, settle);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
settle(error instanceof Error ? error : new Error('Console output failed.'));
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PathLike } from '../../classes/path';
|
|
2
|
+
import type {
|
|
3
|
+
Logger,
|
|
4
|
+
LoggerOptions,
|
|
5
|
+
} from '../types';
|
|
6
|
+
|
|
7
|
+
/** Specify interval and/or maxSize. Size limits use positive integers with B, K, M, or G (binary units). */
|
|
8
|
+
export type LoggerRotationOptions = {
|
|
9
|
+
/** Gzip historical files. Defaults to true. */
|
|
10
|
+
compress?: boolean;
|
|
11
|
+
|
|
12
|
+
/** Number of historical files, excluding the active file. Defaults to 30. */
|
|
13
|
+
keepFiles?: number;
|
|
14
|
+
|
|
15
|
+
/** Maximum combined size of historical files. */
|
|
16
|
+
maxTotalSize?: string;
|
|
17
|
+
} & (
|
|
18
|
+
| {
|
|
19
|
+
/** Opt-in time rotation aligned to the system's local calendar boundary. */
|
|
20
|
+
interval: 'daily' | 'hourly';
|
|
21
|
+
maxSize?: string;
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
/** Opt-in time rotation aligned to the system's local calendar boundary. */
|
|
25
|
+
interval?: 'daily' | 'hourly';
|
|
26
|
+
maxSize: string;
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export interface LoggerFileOptions {
|
|
31
|
+
/** Maximum unfinished payload bytes, including data already submitted to the stream. */
|
|
32
|
+
maxPendingBytes?: number;
|
|
33
|
+
|
|
34
|
+
/** Resolved once at creation. The file is opened in append mode. */
|
|
35
|
+
path: PathLike;
|
|
36
|
+
|
|
37
|
+
/** Omitted or false disables rotation. An object must specify interval or maxSize. */
|
|
38
|
+
rotate?: false | LoggerRotationOptions;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface NodeLogger extends Logger {
|
|
42
|
+
/** Stop accepting records, finish accepted file writes, then release the stream. Not fsync. */
|
|
43
|
+
close: () => Promise<void>;
|
|
44
|
+
|
|
45
|
+
/** A fresh snapshot. Dropped/failed records still resolve their logging promises. */
|
|
46
|
+
getStats: () => NodeLoggerStats;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface NodeLoggerOptions extends LoggerOptions {
|
|
50
|
+
/** Disabled by default. Each logger owns at most one fixed file destination. */
|
|
51
|
+
file?: false | LoggerFileOptions;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface NodeLoggerStats {
|
|
55
|
+
droppedCount: number;
|
|
56
|
+
pendingBytes: number;
|
|
57
|
+
writeErrorCount: number;
|
|
58
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Minimum severity to emit; `success` uses the same threshold as `info`. */
|
|
2
|
+
export type LoggerLevel = 'debug' | 'error' | 'fatal' | 'info' | 'silent' | 'trace' | 'warn';
|
|
3
|
+
|
|
4
|
+
/** A logging method, including the informational success presentation. */
|
|
5
|
+
export type LoggerMethod = 'success' | Exclude<LoggerLevel, 'silent'>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A logger whose logging methods never throw or reject for recoverable failures.
|
|
9
|
+
*
|
|
10
|
+
* Awaiting a method waits for processing, not guaranteed successful delivery or fsync.
|
|
11
|
+
* Configuration errors may throw from the factory, configure(), or setLevel().
|
|
12
|
+
*/
|
|
13
|
+
export interface Logger {
|
|
14
|
+
configure: (options: Pick<LoggerOptions, 'console' | 'icons' | 'prefix' | 'suffix' | 'timestamp'>) => void;
|
|
15
|
+
debug: (...args: unknown[]) => Promise<void>;
|
|
16
|
+
error: (...args: unknown[]) => Promise<void>;
|
|
17
|
+
fatal: (...args: unknown[]) => Promise<void>;
|
|
18
|
+
info: (...args: unknown[]) => Promise<void>;
|
|
19
|
+
|
|
20
|
+
/** Accepts success as an informational method; it is not a configurable threshold. */
|
|
21
|
+
isLevelEnabled: (level: LoggerLevel | LoggerMethod) => boolean;
|
|
22
|
+
|
|
23
|
+
/** Sets a severity threshold (not success); env restores environment-driven filtering. */
|
|
24
|
+
setLevel: (level: 'env' | LoggerLevel) => void;
|
|
25
|
+
success: (...args: unknown[]) => Promise<void>;
|
|
26
|
+
trace: (...args: unknown[]) => Promise<void>;
|
|
27
|
+
warn: (...args: unknown[]) => Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A recoverable logging failure, reported without throwing from log methods. */
|
|
31
|
+
export interface LoggerDiagnostic {
|
|
32
|
+
droppedCount?: number;
|
|
33
|
+
error?: unknown;
|
|
34
|
+
message: string;
|
|
35
|
+
|
|
36
|
+
/** Same-type notifications suppressed since the previous emitted diagnostic. */
|
|
37
|
+
suppressedCount?: number;
|
|
38
|
+
type: 'closed' | 'console' | 'file' | 'format' | 'invalid-level' | 'overflow';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Configuration shared by browser and server loggers. */
|
|
42
|
+
export interface LoggerOptions {
|
|
43
|
+
/** Enables console output. Defaults to `true`. */
|
|
44
|
+
console?: boolean;
|
|
45
|
+
|
|
46
|
+
/** Enables Unicode level icons. Defaults to `true`. */
|
|
47
|
+
icons?: boolean;
|
|
48
|
+
|
|
49
|
+
/** Overrides LOG_LEVEL; `env` restores the environment-driven threshold. */
|
|
50
|
+
level?: 'env' | LoggerLevel;
|
|
51
|
+
|
|
52
|
+
/** Best-effort, rate-limited notification; failures in this callback are contained. */
|
|
53
|
+
onError?: (event: LoggerDiagnostic) => void;
|
|
54
|
+
prefix?: string;
|
|
55
|
+
suffix?: string;
|
|
56
|
+
|
|
57
|
+
/** Enables the fixed local-time millisecond prefix. Defaults to `true`. */
|
|
58
|
+
timestamp?: boolean;
|
|
59
|
+
}
|
|
@@ -7,6 +7,7 @@ import type { LRUCache } from 'lru-cache';
|
|
|
7
7
|
* The key resolver is called synchronously once per operation, and its exceptions propagate.
|
|
8
8
|
* Reads return the cached value without copying it, or `null` for missing or nullish values.
|
|
9
9
|
* `getItemTtl` exposes the underlying remaining TTL in milliseconds; `setItem` returns the underlying cache.
|
|
10
|
+
* `setItemWithTtl` accepts its TTL in milliseconds before the value and key arguments and returns the cache.
|
|
10
11
|
* The facade does not dispose the supplied cache, and LRU defaults remain those of the supplied instance.
|
|
11
12
|
*
|
|
12
13
|
* @typeParam D - The stored value type used by reads and writes.
|
|
@@ -46,5 +47,8 @@ export function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<any, any,
|
|
|
46
47
|
*/
|
|
47
48
|
resolveKey: (...args: P) => keyFn(...args),
|
|
48
49
|
setItem: (value: D, ...args: P) => lruInstance.set(keyFn(...args), value),
|
|
50
|
+
setItemWithTtl(ttlMilliseconds: number, value: D, ...args: P) {
|
|
51
|
+
return lruInstance.set(keyFn(...args), value, { ttl: ttlMilliseconds });
|
|
52
|
+
},
|
|
49
53
|
});
|
|
50
54
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -6,11 +6,6 @@ import type {
|
|
|
6
6
|
|
|
7
7
|
export type { FilteredKeyPath } from './filtered-key-path';
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* A generic string-keyed object for utility APIs that intentionally accept any value shape.
|
|
11
|
-
*/
|
|
12
|
-
export type AnyRecord = Record<string, any>;
|
|
13
|
-
|
|
14
9
|
/**
|
|
15
10
|
* Binary-like inputs accepted by `toBuffer` across browser and Node.js runtimes.
|
|
16
11
|
*/
|
|
@@ -31,11 +26,6 @@ export type MaybePartial<T> = Partial<T> | T;
|
|
|
31
26
|
*/
|
|
32
27
|
export type MaybeReadonly<T> = Readonly<T> | T;
|
|
33
28
|
|
|
34
|
-
/**
|
|
35
|
-
* Number-like value represented as a number or a numeric string.
|
|
36
|
-
*/
|
|
37
|
-
export type Numberish = number | string;
|
|
38
|
-
|
|
39
29
|
/**
|
|
40
30
|
* A `Record` where every key is optional.
|
|
41
31
|
*/
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { PathLike } from "./path.js";
|
|
2
|
-
import { Config, NodeSSH, SSHExecCommandOptions, SSHGetPutDirectoryOptions, SSHPutFilesOptions } from "node-ssh";
|
|
3
|
-
import { SFTPWrapper, TransferOptions } from "ssh2";
|
|
4
|
-
//#region src/classes/ssh-client.d.ts
|
|
5
|
-
declare const loggerLevelStringToConsolaLogLevelMap: {
|
|
6
|
-
readonly debug: 4;
|
|
7
|
-
readonly error: 0;
|
|
8
|
-
readonly fatal: 0;
|
|
9
|
-
readonly info: 3;
|
|
10
|
-
readonly normal: 2;
|
|
11
|
-
readonly silent: -999;
|
|
12
|
-
readonly trace: 5;
|
|
13
|
-
readonly verbose: 999;
|
|
14
|
-
readonly warn: 1;
|
|
15
|
-
};
|
|
16
|
-
export declare class SshClient {
|
|
17
|
-
#private;
|
|
18
|
-
getDir: (localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) => Promise<boolean>;
|
|
19
|
-
putDir: (localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) => Promise<boolean>;
|
|
20
|
-
constructor(host: string, username: string, password: string, port?: number, connectConfig?: Config);
|
|
21
|
-
get nodeSsh(): NodeSSH;
|
|
22
|
-
connect(): Promise<boolean>;
|
|
23
|
-
disconnect(): boolean;
|
|
24
|
-
execCommand(command: string, options?: SSHExecCommandOptions): Promise<void | import("node-ssh").SSHExecCommandResponse>;
|
|
25
|
-
execCommandWithIo(command: string, options?: SSHExecCommandOptions): Promise<void | import("node-ssh").SSHExecCommandResponse>;
|
|
26
|
-
getDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions): Promise<boolean>;
|
|
27
|
-
getFile(localFile: PathLike, remoteFile: PathLike, givenSftp?: null | SFTPWrapper, transferOptions?: null | TransferOptions): Promise<boolean>;
|
|
28
|
-
isConnected(): boolean;
|
|
29
|
-
mkdir(path: PathLike): Promise<boolean>;
|
|
30
|
-
putDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions): Promise<boolean>;
|
|
31
|
-
putFile(localFile: PathLike, remoteFile: PathLike, givenSftp?: null | SFTPWrapper, transferOptions?: null | TransferOptions): Promise<boolean>;
|
|
32
|
-
putFiles(files: {
|
|
33
|
-
local: PathLike;
|
|
34
|
-
remote: PathLike;
|
|
35
|
-
}[], options?: SSHPutFilesOptions): Promise<boolean>;
|
|
36
|
-
setLoggerLevel(level: keyof typeof loggerLevelStringToConsolaLogLevelMap): void;
|
|
37
|
-
}
|
|
38
|
-
//#endregion
|
|
39
|
-
//# sourceMappingURL=ssh-client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ssh-client.d.ts","names":[],"sources":["../../src/classes/ssh-client.ts"],"mappings":";;;;cAgBM;;;;;;;;;;;qBAYO;;EAOT,SAAM,gBA2D6B,UAAQ,iBAAmB,UAAQ,UAAY,8BAAyB;EA1D3G,SAAM,gBAgG6B,UAAQ,iBAAmB,UAAQ,UAAY,8BAAyB;EA7F/F,YAAA,cAAc,kBAAkB,kBAAkB,eAAmB,gBAAgB;MAe7F,WAAO;EAKL,WAAO;EAUb;EAUA,YAAY,iBAAiB,UAAU,wBAAqB,kCAAA;EAI5D,kBAAkB,iBAAiB,UAAU,wBAAqB,kCAAA;EAW5D,aAAa,gBAAgB,UAAU,iBAAiB,UAAU,UAAU,4BAAyB;EASrG,QACF,WAAW,UACX,YAAY,UACZ,mBAAmB,aACnB,yBAAyB,kBAAe;EAW5C;EAIM,MAAM,MAAM,WAAQ;EAUpB,aAAa,gBAAgB,UAAU,iBAAiB,UAAU,UAAU,4BAAyB;EASrG,QACF,WAAW,UACX,YAAY,UACZ,mBAAmB,aACnB,yBAAyB,kBAAe;EAWtC,SAAS;IAAS,OAAO;IAAU,QAAQ;OAAc,UAAU,qBAAkB;EAe3F,eAAe,oBAAoB"}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { createConsola } from "consola";
|
|
2
|
-
import { NodeSSH } from "node-ssh";
|
|
3
|
-
//#region src/classes/ssh-client.ts
|
|
4
|
-
const loggerLevelStringToConsolaLogLevelMap = {
|
|
5
|
-
debug: 4,
|
|
6
|
-
error: 0,
|
|
7
|
-
fatal: 0,
|
|
8
|
-
info: 3,
|
|
9
|
-
normal: 2,
|
|
10
|
-
silent: -999,
|
|
11
|
-
trace: 5,
|
|
12
|
-
verbose: 999,
|
|
13
|
-
warn: 1
|
|
14
|
-
};
|
|
15
|
-
var SshClient = class {
|
|
16
|
-
#connectConfig;
|
|
17
|
-
#logger;
|
|
18
|
-
#nodeSsh;
|
|
19
|
-
getDir = this.getDirectory;
|
|
20
|
-
putDir = this.putDirectory;
|
|
21
|
-
constructor(host, username, password, port = 22, connectConfig) {
|
|
22
|
-
this.#connectConfig = {
|
|
23
|
-
...connectConfig,
|
|
24
|
-
host,
|
|
25
|
-
password,
|
|
26
|
-
port,
|
|
27
|
-
username
|
|
28
|
-
};
|
|
29
|
-
this.#logger = createConsola();
|
|
30
|
-
this.#nodeSsh = new NodeSSH();
|
|
31
|
-
if (process.env.NODE_ENV === "production") this.setLoggerLevel("error");
|
|
32
|
-
}
|
|
33
|
-
get nodeSsh() {
|
|
34
|
-
return this.#nodeSsh;
|
|
35
|
-
}
|
|
36
|
-
async connect() {
|
|
37
|
-
try {
|
|
38
|
-
this.#nodeSsh = await this.#nodeSsh.connect(this.#connectConfig);
|
|
39
|
-
return true;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
this.#logger.error(error);
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
disconnect() {
|
|
46
|
-
try {
|
|
47
|
-
this.#nodeSsh.dispose();
|
|
48
|
-
return true;
|
|
49
|
-
} catch (error) {
|
|
50
|
-
this.#logger.error(error);
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
execCommand(command, options) {
|
|
55
|
-
return this.#nodeSsh.execCommand(command, options).catch(() => {});
|
|
56
|
-
}
|
|
57
|
-
execCommandWithIo(command, options) {
|
|
58
|
-
return this.execCommand(command, {
|
|
59
|
-
...options,
|
|
60
|
-
onStderr: (data) => process.stderr.write(data.toString()),
|
|
61
|
-
onStdout: (data) => process.stdout.write(data.toString())
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
async getDirectory(localDirectory, remoteDirectory, options) {
|
|
65
|
-
try {
|
|
66
|
-
return await this.#nodeSsh.getDirectory(localDirectory.toString(), remoteDirectory.toString(), options);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
this.#logger.error(error);
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async getFile(localFile, remoteFile, givenSftp, transferOptions) {
|
|
73
|
-
try {
|
|
74
|
-
await this.#nodeSsh.getFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);
|
|
75
|
-
return true;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
this.#logger.error(error);
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
isConnected() {
|
|
82
|
-
return this.#nodeSsh.isConnected();
|
|
83
|
-
}
|
|
84
|
-
async mkdir(path) {
|
|
85
|
-
try {
|
|
86
|
-
await this.#nodeSsh.mkdir(path.toString());
|
|
87
|
-
return true;
|
|
88
|
-
} catch (error) {
|
|
89
|
-
this.#logger.error(error);
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async putDirectory(localDirectory, remoteDirectory, options) {
|
|
94
|
-
try {
|
|
95
|
-
return await this.#nodeSsh.putDirectory(localDirectory.toString(), remoteDirectory.toString(), options);
|
|
96
|
-
} catch (error) {
|
|
97
|
-
this.#logger.error(error);
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
async putFile(localFile, remoteFile, givenSftp, transferOptions) {
|
|
102
|
-
try {
|
|
103
|
-
await this.#nodeSsh.putFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);
|
|
104
|
-
return true;
|
|
105
|
-
} catch (error) {
|
|
106
|
-
this.#logger.error(error);
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
async putFiles(files, options) {
|
|
111
|
-
try {
|
|
112
|
-
const convertedFiles = files.map(({ local, remote }) => ({
|
|
113
|
-
local: local.toString(),
|
|
114
|
-
remote: remote.toString()
|
|
115
|
-
}));
|
|
116
|
-
await this.#nodeSsh.putFiles(convertedFiles, options);
|
|
117
|
-
return true;
|
|
118
|
-
} catch (error) {
|
|
119
|
-
this.#logger.error(error);
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
setLoggerLevel(level) {
|
|
124
|
-
this.#logger.level = loggerLevelStringToConsolaLogLevelMap[level];
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
//#endregion
|
|
128
|
-
export { SshClient };
|
|
129
|
-
|
|
130
|
-
//# sourceMappingURL=ssh-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ssh-client.js","names":[],"sources":["../../src/classes/ssh-client.ts"],"sourcesContent":["import { createConsola } from 'consola';\nimport type { ConsolaInstance } from 'consola';\nimport { NodeSSH } from 'node-ssh';\nimport type {\n Config,\n SSHExecCommandOptions,\n SSHGetPutDirectoryOptions,\n SSHPutFilesOptions,\n} from 'node-ssh';\nimport type {\n SFTPWrapper,\n TransferOptions,\n} from 'ssh2';\n\nimport type { PathLike } from './path';\n\nconst loggerLevelStringToConsolaLogLevelMap = {\n debug: 4,\n error: 0,\n fatal: 0,\n info: 3,\n normal: 2,\n silent: -999,\n trace: 5,\n verbose: 999,\n warn: 1,\n} as const;\n\nexport class SshClient {\n // Private instance properties\n readonly #connectConfig: Config;\n readonly #logger: ConsolaInstance;\n #nodeSsh: NodeSSH;\n\n // Public instance properties\n getDir = this.getDirectory;\n putDir = this.putDirectory;\n\n // Constructor\n constructor(host: string, username: string, password: string, port: number = 22, connectConfig?: Config) {\n this.#connectConfig = {\n ...connectConfig,\n host,\n password,\n port,\n username,\n };\n\n this.#logger = createConsola();\n this.#nodeSsh = new NodeSSH();\n if (process.env.NODE_ENV === 'production') this.setLoggerLevel('error');\n }\n\n // Public instance accessors\n get nodeSsh() {\n return this.#nodeSsh;\n }\n\n // Public instance methods\n async connect() {\n try {\n this.#nodeSsh = await this.#nodeSsh.connect(this.#connectConfig);\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n disconnect() {\n try {\n this.#nodeSsh.dispose();\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n execCommand(command: string, options?: SSHExecCommandOptions) {\n return this.#nodeSsh.execCommand(command, options).catch(() => {});\n }\n\n execCommandWithIo(command: string, options?: SSHExecCommandOptions) {\n return this.execCommand(\n command,\n {\n ...options,\n onStderr: (data) => process.stderr.write(data.toString()),\n onStdout: (data) => process.stdout.write(data.toString()),\n },\n );\n }\n\n async getDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) {\n try {\n return await this.#nodeSsh.getDirectory(localDirectory.toString(), remoteDirectory.toString(), options);\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n async getFile(\n localFile: PathLike,\n remoteFile: PathLike,\n givenSftp?: null | SFTPWrapper,\n transferOptions?: null | TransferOptions,\n ) {\n try {\n await this.#nodeSsh.getFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n isConnected() {\n return this.#nodeSsh.isConnected();\n }\n\n async mkdir(path: PathLike) {\n try {\n await this.#nodeSsh.mkdir(path.toString());\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n async putDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) {\n try {\n return await this.#nodeSsh.putDirectory(localDirectory.toString(), remoteDirectory.toString(), options);\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n async putFile(\n localFile: PathLike,\n remoteFile: PathLike,\n givenSftp?: null | SFTPWrapper,\n transferOptions?: null | TransferOptions,\n ) {\n try {\n await this.#nodeSsh.putFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n async putFiles(files: { local: PathLike; remote: PathLike }[], options?: SSHPutFilesOptions) {\n try {\n const convertedFiles = files.map(({ local, remote }) => ({\n local: local.toString(),\n remote: remote.toString(),\n }));\n\n await this.#nodeSsh.putFiles(convertedFiles, options);\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n setLoggerLevel(level: keyof typeof loggerLevelStringToConsolaLogLevelMap) {\n this.#logger.level = loggerLevelStringToConsolaLogLevelMap[level];\n }\n}\n"],"mappings":"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"}
|
package/dist/consola.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//#region src/consola.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* A consola logger with environment-controlled verbosity.
|
|
4
|
-
*
|
|
5
|
-
* @remarks
|
|
6
|
-
* `CONSOLA_LOGGER_LEVEL` sets the log level when defined at module initialization;
|
|
7
|
-
* otherwise, `NODE_ENV=production` selects `0`, and other environments retain the logger's default level.
|
|
8
|
-
* Assign `logger.level` to change verbosity after initialization.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { logger } from '@kikiutils/shared/consola';
|
|
14
|
-
*
|
|
15
|
-
* logger.level = 3;
|
|
16
|
-
* logger.info('Application started');
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @see {@link https://github.com/unjs/consola#log-level | Consola log levels}
|
|
20
|
-
*/
|
|
21
|
-
export declare const consolaLogger: import("consola").ConsolaInstance;
|
|
22
|
-
export declare const logger: import("consola").ConsolaInstance;
|
|
23
|
-
//#endregion
|
|
24
|
-
//# sourceMappingURL=consola.d.ts.map
|
package/dist/consola.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"consola.d.ts","names":[],"sources":["../src/consola.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;qBAqBa,iCAAa;qBACb,0BAAM"}
|
package/dist/consola.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { createConsola } from "consola";
|
|
2
|
-
//#region src/consola.ts
|
|
3
|
-
/**
|
|
4
|
-
* A consola logger with environment-controlled verbosity.
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* `CONSOLA_LOGGER_LEVEL` sets the log level when defined at module initialization;
|
|
8
|
-
* otherwise, `NODE_ENV=production` selects `0`, and other environments retain the logger's default level.
|
|
9
|
-
* Assign `logger.level` to change verbosity after initialization.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { logger } from '@kikiutils/shared/consola';
|
|
15
|
-
*
|
|
16
|
-
* logger.level = 3;
|
|
17
|
-
* logger.info('Application started');
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @see {@link https://github.com/unjs/consola#log-level | Consola log levels}
|
|
21
|
-
*/
|
|
22
|
-
const consolaLogger = createConsola();
|
|
23
|
-
const logger = consolaLogger;
|
|
24
|
-
if (process.env.CONSOLA_LOGGER_LEVEL !== void 0) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;
|
|
25
|
-
else consolaLogger.level = process.env.NODE_ENV === "production" ? 0 : consolaLogger.level;
|
|
26
|
-
//#endregion
|
|
27
|
-
export { consolaLogger, logger };
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=consola.js.map
|
package/dist/consola.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"consola.js","names":[],"sources":["../src/consola.ts"],"sourcesContent":["import { createConsola } from 'consola';\n\n/**\n * A consola logger with environment-controlled verbosity.\n *\n * @remarks\n * `CONSOLA_LOGGER_LEVEL` sets the log level when defined at module initialization;\n * otherwise, `NODE_ENV=production` selects `0`, and other environments retain the logger's default level.\n * Assign `logger.level` to change verbosity after initialization.\n *\n * @example\n *\n * ```ts\n * import { logger } from '@kikiutils/shared/consola';\n *\n * logger.level = 3;\n * logger.info('Application started');\n * ```\n *\n * @see {@link https://github.com/unjs/consola#log-level | Consola log levels}\n */\nexport const consolaLogger = createConsola();\nexport const logger = consolaLogger;\nif (process.env.CONSOLA_LOGGER_LEVEL !== undefined) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;\nelse consolaLogger.level = process.env.NODE_ENV === 'production' ? 0 : consolaLogger.level;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,gBAAgB,cAAc;AAC3C,MAAa,SAAS;AACtB,IAAI,QAAQ,IAAI,yBAAyB,KAAA,GAAW,cAAc,QAAQ,CAAC,QAAQ,IAAI;KAClF,cAAc,QAAQ,QAAQ,IAAI,aAAa,eAAe,IAAI,cAAc"}
|
package/dist/object.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
//#region src/object.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Serializes a nested object into a deterministic, flat string format.
|
|
4
|
-
*
|
|
5
|
-
* @remarks
|
|
6
|
-
* This function recursively traverses the input object (including nested objects and arrays),
|
|
7
|
-
* flattens it into key paths using dot notation (e.g. "a.b.0.c"), sorts all keys,
|
|
8
|
-
* and joins each key-value pair into a string with customizable separators.
|
|
9
|
-
*
|
|
10
|
-
* It is designed for use cases such as signature generation, cache key construction,
|
|
11
|
-
* or any context requiring consistent and predictable object serialization.
|
|
12
|
-
*
|
|
13
|
-
* Note: Empty objects and arrays produce an empty string, which is useful for
|
|
14
|
-
* generating deterministic signature payloads.
|
|
15
|
-
*
|
|
16
|
-
* @param input - The object to serialize. Can contain nested objects and arrays.
|
|
17
|
-
* @param kvSeparator - The string used to separate each key from its value (default: '=').
|
|
18
|
-
* @param pairSeparator - The string used to separate each key-value pair (default: '&').
|
|
19
|
-
*
|
|
20
|
-
* @returns A deterministic string representation of the input object.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
*
|
|
24
|
-
* ```ts
|
|
25
|
-
* import { stringifyObjectDeterministically } from '@kikiutils/shared/object';
|
|
26
|
-
*
|
|
27
|
-
* console.log(stringifyObjectDeterministically({
|
|
28
|
-
* b: 2,
|
|
29
|
-
* a: {
|
|
30
|
-
* x: 1,
|
|
31
|
-
* y: [
|
|
32
|
-
* 3,
|
|
33
|
-
* 4,
|
|
34
|
-
* ],
|
|
35
|
-
* },
|
|
36
|
-
* })); // => a.x=1&a.y.0=3&a.y.1=4&b=2
|
|
37
|
-
*
|
|
38
|
-
* console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // => foo:bar
|
|
39
|
-
* console.log(stringifyObjectDeterministically({})); // => ''
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function stringifyObjectDeterministically(input: Record<string, any>, kvSeparator?: string, pairSeparator?: string): string;
|
|
43
|
-
//#endregion
|
|
44
|
-
//# sourceMappingURL=object.d.ts.map
|
package/dist/object.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","names":[],"sources":["../src/object.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCgB,iCACZ,OAAO,qBACP,sBACA"}
|