bun-types 1.0.28 โ 1.0.29
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/bun.d.ts +48 -0
- package/package.json +1 -1
- package/test.d.ts +13 -0
package/bun.d.ts
CHANGED
|
@@ -47,6 +47,54 @@ declare module "bun" {
|
|
|
47
47
|
*/
|
|
48
48
|
function which(command: string, options?: { PATH?: string; cwd?: string }): string | null;
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Get the column count of a string as it would be displayed in a terminal.
|
|
52
|
+
* Supports ANSI escape codes, emoji, and wide characters.
|
|
53
|
+
*
|
|
54
|
+
* This is useful for:
|
|
55
|
+
* - Aligning text in a terminal
|
|
56
|
+
* - Quickly checking if a string contains ANSI escape codes
|
|
57
|
+
* - Measuring the width of a string in a terminal
|
|
58
|
+
*
|
|
59
|
+
* This API is designed to match the popular "string-width" package, so that
|
|
60
|
+
* existing code can be easily ported to Bun and vice versa.
|
|
61
|
+
*
|
|
62
|
+
* @returns The width of the string in columns
|
|
63
|
+
*
|
|
64
|
+
* ## Examples
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { stringWidth } from "bun";
|
|
68
|
+
*
|
|
69
|
+
* console.log(stringWidth("abc")); // 3
|
|
70
|
+
* console.log(stringWidth("๐ฉโ๐ฉโ๐งโ๐ฆ")); // 1
|
|
71
|
+
* console.log(stringWidth("\u001b[31mhello\u001b[39m")); // 5
|
|
72
|
+
* console.log(stringWidth("\u001b[31mhello\u001b[39m", { countAnsiEscapeCodes: false })); // 5
|
|
73
|
+
* console.log(stringWidth("\u001b[31mhello\u001b[39m", { countAnsiEscapeCodes: true })); // 13
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
function stringWidth(
|
|
78
|
+
/**
|
|
79
|
+
* The string to measure
|
|
80
|
+
*/
|
|
81
|
+
input: string,
|
|
82
|
+
options?: {
|
|
83
|
+
/**
|
|
84
|
+
* If `true`, count ANSI escape codes as part of the string width. If `false`, ANSI escape codes are ignored when calculating the string width.
|
|
85
|
+
*
|
|
86
|
+
* @default false
|
|
87
|
+
*/
|
|
88
|
+
countAnsiEscapeCodes?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* When it's ambiugous and `true`, count emoji as 2 characters wide. If `false`, emoji are counted as 1 character wide.
|
|
91
|
+
*
|
|
92
|
+
* @default false
|
|
93
|
+
*/
|
|
94
|
+
ambiguousIsNarrow?: boolean;
|
|
95
|
+
},
|
|
96
|
+
): number;
|
|
97
|
+
|
|
50
98
|
export type ShellFunction = (input: Uint8Array) => Uint8Array;
|
|
51
99
|
|
|
52
100
|
export type ShellExpression =
|
package/package.json
CHANGED
package/test.d.ts
CHANGED
|
@@ -873,6 +873,19 @@ declare module "bun:test" {
|
|
|
873
873
|
* @param expected the expected value
|
|
874
874
|
*/
|
|
875
875
|
toStrictEqual(expected: T): void;
|
|
876
|
+
/**
|
|
877
|
+
* Asserts that the value is deep equal to an element in the expected array.
|
|
878
|
+
*
|
|
879
|
+
* The value must be an array or iterable, which includes strings.
|
|
880
|
+
*
|
|
881
|
+
* @example
|
|
882
|
+
* expect(1).toBeOneOf([1,2,3]);
|
|
883
|
+
* expect("foo").toBeOneOf(["foo", "bar"]);
|
|
884
|
+
* expect(true).toBeOneOf(new Set([true]));
|
|
885
|
+
*
|
|
886
|
+
* @param expected the expected value
|
|
887
|
+
*/
|
|
888
|
+
toBeOneOf(expected: Array<unknown> | Iterable<unknown>): void;
|
|
876
889
|
/**
|
|
877
890
|
* Asserts that a value contains what is expected.
|
|
878
891
|
*
|