@stacksjs/utils 0.70.23 → 0.70.25
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/dist/index.js +15 -4595
- package/dist/src/bytes.d.ts +42 -0
- package/dist/src/clean.d.ts +1 -0
- package/dist/src/colors.d.ts +96 -0
- package/dist/{config.d.ts → src/config.d.ts} +2 -2
- package/dist/src/debounce.d.ts +29 -0
- package/dist/src/detect.d.ts +35 -0
- package/dist/src/equal.d.ts +13 -0
- package/dist/src/export-size.d.ts +2 -0
- package/dist/{find.d.ts → src/find.d.ts} +1 -3
- package/dist/src/git.d.ts +1 -0
- package/dist/{hash.d.ts → src/hash.d.ts} +1 -1
- package/dist/{helpers.d.ts → src/helpers.d.ts} +37 -5
- package/dist/src/index.d.ts +23 -0
- package/dist/src/macroable.d.ts +28 -0
- package/dist/src/markdown.d.ts +46 -0
- package/dist/src/merge.d.ts +20 -0
- package/dist/src/observer.d.ts +64 -0
- package/dist/src/pipeline.d.ts +13 -0
- package/dist/src/safe-json.d.ts +49 -0
- package/dist/src/size.d.ts +37 -0
- package/dist/{versions.d.ts → src/versions.d.ts} +2 -4
- package/package.json +23 -37
- package/dist/clean.d.ts +0 -1
- package/dist/equal.d.ts +0 -1
- package/dist/export-size.d.ts +0 -1
- package/dist/git.d.ts +0 -1
- package/dist/glob.d.ts +0 -1
- package/dist/index.d.ts +0 -11
- package/dist/macroable.d.ts +0 -1
- package/dist/utils.d.ts +0 -3
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format bytes to human-readable string
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* formatBytes(1024) // '1 KB'
|
|
7
|
+
* formatBytes(1024, { binary: true }) // '1 KiB'
|
|
8
|
+
* formatBytes(1234567) // '1.2 MB'
|
|
9
|
+
* formatBytes(1234567, { precision: 2 }) // '1.23 MB'
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatBytes(bytes: number, options?: BytesOptions): string;
|
|
13
|
+
/**
|
|
14
|
+
* Parse human-readable byte string to number
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* parseBytes('1 KB') // 1000
|
|
19
|
+
* parseBytes('1 KiB') // 1024
|
|
20
|
+
* parseBytes('1.5 MB') // 1500000
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseBytes(input: string): number;
|
|
24
|
+
/**
|
|
25
|
+
* Compare two byte values
|
|
26
|
+
*/
|
|
27
|
+
export declare function compareBytes(a: number | string, b: number | string): number;
|
|
28
|
+
// Aliases
|
|
29
|
+
export declare const prettyBytes: unknown;
|
|
30
|
+
export declare const readableSize: unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Format bytes to human-readable string (pretty-bytes replacement)
|
|
33
|
+
*/
|
|
34
|
+
export declare interface BytesOptions {
|
|
35
|
+
precision?: number
|
|
36
|
+
binary?: boolean
|
|
37
|
+
space?: boolean
|
|
38
|
+
locale?: string
|
|
39
|
+
minimumFractionDigits?: number
|
|
40
|
+
maximumFractionDigits?: number
|
|
41
|
+
}
|
|
42
|
+
export { formatBytes as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cleanProject(): Promise<void>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Strip colors from text
|
|
2
|
+
export declare function stripColors(text: string): string;
|
|
3
|
+
// Check if colors are supported
|
|
4
|
+
export declare function supportsColor(): boolean;
|
|
5
|
+
// Color functions
|
|
6
|
+
export declare const black: unknown;
|
|
7
|
+
export declare const red: unknown;
|
|
8
|
+
export declare const green: unknown;
|
|
9
|
+
export declare const yellow: unknown;
|
|
10
|
+
export declare const blue: unknown;
|
|
11
|
+
export declare const magenta: unknown;
|
|
12
|
+
export declare const cyan: unknown;
|
|
13
|
+
export declare const white: unknown;
|
|
14
|
+
export declare const gray: unknown;
|
|
15
|
+
export declare const grey: unknown;
|
|
16
|
+
// Bright colors
|
|
17
|
+
export declare const lightRed: unknown;
|
|
18
|
+
export declare const lightGreen: unknown;
|
|
19
|
+
export declare const lightYellow: unknown;
|
|
20
|
+
export declare const lightBlue: unknown;
|
|
21
|
+
export declare const lightMagenta: unknown;
|
|
22
|
+
export declare const lightCyan: unknown;
|
|
23
|
+
export declare const lightGray: unknown;
|
|
24
|
+
export declare const lightGrey: unknown;
|
|
25
|
+
// Background colors
|
|
26
|
+
export declare const bgBlack: unknown;
|
|
27
|
+
export declare const bgRed: unknown;
|
|
28
|
+
export declare const bgGreen: unknown;
|
|
29
|
+
export declare const bgYellow: unknown;
|
|
30
|
+
export declare const bgBlue: unknown;
|
|
31
|
+
export declare const bgMagenta: unknown;
|
|
32
|
+
export declare const bgCyan: unknown;
|
|
33
|
+
export declare const bgWhite: unknown;
|
|
34
|
+
// Bright background colors
|
|
35
|
+
export declare const bgLightRed: unknown;
|
|
36
|
+
export declare const bgLightGreen: unknown;
|
|
37
|
+
export declare const bgLightYellow: unknown;
|
|
38
|
+
export declare const bgLightBlue: unknown;
|
|
39
|
+
export declare const bgLightMagenta: unknown;
|
|
40
|
+
export declare const bgLightCyan: unknown;
|
|
41
|
+
// Text formatting
|
|
42
|
+
export declare const bold: unknown;
|
|
43
|
+
export declare const dim: unknown;
|
|
44
|
+
export declare const italic: unknown;
|
|
45
|
+
export declare const underline: unknown;
|
|
46
|
+
export declare const inverse: unknown;
|
|
47
|
+
export declare const hidden: unknown;
|
|
48
|
+
export declare const strikethrough: unknown;
|
|
49
|
+
// Reset
|
|
50
|
+
export declare const reset: unknown;
|
|
51
|
+
declare type ColorFn = (_text: string | number) => string;
|
|
52
|
+
// Default export
|
|
53
|
+
export default {
|
|
54
|
+
black,
|
|
55
|
+
red,
|
|
56
|
+
green,
|
|
57
|
+
yellow,
|
|
58
|
+
blue,
|
|
59
|
+
magenta,
|
|
60
|
+
cyan,
|
|
61
|
+
white,
|
|
62
|
+
gray,
|
|
63
|
+
grey,
|
|
64
|
+
lightRed,
|
|
65
|
+
lightGreen,
|
|
66
|
+
lightYellow,
|
|
67
|
+
lightBlue,
|
|
68
|
+
lightMagenta,
|
|
69
|
+
lightCyan,
|
|
70
|
+
lightGray,
|
|
71
|
+
lightGrey,
|
|
72
|
+
bgBlack,
|
|
73
|
+
bgRed,
|
|
74
|
+
bgGreen,
|
|
75
|
+
bgYellow,
|
|
76
|
+
bgBlue,
|
|
77
|
+
bgMagenta,
|
|
78
|
+
bgCyan,
|
|
79
|
+
bgWhite,
|
|
80
|
+
bgLightRed,
|
|
81
|
+
bgLightGreen,
|
|
82
|
+
bgLightYellow,
|
|
83
|
+
bgLightBlue,
|
|
84
|
+
bgLightMagenta,
|
|
85
|
+
bgLightCyan,
|
|
86
|
+
bold,
|
|
87
|
+
dim,
|
|
88
|
+
italic,
|
|
89
|
+
underline,
|
|
90
|
+
inverse,
|
|
91
|
+
hidden,
|
|
92
|
+
strikethrough,
|
|
93
|
+
reset,
|
|
94
|
+
stripColors,
|
|
95
|
+
supportsColor,
|
|
96
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a debounced function that delays invoking func until after wait milliseconds
|
|
3
|
+
* have elapsed since the last time the debounced function was invoked.
|
|
4
|
+
*
|
|
5
|
+
* @param fn - The function to debounce
|
|
6
|
+
* @param wait - The number of milliseconds to delay
|
|
7
|
+
* @param options - Options object
|
|
8
|
+
* @returns The debounced function
|
|
9
|
+
*/
|
|
10
|
+
export declare function debounce<T extends (..._args: any[]) => any>(fn: T, wait?: number, options?: DebounceOptions): T & { cancel: () => void; flush: () => void };
|
|
11
|
+
/**
|
|
12
|
+
* Creates a throttled function that only invokes func at most once per every wait milliseconds
|
|
13
|
+
*
|
|
14
|
+
* @param fn - The function to throttle
|
|
15
|
+
* @param wait - The number of milliseconds to throttle
|
|
16
|
+
* @returns The throttled function
|
|
17
|
+
*/
|
|
18
|
+
export declare function throttle<T extends (...args: any[]) => any>(fn: T, wait?: number): T & { cancel: () => void };
|
|
19
|
+
/**
|
|
20
|
+
* Delays execution of a function
|
|
21
|
+
*/
|
|
22
|
+
export declare function delay(ms: number): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Debounce and throttle utilities (perfect-debounce replacement)
|
|
25
|
+
*/
|
|
26
|
+
export declare interface DebounceOptions {
|
|
27
|
+
leading?: boolean
|
|
28
|
+
trailing?: boolean
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare function detectIndent(text: string): IndentInfo;
|
|
2
|
+
/**
|
|
3
|
+
* Detect newline type in a string
|
|
4
|
+
*
|
|
5
|
+
* @returns '\r\n' (CRLF - Windows), '\n' (LF - Unix), '\r' (CR - old Mac), or null
|
|
6
|
+
*/
|
|
7
|
+
export declare function detectNewline(text: string): '\r\n' | '\n' | '\r' | null;
|
|
8
|
+
/**
|
|
9
|
+
* Detect newline type with graceful fallback
|
|
10
|
+
*/
|
|
11
|
+
export declare function detectNewlineGraceful(text: string, fallback?: '\r\n' | '\n'): '\r\n' | '\n' | '\r';
|
|
12
|
+
/**
|
|
13
|
+
* Normalize newlines in text to specified type
|
|
14
|
+
*/
|
|
15
|
+
export declare function normalizeNewlines(text: string, newline?: '\r\n' | '\n' | '\r'): string;
|
|
16
|
+
/**
|
|
17
|
+
* Count different types of newlines in text
|
|
18
|
+
*/
|
|
19
|
+
export declare function countNewlines(text: string): {
|
|
20
|
+
crlf: number
|
|
21
|
+
lf: number
|
|
22
|
+
cr: number
|
|
23
|
+
total: number
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Text detection utilities (detect-indent and detect-newline replacements)
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Detect indentation type and amount in a string
|
|
30
|
+
*/
|
|
31
|
+
export declare interface IndentInfo {
|
|
32
|
+
amount: number
|
|
33
|
+
type: 'space' | 'tab' | null
|
|
34
|
+
indent: string
|
|
35
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep equality with NaN-safety and cycle detection.
|
|
3
|
+
*
|
|
4
|
+
* - `NaN === NaN` is false in JavaScript, so the previous `Object.is`
|
|
5
|
+
* tail correctly handled that case but only at the leaf — a
|
|
6
|
+
* `[NaN, NaN]` pair compared element-by-element worked, but compound
|
|
7
|
+
* structures relied on the tail. The new shape preserves that.
|
|
8
|
+
* - Circular references used to send isDeepEqual into infinite recursion
|
|
9
|
+
* (`a.self = a; isDeepEqual(a, a)` blew the stack). A WeakSet of
|
|
10
|
+
* already-visited objects breaks the cycle and treats two structurally
|
|
11
|
+
* identical cycles as equal.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isDeepEqual(value1: any, value2: any, seen?: WeakMap<object, object>): boolean;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
declare
|
|
1
|
+
export declare function findStacksProjects(dir?: string, options?: FindStacksProjectsOptions): Promise<string[]>;
|
|
2
2
|
declare interface FindStacksProjectsOptions {
|
|
3
3
|
quiet?: boolean
|
|
4
4
|
}
|
|
5
|
-
export declare function findStacksProjects(dir?: string, options?: FindStacksProjectsOptions): Promise<string[]>;
|
|
6
|
-
declare function searchDirectory(directory: string): Promise<string[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isGitClean(): boolean;
|
|
@@ -1,21 +1,53 @@
|
|
|
1
1
|
import type { AddressInfo } from 'node:net';
|
|
2
2
|
import type { CliOptions, Manifest, Subprocess } from '@stacksjs/types';
|
|
3
3
|
import type { NpmScript } from '@stacksjs/enums';
|
|
4
|
-
|
|
4
|
+
import type { Result } from '@stacksjs/error-handling';
|
|
5
|
+
// Bun has native YAML support via Bun.YAML
|
|
6
|
+
// import { semver } from './versions'
|
|
5
7
|
export declare function packageManager(): Promise<string>;
|
|
6
8
|
export declare function initProject(): Promise<Result<Subprocess, Error>>;
|
|
7
9
|
export declare function ensureProjectIsInitialized(): Promise<boolean>;
|
|
8
10
|
export declare function installIfVersionMismatch(): Promise<void>;
|
|
9
11
|
export declare function frameworkVersion(): Promise<string>;
|
|
10
12
|
export declare function isAppKeySet(): Promise<boolean>;
|
|
11
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Determines the utilized reset preset.
|
|
15
|
+
*
|
|
16
|
+
* @url https://github.com/cwcss/crosswind
|
|
17
|
+
* @param preset
|
|
18
|
+
*/
|
|
19
|
+
export declare function determineResetPreset(preset?: string | null): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Determines whether the specified value is a package manifest.
|
|
22
|
+
*/
|
|
12
23
|
export declare function isManifest(obj: any): obj is Manifest;
|
|
13
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Determines whether the specified value is a string, null, or undefined.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isOptionalString(value: any): value is string | null | undefined;
|
|
14
28
|
export declare function setEnvValue(key: string, value: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Runs the specified NPM script in the package.json file.
|
|
31
|
+
*/
|
|
15
32
|
export declare function runNpmScript(script: NpmScript, options?: CliOptions): Promise<Result<Subprocess, Error>>;
|
|
33
|
+
/**
|
|
34
|
+
* Determines whether the specified NPM script exists in the given manifest.
|
|
35
|
+
*/
|
|
16
36
|
export declare function hasScript(manifest: Manifest, script: NpmScript): boolean;
|
|
17
37
|
export declare function parseYaml(content: any): any;
|
|
38
|
+
/**
|
|
39
|
+
* Determines the level of debugging.
|
|
40
|
+
*
|
|
41
|
+
* The debug level is determined by the following:
|
|
42
|
+
* 1. The --verbose flag
|
|
43
|
+
* 2. The debug property in the app configuration
|
|
44
|
+
*
|
|
45
|
+
* Currently, we don't support a custom debug level,
|
|
46
|
+
* though, we would like to in the future.
|
|
47
|
+
*
|
|
48
|
+
* @param options
|
|
49
|
+
*/
|
|
18
50
|
export declare function determineDebugLevel(options?: CliOptions): boolean;
|
|
19
51
|
export declare function isIpv6(address: AddressInfo): boolean;
|
|
20
|
-
|
|
21
|
-
export
|
|
52
|
+
export declare function dumpYaml(content: any): string;
|
|
53
|
+
export declare function loadYaml(content: string): any;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from './clean';
|
|
2
|
+
export * from './config';
|
|
3
|
+
export * from './equal';
|
|
4
|
+
export * from './export-size';
|
|
5
|
+
export * from './find';
|
|
6
|
+
export * from './git';
|
|
7
|
+
export * from './hash';
|
|
8
|
+
export * from './helpers';
|
|
9
|
+
export * from './macroable';
|
|
10
|
+
export * from './safe-json';
|
|
11
|
+
export * from './versions';
|
|
12
|
+
export * as browserUtils from '@stacksjs/browser';
|
|
13
|
+
export { clamp, notNullish, retry, useOnline } from '@stacksjs/browser';
|
|
14
|
+
// Native utility replacements
|
|
15
|
+
export * from './merge';
|
|
16
|
+
export * from './detect';
|
|
17
|
+
export * from './debounce';
|
|
18
|
+
export * from './bytes';
|
|
19
|
+
export * from './colors';
|
|
20
|
+
export * from './markdown';
|
|
21
|
+
export * from './size';
|
|
22
|
+
export * from './observer';
|
|
23
|
+
export * from './pipeline';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a macroable class
|
|
3
|
+
*/
|
|
4
|
+
export declare function createMacroable<T extends new (..._args: any[]) => any>(BaseClass?: T): T & MacroableConstructor;
|
|
5
|
+
/**
|
|
6
|
+
* Mixin for adding macroable functionality to existing classes
|
|
7
|
+
*/
|
|
8
|
+
export declare function macroable<T extends new (..._args: any[]) => any>(target: T): T & MacroableConstructor;
|
|
9
|
+
/**
|
|
10
|
+
* Native Macroable implementation
|
|
11
|
+
* Inspired by Laravel's Macroable trait - allows adding methods dynamically to classes
|
|
12
|
+
*/
|
|
13
|
+
export declare interface MacroableConstructor {
|
|
14
|
+
new (...args: any[]): any
|
|
15
|
+
macro(name: string, fn: Function, replace?: boolean): void
|
|
16
|
+
mixin(obj: Record<string, any>, replace?: boolean): void
|
|
17
|
+
hasMacro(name: string): boolean
|
|
18
|
+
flushMacros(): void
|
|
19
|
+
getMacros(): string[]
|
|
20
|
+
}
|
|
21
|
+
export declare class Macroable {
|
|
22
|
+
static macro(name: string, fn: Function, replace?: boolean): void;
|
|
23
|
+
static mixin(obj: Record<string, any>, replace?: boolean): void;
|
|
24
|
+
static hasMacro(name: string): boolean;
|
|
25
|
+
static flushMacros(): void;
|
|
26
|
+
static getMacros(): string[];
|
|
27
|
+
protected callMacro(name: string, ...args: any[]): any;
|
|
28
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a markdown table from a 2D array
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const table = markdownTable([
|
|
7
|
+
* ['Name', 'Age', 'City'],
|
|
8
|
+
* ['Alice', 30, 'NYC'],
|
|
9
|
+
* ['Bob', 25, 'LA']
|
|
10
|
+
* ])
|
|
11
|
+
* // | Name | Age | City |
|
|
12
|
+
* // | ----- | --- | ---- |
|
|
13
|
+
* // | Alice | 30 | NYC |
|
|
14
|
+
* // | Bob | 25 | LA |
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function markdownTable(table: Table, options?: MarkdownTableOptions): string;
|
|
18
|
+
/**
|
|
19
|
+
* Create a markdown table from objects
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const data = [
|
|
24
|
+
* { name: 'Alice', age: 30 },
|
|
25
|
+
* { name: 'Bob', age: 25 }
|
|
26
|
+
* ]
|
|
27
|
+
* const table = markdownTableFromObjects(data)
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function markdownTableFromObjects<T extends Record<string, any>>(objects: T[], options?: MarkdownTableOptions): string;
|
|
31
|
+
/**
|
|
32
|
+
* Markdown table generation (markdown-table replacement)
|
|
33
|
+
*/
|
|
34
|
+
export declare interface MarkdownTableOptions {
|
|
35
|
+
align?: Array<'l' | 'c' | 'r' | 'left' | 'center' | 'right' | null>
|
|
36
|
+
padding?: boolean
|
|
37
|
+
delimiter?: string
|
|
38
|
+
delimiterStart?: boolean
|
|
39
|
+
delimiterEnd?: boolean
|
|
40
|
+
alignDelimiter?: string
|
|
41
|
+
}
|
|
42
|
+
declare type CellValue = string | number | boolean | null | undefined;
|
|
43
|
+
declare type Row = CellValue[];
|
|
44
|
+
declare type Table = Row[];
|
|
45
|
+
// Alias
|
|
46
|
+
export { markdownTable as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function merge<T extends Record<string, any>>(...objects: DeepPartial<T>[]): T;
|
|
2
|
+
/**
|
|
3
|
+
* Create a merger function with defaults (defu-like API)
|
|
4
|
+
*/
|
|
5
|
+
export declare function createMerger<T extends Record<string, any>>(defaults: T): void;
|
|
6
|
+
/**
|
|
7
|
+
* Merge with defaults (defu API)
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeDefaults<T extends Record<string, any>>(obj: DeepPartial<T>, ...defaults: DeepPartial<T>[]): T;
|
|
10
|
+
// Aliases for defu compatibility
|
|
11
|
+
export declare const defu: unknown;
|
|
12
|
+
export declare const defuArrayFn: unknown;
|
|
13
|
+
/**
|
|
14
|
+
* Deep merge objects (defu replacement)
|
|
15
|
+
*
|
|
16
|
+
* Merges multiple objects together, with later objects taking precedence.
|
|
17
|
+
* Arrays are concatenated, objects are recursively merged.
|
|
18
|
+
*/
|
|
19
|
+
declare type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
|
|
20
|
+
export { merge as default };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if ResizeObserver is supported natively
|
|
3
|
+
*/
|
|
4
|
+
export declare function isResizeObserverSupported(): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Get ResizeObserver (native or polyfill)
|
|
7
|
+
*
|
|
8
|
+
* Modern browsers all support ResizeObserver, but this provides a fallback
|
|
9
|
+
*/
|
|
10
|
+
export declare function getResizeObserver(): any;
|
|
11
|
+
/**
|
|
12
|
+
* Create a resize observer with automatic cleanup
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const cleanup = createResizeObserver((entries) => {
|
|
17
|
+
* for (const entry of entries) {
|
|
18
|
+
* console.log('Element resized:', entry.target)
|
|
19
|
+
* }
|
|
20
|
+
* }, element)
|
|
21
|
+
*
|
|
22
|
+
* // Later, clean up
|
|
23
|
+
* cleanup()
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function createResizeObserver(callback: ResizeObserverCallback, target: Element | Element[]): () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Observe element size changes
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const stop = observeElementSize(element, (entry) => {
|
|
33
|
+
* console.log('Size:', entry.contentRect.width, entry.contentRect.height)
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* // Stop observing
|
|
37
|
+
* stop()
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function observeElementSize(element: Element, callback: (entry: ResizeObserverEntry) => void): () => void;
|
|
41
|
+
// Export the native ResizeObserver if available, or the polyfill
|
|
42
|
+
export declare const ResizeObserver: any;
|
|
43
|
+
/**
|
|
44
|
+
* ResizeObserver polyfill (resize-observer-polyfill replacement)
|
|
45
|
+
*
|
|
46
|
+
* Note: Modern browsers all support ResizeObserver natively now.
|
|
47
|
+
* This provides a simple fallback for older browsers.
|
|
48
|
+
*/
|
|
49
|
+
export declare interface ResizeObserverSize {
|
|
50
|
+
readonly inlineSize: number
|
|
51
|
+
readonly blockSize: number
|
|
52
|
+
}
|
|
53
|
+
export declare interface ResizeObserverEntry {
|
|
54
|
+
readonly target: Element
|
|
55
|
+
readonly contentRect: DOMRectReadOnly
|
|
56
|
+
readonly borderBoxSize: ReadonlyArray<ResizeObserverSize>
|
|
57
|
+
readonly contentBoxSize: ReadonlyArray<ResizeObserverSize>
|
|
58
|
+
readonly devicePixelContentBoxSize: ReadonlyArray<ResizeObserverSize>
|
|
59
|
+
}
|
|
60
|
+
export type ResizeObserverCallback = (
|
|
61
|
+
entries: ResizeObserverEntry[],
|
|
62
|
+
observer: ResizeObserver,
|
|
63
|
+
) => void;
|
|
64
|
+
export default ResizeObserver;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare interface PipeClass<T> {
|
|
2
|
+
handle: PipeFunction<T>
|
|
3
|
+
}
|
|
4
|
+
declare type PipeFunction<T> = (data: T, next: (data: T) => T) => T;
|
|
5
|
+
declare type Pipe<T> = PipeFunction<T> | PipeClass<T>;
|
|
6
|
+
export declare class Pipeline<T> {
|
|
7
|
+
static send<T>(passable: T): Pipeline<T>;
|
|
8
|
+
through(pipes: Pipe<T>[]): this;
|
|
9
|
+
pipe(...pipes: Pipe<T>[]): this;
|
|
10
|
+
via(method: string): this;
|
|
11
|
+
then(destination: (data: T) => T): T;
|
|
12
|
+
thenReturn(): T;
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse `text` as JSON, returning `defaultValue` (default: `undefined`)
|
|
3
|
+
* when the input isn't valid JSON.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const config = safeJsonParse<Config>(rawText, { mode: 'default' })
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function safeJsonParse<T = unknown>(text: unknown, defaultValue?: T): T | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Result-flavored variant: surfaces *why* a parse failed when callers
|
|
13
|
+
* want to log the difference between "empty input" and "malformed input".
|
|
14
|
+
*/
|
|
15
|
+
// eslint-disable-next-line pickier/no-unused-vars
|
|
16
|
+
export declare function safeJsonParseResult<T = unknown>(text: unknown): { ok: true, value: T } | { ok: false, reason: 'not-string' | 'empty' | 'malformed', error?: unknown };
|
|
17
|
+
/**
|
|
18
|
+
* Stringify with cycle and bigint safety.
|
|
19
|
+
*
|
|
20
|
+
* `JSON.stringify` throws on circular refs (rare but real, e.g. logger
|
|
21
|
+
* captures of an Express-style req object) and on bigint values (common
|
|
22
|
+
* with database IDs that overflow Number). This wrapper substitutes
|
|
23
|
+
* `[Circular]` for cycles and converts bigints to strings — same shape
|
|
24
|
+
* downstream consumers expect from a "best-effort serialize this for
|
|
25
|
+
* logs" call.
|
|
26
|
+
*/
|
|
27
|
+
export declare function safeJsonStringify(value: unknown, space?: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* Safe JSON wrappers.
|
|
30
|
+
*
|
|
31
|
+
* Bare `JSON.parse(s)` throws `SyntaxError` on malformed input —
|
|
32
|
+
* which 90% of the time is exactly what you want, except in:
|
|
33
|
+
*
|
|
34
|
+
* - Webhook handlers: a malformed payload should produce a 400, not crash
|
|
35
|
+
* - Cache reads: a corrupt cache entry should miss, not throw
|
|
36
|
+
* - Log readers: a bad line should be skipped, not stop the parser
|
|
37
|
+
* - User-supplied config: a typo should produce a clear "X is invalid" error
|
|
38
|
+
*
|
|
39
|
+
* `safeJsonParse` returns `undefined` for malformed input (or a typed
|
|
40
|
+
* default), so call sites don't need a try/catch ladder around every
|
|
41
|
+
* untrusted input. `safeJsonParseResult` returns a discriminated union
|
|
42
|
+
* for cases where the failure reason matters.
|
|
43
|
+
*/
|
|
44
|
+
export type JsonValue = | string
|
|
45
|
+
| number
|
|
46
|
+
| boolean
|
|
47
|
+
| null
|
|
48
|
+
| JsonValue[]
|
|
49
|
+
| { [key: string]: JsonValue }
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the size of a file
|
|
3
|
+
*/
|
|
4
|
+
export declare function getFileSize(filePath: string): Promise<number>;
|
|
5
|
+
/**
|
|
6
|
+
* Get sizes of all exports in a package
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const sizes = await getExportsSize('./dist')
|
|
11
|
+
* console.log(sizes.totalReadable) // "42.5 KB"
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function getExportsSize(distPath: string): Promise<PackageExportsSizeResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Get gzipped size estimate
|
|
17
|
+
*/
|
|
18
|
+
export declare function estimateGzipSize(size: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Get brotli size estimate
|
|
21
|
+
*/
|
|
22
|
+
export declare function estimateBrotliSize(size: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Format export sizes as a table
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatExportSizes(result: PackageExportsSizeResult): string;
|
|
27
|
+
export declare interface ExportSize {
|
|
28
|
+
name: string
|
|
29
|
+
size: number
|
|
30
|
+
readable: string
|
|
31
|
+
}
|
|
32
|
+
export declare interface PackageExportsSizeResult {
|
|
33
|
+
totalSize: number
|
|
34
|
+
totalReadable: string
|
|
35
|
+
exports: ExportSize[]
|
|
36
|
+
}
|
|
37
|
+
export { getExportsSize as default };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { version } from '../package.json';
|
|
2
|
-
|
|
3
|
-
export declare const semver: typeof Bun.semver;
|
|
4
2
|
export declare function isVersionGreaterThan(version: string, compareVersion: string): boolean;
|
|
5
3
|
export declare function isVersionLessThan(version: string, compareVersion: string): boolean;
|
|
6
4
|
export declare function isVersionEqual(version: string, compareVersion: string): boolean;
|
|
7
5
|
export declare function isVersionGreaterThanOrEqual(version: string, compareVersion: string): boolean;
|
|
8
6
|
export declare function isVersionLessThanOrEqual(version: string, compareVersion: string): boolean;
|
|
9
|
-
|
|
10
|
-
export { version }
|
|
7
|
+
export declare const semver: typeof Bun.semver;
|
|
8
|
+
export { version };
|