@easbot/utils 0.1.7

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.
@@ -0,0 +1,468 @@
1
+ import z, { z as z$1 } from 'zod';
2
+ import { statSync } from 'fs';
3
+ import { Readable } from 'stream';
4
+
5
+ declare function findLast<T>(items: readonly T[], predicate: (item: T, index: number, items: readonly T[]) => boolean): T | undefined;
6
+
7
+ declare namespace Binary {
8
+ function search<T>(array: T[], id: string, compare: (item: T) => string): {
9
+ found: boolean;
10
+ index: number;
11
+ };
12
+ function insert<T>(array: T[], item: T, compare: (item: T) => string): T[];
13
+ }
14
+
15
+ declare function base64Encode(value: string): string;
16
+ declare function base64Decode(value: string): string;
17
+ declare function hash(content: string, algorithm?: string): Promise<string>;
18
+ declare function checksum(content: string): string | undefined;
19
+
20
+ declare abstract class NamedError extends Error {
21
+ abstract schema(): z.core.$ZodType;
22
+ abstract toObject(): {
23
+ name: string;
24
+ data: any;
25
+ };
26
+ static create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data): {
27
+ new (data: z.input<Data>, options?: ErrorOptions): {
28
+ readonly name: Name;
29
+ readonly data: z.core.input<Data>;
30
+ schema(): z.ZodObject<{
31
+ name: z.ZodLiteral<Name>;
32
+ data: Data;
33
+ }, z.core.$strip>;
34
+ toObject(): {
35
+ name: Name;
36
+ data: z.core.input<Data>;
37
+ };
38
+ message: string;
39
+ stack?: string;
40
+ cause?: unknown;
41
+ };
42
+ readonly Schema: z.ZodObject<{
43
+ name: z.ZodLiteral<Name>;
44
+ data: Data;
45
+ }, z.core.$strip>;
46
+ isInstance(input: any): input is InstanceType<any>;
47
+ create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data): any;
48
+ readonly Unknown: {
49
+ new (data: {
50
+ message: string;
51
+ }, options?: ErrorOptions): {
52
+ readonly name: "UnknownError";
53
+ readonly data: {
54
+ message: string;
55
+ };
56
+ schema(): z.ZodObject<{
57
+ name: z.ZodLiteral<"UnknownError">;
58
+ data: z.ZodObject<{
59
+ message: z.ZodString;
60
+ }, z.core.$strip>;
61
+ }, z.core.$strip>;
62
+ toObject(): {
63
+ name: "UnknownError";
64
+ data: {
65
+ message: string;
66
+ };
67
+ };
68
+ message: string;
69
+ stack?: string;
70
+ cause?: unknown;
71
+ };
72
+ readonly Schema: z.ZodObject<{
73
+ name: z.ZodLiteral<"UnknownError">;
74
+ data: z.ZodObject<{
75
+ message: z.ZodString;
76
+ }, z.core.$strip>;
77
+ }, z.core.$strip>;
78
+ isInstance(input: any): input is {
79
+ readonly name: "UnknownError";
80
+ readonly data: {
81
+ message: string;
82
+ };
83
+ schema(): z.ZodObject<{
84
+ name: z.ZodLiteral<"UnknownError">;
85
+ data: z.ZodObject<{
86
+ message: z.ZodString;
87
+ }, z.core.$strip>;
88
+ }, z.core.$strip>;
89
+ toObject(): {
90
+ name: "UnknownError";
91
+ data: {
92
+ message: string;
93
+ };
94
+ };
95
+ message: string;
96
+ stack?: string;
97
+ cause?: unknown;
98
+ };
99
+ create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data): any;
100
+ readonly Unknown: any;
101
+ isError(error: unknown): error is Error;
102
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
103
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
104
+ stackTraceLimit: number;
105
+ };
106
+ isError(error: unknown): error is Error;
107
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
108
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
109
+ stackTraceLimit: number;
110
+ };
111
+ static readonly Unknown: {
112
+ new (data: {
113
+ message: string;
114
+ }, options?: ErrorOptions): {
115
+ readonly name: "UnknownError";
116
+ readonly data: {
117
+ message: string;
118
+ };
119
+ schema(): z.ZodObject<{
120
+ name: z.ZodLiteral<"UnknownError">;
121
+ data: z.ZodObject<{
122
+ message: z.ZodString;
123
+ }, z.core.$strip>;
124
+ }, z.core.$strip>;
125
+ toObject(): {
126
+ name: "UnknownError";
127
+ data: {
128
+ message: string;
129
+ };
130
+ };
131
+ message: string;
132
+ stack?: string;
133
+ cause?: unknown;
134
+ };
135
+ readonly Schema: z.ZodObject<{
136
+ name: z.ZodLiteral<"UnknownError">;
137
+ data: z.ZodObject<{
138
+ message: z.ZodString;
139
+ }, z.core.$strip>;
140
+ }, z.core.$strip>;
141
+ isInstance(input: any): input is {
142
+ readonly name: "UnknownError";
143
+ readonly data: {
144
+ message: string;
145
+ };
146
+ schema(): z.ZodObject<{
147
+ name: z.ZodLiteral<"UnknownError">;
148
+ data: z.ZodObject<{
149
+ message: z.ZodString;
150
+ }, z.core.$strip>;
151
+ }, z.core.$strip>;
152
+ toObject(): {
153
+ name: "UnknownError";
154
+ data: {
155
+ message: string;
156
+ };
157
+ };
158
+ message: string;
159
+ stack?: string;
160
+ cause?: unknown;
161
+ };
162
+ create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data): {
163
+ new (data: z.input<Data>, options?: ErrorOptions): {
164
+ readonly name: Name;
165
+ readonly data: z.core.input<Data>;
166
+ schema(): z.ZodObject<{
167
+ name: z.ZodLiteral<Name>;
168
+ data: Data;
169
+ }, z.core.$strip>;
170
+ toObject(): {
171
+ name: Name;
172
+ data: z.core.input<Data>;
173
+ };
174
+ message: string;
175
+ stack?: string;
176
+ cause?: unknown;
177
+ };
178
+ readonly Schema: z.ZodObject<{
179
+ name: z.ZodLiteral<Name>;
180
+ data: Data;
181
+ }, z.core.$strip>;
182
+ isInstance(input: any): input is InstanceType<any>;
183
+ create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data): any;
184
+ readonly Unknown: any;
185
+ isError(error: unknown): error is Error;
186
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
187
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
188
+ stackTraceLimit: number;
189
+ };
190
+ readonly Unknown: any;
191
+ isError(error: unknown): error is Error;
192
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
193
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
194
+ stackTraceLimit: number;
195
+ };
196
+ }
197
+
198
+ declare namespace Filesystem {
199
+ function exists(p: string): Promise<boolean>;
200
+ function isDir(p: string): Promise<boolean>;
201
+ function stat(p: string): ReturnType<typeof statSync> | undefined;
202
+ function size(p: string): Promise<number>;
203
+ function readText(p: string): Promise<string>;
204
+ function readJson<T = any>(p: string): Promise<T>;
205
+ function readBytes(p: string): Promise<Buffer>;
206
+ function readArrayBuffer(p: string): Promise<ArrayBuffer>;
207
+ function write(p: string, content: string | Buffer | Uint8Array, mode?: number): Promise<void>;
208
+ function writeJson(p: string, data: unknown, mode?: number): Promise<void>;
209
+ function writeStream(p: string, stream: ReadableStream<Uint8Array> | Readable, mode?: number): Promise<void>;
210
+ function mimeType(p: string): string;
211
+ function normalizePath(p: string): string;
212
+ function overlaps(a: string, b: string): boolean;
213
+ function contains(parent: string, child: string): boolean;
214
+ function findUp(target: string, start: string, stop?: string): Promise<string[]>;
215
+ function up(options: {
216
+ targets: string[];
217
+ start: string;
218
+ stop?: string;
219
+ }): AsyncGenerator<string, void, unknown>;
220
+ function globUp(pattern: string, start: string, stop?: string): Promise<string[]>;
221
+ }
222
+
223
+ declare function fn<T extends z$1.ZodType, Result>(schema: T, cb: (input: z$1.infer<T>) => Result): {
224
+ (input: z$1.infer<T>): Result;
225
+ force(input: z$1.infer<T>): Result;
226
+ schema: T;
227
+ };
228
+
229
+ declare namespace Identifier {
230
+ function ascending(): string;
231
+ function descending(): string;
232
+ function create(descending: boolean, timestamp?: number): string;
233
+ }
234
+
235
+ declare function loadTextFile(relativePath: string, importMetaUrl?: string): {
236
+ (): Promise<string>;
237
+ reset(): void;
238
+ };
239
+ declare function loadTextFileAsync(relativePath: string, importMetaUrl?: string): {
240
+ (): Promise<string>;
241
+ reset(): void;
242
+ };
243
+
244
+ declare function iife<T>(fn: () => T): T;
245
+
246
+ declare function lazy<T>(fn: () => T): {
247
+ (): T;
248
+ reset(): void;
249
+ };
250
+
251
+ declare const MarkdownStyleSchema: z$1.ZodEnum<{
252
+ bold: "bold";
253
+ code: "code";
254
+ italic: "italic";
255
+ strikethrough: "strikethrough";
256
+ code_block: "code_block";
257
+ spoiler: "spoiler";
258
+ blockquote: "blockquote";
259
+ }>;
260
+ type MarkdownStyle = z$1.infer<typeof MarkdownStyleSchema>;
261
+ declare const MarkdownStyleSpanSchema: z$1.ZodObject<{
262
+ start: z$1.ZodNumber;
263
+ end: z$1.ZodNumber;
264
+ style: z$1.ZodEnum<{
265
+ bold: "bold";
266
+ code: "code";
267
+ italic: "italic";
268
+ strikethrough: "strikethrough";
269
+ code_block: "code_block";
270
+ spoiler: "spoiler";
271
+ blockquote: "blockquote";
272
+ }>;
273
+ }, z$1.core.$strict>;
274
+ type MarkdownStyleSpan = z$1.infer<typeof MarkdownStyleSpanSchema>;
275
+ declare const MarkdownLinkSpanSchema: z$1.ZodObject<{
276
+ start: z$1.ZodNumber;
277
+ end: z$1.ZodNumber;
278
+ href: z$1.ZodString;
279
+ }, z$1.core.$strict>;
280
+ type MarkdownLinkSpan = z$1.infer<typeof MarkdownLinkSpanSchema>;
281
+ declare const MarkdownIRSchema: z$1.ZodObject<{
282
+ text: z$1.ZodString;
283
+ styles: z$1.ZodArray<z$1.ZodObject<{
284
+ start: z$1.ZodNumber;
285
+ end: z$1.ZodNumber;
286
+ style: z$1.ZodEnum<{
287
+ bold: "bold";
288
+ code: "code";
289
+ italic: "italic";
290
+ strikethrough: "strikethrough";
291
+ code_block: "code_block";
292
+ spoiler: "spoiler";
293
+ blockquote: "blockquote";
294
+ }>;
295
+ }, z$1.core.$strict>>;
296
+ links: z$1.ZodArray<z$1.ZodObject<{
297
+ start: z$1.ZodNumber;
298
+ end: z$1.ZodNumber;
299
+ href: z$1.ZodString;
300
+ }, z$1.core.$strict>>;
301
+ }, z$1.core.$strict>;
302
+ type MarkdownIR = z$1.infer<typeof MarkdownIRSchema>;
303
+ declare const MarkdownTableModeSchema: z$1.ZodEnum<{
304
+ code: "code";
305
+ off: "off";
306
+ bullets: "bullets";
307
+ }>;
308
+ type MarkdownTableMode = z$1.infer<typeof MarkdownTableModeSchema>;
309
+ declare const MarkdownParseOptionsSchema: z$1.ZodDefault<z$1.ZodObject<{
310
+ linkify: z$1.ZodOptional<z$1.ZodDefault<z$1.ZodBoolean>>;
311
+ enableSpoilers: z$1.ZodOptional<z$1.ZodDefault<z$1.ZodBoolean>>;
312
+ headingStyle: z$1.ZodOptional<z$1.ZodDefault<z$1.ZodEnum<{
313
+ bold: "bold";
314
+ none: "none";
315
+ }>>>;
316
+ blockquotePrefix: z$1.ZodOptional<z$1.ZodDefault<z$1.ZodString>>;
317
+ autolink: z$1.ZodOptional<z$1.ZodDefault<z$1.ZodBoolean>>;
318
+ tableMode: z$1.ZodOptional<z$1.ZodDefault<z$1.ZodEnum<{
319
+ code: "code";
320
+ off: "off";
321
+ bullets: "bullets";
322
+ }>>>;
323
+ }, z$1.core.$strip>>;
324
+ type MarkdownParseOptions = z$1.infer<typeof MarkdownParseOptionsSchema>;
325
+ declare const StyleMarkerSchema: z$1.ZodObject<{
326
+ open: z$1.ZodString;
327
+ close: z$1.ZodString;
328
+ }, z$1.core.$strict>;
329
+ type StyleMarker = z$1.infer<typeof StyleMarkerSchema>;
330
+ type RenderOptions = {
331
+ styleMarkers?: Record<MarkdownStyle, StyleMarker>;
332
+ escapeText?: (text: string) => string;
333
+ buildLink?: (link: MarkdownLinkSpan, text: string) => RenderLink | null;
334
+ };
335
+ declare const RenderLinkSchema: z$1.ZodObject<{
336
+ start: z$1.ZodNumber;
337
+ end: z$1.ZodNumber;
338
+ open: z$1.ZodString;
339
+ close: z$1.ZodString;
340
+ }, z$1.core.$strict>;
341
+ type RenderLink = z$1.infer<typeof RenderLinkSchema>;
342
+ declare const FormatOptionsSchema: z$1.ZodObject<{
343
+ indentSize: z$1.ZodDefault<z$1.ZodNumber>;
344
+ listMarker: z$1.ZodDefault<z$1.ZodEnum<{
345
+ "-": "-";
346
+ "\u2022": "•";
347
+ "*": "*";
348
+ }>>;
349
+ codeBlockMarker: z$1.ZodDefault<z$1.ZodEnum<{
350
+ "```": "```";
351
+ "~~~": "~~~";
352
+ }>>;
353
+ preserveFrontmatter: z$1.ZodDefault<z$1.ZodBoolean>;
354
+ }, z$1.core.$strict>;
355
+ type FormatOptions = z$1.infer<typeof FormatOptionsSchema>;
356
+ declare const ParsedFrontmatterSchema: z$1.ZodRecord<z$1.ZodString, z$1.ZodString>;
357
+ type ParsedFrontmatter = z$1.infer<typeof ParsedFrontmatterSchema>;
358
+ declare const InlineCodeStateSchema: z$1.ZodObject<{
359
+ open: z$1.ZodBoolean;
360
+ ticks: z$1.ZodNumber;
361
+ }, z$1.core.$strict>;
362
+ type InlineCodeState$1 = z$1.infer<typeof InlineCodeStateSchema>;
363
+ type CodeSpanIndex$1 = {
364
+ inlineState: InlineCodeState$1;
365
+ isInside: (offset: number) => boolean;
366
+ };
367
+ declare const FenceSpanSchema: z$1.ZodObject<{
368
+ start: z$1.ZodNumber;
369
+ end: z$1.ZodNumber;
370
+ openLine: z$1.ZodString;
371
+ marker: z$1.ZodString;
372
+ indent: z$1.ZodString;
373
+ }, z$1.core.$strict>;
374
+ type FenceSpan$1 = z$1.infer<typeof FenceSpanSchema>;
375
+ declare const MarkdownConfigSchema: z$1.ZodObject<{
376
+ tables: z$1.ZodOptional<z$1.ZodEnum<{
377
+ code: "code";
378
+ off: "off";
379
+ bullets: "bullets";
380
+ }>>;
381
+ }, z$1.core.$strict>;
382
+ type MarkdownConfig = z$1.infer<typeof MarkdownConfigSchema>;
383
+
384
+ declare function markdownToIR(markdown: string, options?: MarkdownParseOptions): MarkdownIR;
385
+ declare function markdownToIRWithMeta(markdown: string, options?: MarkdownParseOptions): {
386
+ ir: MarkdownIR;
387
+ hasTables: boolean;
388
+ };
389
+ declare function chunkMarkdownIR(ir: MarkdownIR, limit: number): MarkdownIR[];
390
+
391
+ declare function renderMarkdownWithMarkers(ir: MarkdownIR, options?: RenderOptions): string;
392
+ declare function renderMarkdown(ir: MarkdownIR, options?: RenderOptions): string;
393
+
394
+ declare function formatMarkdown(markdown: string, options?: FormatOptions): string;
395
+
396
+ declare function parseFrontmatterBlock(content: string): ParsedFrontmatter;
397
+ declare function serializeFrontmatter(data: ParsedFrontmatter): string;
398
+ declare function extractFrontmatter(content: string): {
399
+ frontmatter: ParsedFrontmatter;
400
+ content: string;
401
+ };
402
+
403
+ declare function scanParenAwareBreakpoints(text: string, start: number, end: number, isAllowed?: (index: number) => boolean): {
404
+ lastNewline: number;
405
+ lastWhitespace: number;
406
+ };
407
+ declare function chunkText(text: string, limit: number): string[];
408
+ declare function chunkTextByBreakResolver(text: string, limit: number, resolveBreakIndex: (window: string) => number): string[];
409
+
410
+ type InlineCodeState = {
411
+ open: boolean;
412
+ ticks: number;
413
+ };
414
+ declare function createInlineCodeState(): InlineCodeState;
415
+ type CodeSpanIndex = {
416
+ inlineState: InlineCodeState;
417
+ isInside: (index: number) => boolean;
418
+ };
419
+ declare function buildCodeSpanIndex(text: string, inlineState?: InlineCodeState): CodeSpanIndex;
420
+
421
+ type FenceSpan = {
422
+ start: number;
423
+ end: number;
424
+ openLine: string;
425
+ marker: string;
426
+ indent: string;
427
+ };
428
+ declare function parseFenceSpans(buffer: string): FenceSpan[];
429
+ declare function findFenceSpanAt(spans: FenceSpan[], index: number): FenceSpan | undefined;
430
+ declare function isSafeFenceBreak(spans: FenceSpan[], index: number): boolean;
431
+
432
+ declare function convertMarkdownTables(markdown: string, mode: MarkdownTableMode): string;
433
+
434
+ declare namespace Markdown {
435
+ function parse(markdown: string, options?: MarkdownParseOptions): MarkdownIR;
436
+ function render(ir: MarkdownIR, options?: RenderOptions): string;
437
+ function format(markdown: string, options?: FormatOptions): string;
438
+ function parseFrontmatter(content: string): ParsedFrontmatter;
439
+ function serializeFrontmatter(data: ParsedFrontmatter): string;
440
+ function extractFrontmatter(content: string): {
441
+ frontmatter: ParsedFrontmatter;
442
+ content: string;
443
+ };
444
+ function chunk(text: string, limit: number): string[];
445
+ function buildCodeIndex(text: string, inlineState?: InlineCodeState$1): CodeSpanIndex$1;
446
+ function convertTables(markdown: string, tableMode: MarkdownTableMode): string;
447
+ }
448
+
449
+ declare function getFilename(path: string | undefined): string;
450
+ declare function getDirectory(path: string | undefined): string;
451
+ declare function getFileExtension(path: string | undefined): string | undefined;
452
+ declare function getFilenameTruncated(path: string | undefined, maxLength?: number): string;
453
+ declare function truncateMiddle(text: string, maxLength?: number): string;
454
+
455
+ interface RetryOptions {
456
+ attempts?: number;
457
+ delay?: number;
458
+ factor?: number;
459
+ maxDelay?: number;
460
+ retryIf?: (error: unknown) => boolean;
461
+ }
462
+ declare function retry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
463
+
464
+ declare namespace Slug {
465
+ function create(): string;
466
+ }
467
+
468
+ export { Binary, type CodeSpanIndex$1 as CodeSpanIndex, type FenceSpan$1 as FenceSpan, Filesystem, type FormatOptions, Identifier, type InlineCodeState$1 as InlineCodeState, Markdown, type MarkdownConfig, type MarkdownIR, type MarkdownLinkSpan, type MarkdownParseOptions, type MarkdownStyle, type MarkdownStyleSpan, type MarkdownTableMode, NamedError, type ParsedFrontmatter, type RenderLink, type RenderOptions, Slug, type StyleMarker, base64Decode, base64Encode, buildCodeSpanIndex, checksum, chunkMarkdownIR, chunkText, chunkTextByBreakResolver, convertMarkdownTables, createInlineCodeState, extractFrontmatter, findFenceSpanAt, findLast, fn, formatMarkdown, getDirectory, getFileExtension, getFilename, getFilenameTruncated, hash, iife, isSafeFenceBreak, lazy, loadTextFile, loadTextFileAsync, markdownToIR, markdownToIRWithMeta, parseFenceSpans, parseFrontmatterBlock, renderMarkdown, renderMarkdownWithMarkers, retry, scanParenAwareBreakpoints, serializeFrontmatter, truncateMiddle };