utilium 0.8.3 → 0.8.5

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/numbers.d.ts CHANGED
@@ -1,3 +1,8 @@
1
1
  export declare function range(min: number, max: number): number[];
2
2
  export declare function toDegrees(radians: number): number;
3
3
  export declare function toRadians(degrees: number): number;
4
+ export declare const formatCompact: {
5
+ (value: number): string;
6
+ (value: number | bigint): string;
7
+ (value: number | bigint | Intl.StringNumericLiteral): string;
8
+ };
package/dist/numbers.js CHANGED
@@ -11,3 +11,5 @@ export function toDegrees(radians) {
11
11
  export function toRadians(degrees) {
12
12
  return (degrees / 180) * Math.PI;
13
13
  }
14
+ const __formatter = Intl.NumberFormat('en', { notation: 'compact' });
15
+ export const formatCompact = __formatter.format.bind(__formatter);
package/dist/shell.d.ts CHANGED
@@ -8,6 +8,10 @@ export interface ShellOptions {
8
8
  * The prompt to use, can be a getter.
9
9
  */
10
10
  readonly prompt?: string;
11
+ /**
12
+ * The length to use for the prompt. Useful if escape sequences are used in the prompt.
13
+ */
14
+ readonly promptLength?: number;
11
15
  /**
12
16
  * The handler for when a line is parsed
13
17
  */
package/dist/shell.js CHANGED
@@ -5,7 +5,7 @@ function handleData($, data) {
5
5
  function clear() {
6
6
  $.terminal.write('\x1b[2K\r' + $.prompt);
7
7
  }
8
- const x = $.terminal.buffer.active.cursorX - $.prompt.length;
8
+ const x = $.terminal.buffer.active.cursorX - $.promptLength;
9
9
  switch (data) {
10
10
  case 'ArrowUp':
11
11
  case '\x1b[A':
@@ -34,10 +34,10 @@ function handleData($, data) {
34
34
  }
35
35
  break;
36
36
  case '\x1b[F':
37
- $.terminal.write(`\x1b[${$.prompt.length + $.currentInput.length + 1}G`);
37
+ $.terminal.write(`\x1b[${$.promptLength + $.currentInput.length + 1}G`);
38
38
  break;
39
39
  case '\x1b[H':
40
- $.terminal.write(`\x1b[${$.prompt.length + 1}G`);
40
+ $.terminal.write(`\x1b[${$.promptLength + 1}G`);
41
41
  break;
42
42
  case '\x7f':
43
43
  if (x <= 0) {
@@ -70,6 +70,9 @@ export function createShell(options) {
70
70
  get prompt() {
71
71
  return options.prompt ?? '';
72
72
  },
73
+ get promptLength() {
74
+ return options.promptLength ?? this.prompt.length;
75
+ },
73
76
  onLine: options.onLine ?? (() => { }),
74
77
  input: '',
75
78
  index: -1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "Typescript utilities",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/numbers.ts CHANGED
@@ -13,3 +13,7 @@ export function toDegrees(radians: number): number {
13
13
  export function toRadians(degrees: number): number {
14
14
  return (degrees / 180) * Math.PI;
15
15
  }
16
+
17
+ const __formatter = Intl.NumberFormat('en', { notation: 'compact' });
18
+
19
+ export const formatCompact = __formatter.format.bind(__formatter);
package/src/shell.ts CHANGED
@@ -12,6 +12,11 @@ export interface ShellOptions {
12
12
  */
13
13
  readonly prompt?: string;
14
14
 
15
+ /**
16
+ * The length to use for the prompt. Useful if escape sequences are used in the prompt.
17
+ */
18
+ readonly promptLength?: number;
19
+
15
20
  /**
16
21
  * The handler for when a line is parsed
17
22
  */
@@ -48,7 +53,7 @@ function handleData($: ShellContext, data: string) {
48
53
  function clear(): void {
49
54
  $.terminal.write('\x1b[2K\r' + $.prompt);
50
55
  }
51
- const x = $.terminal.buffer.active.cursorX - $.prompt.length;
56
+ const x = $.terminal.buffer.active.cursorX - $.promptLength;
52
57
  switch (data) {
53
58
  case 'ArrowUp':
54
59
  case '\x1b[A':
@@ -77,10 +82,10 @@ function handleData($: ShellContext, data: string) {
77
82
  }
78
83
  break;
79
84
  case '\x1b[F':
80
- $.terminal.write(`\x1b[${$.prompt.length + $.currentInput.length + 1}G`);
85
+ $.terminal.write(`\x1b[${$.promptLength + $.currentInput.length + 1}G`);
81
86
  break;
82
87
  case '\x1b[H':
83
- $.terminal.write(`\x1b[${$.prompt.length + 1}G`);
88
+ $.terminal.write(`\x1b[${$.promptLength + 1}G`);
84
89
  break;
85
90
  case '\x7f':
86
91
  if (x <= 0) {
@@ -114,6 +119,9 @@ export function createShell(options: ShellOptions): ShellContext {
114
119
  get prompt() {
115
120
  return options.prompt ?? '';
116
121
  },
122
+ get promptLength() {
123
+ return options.promptLength ?? this.prompt.length;
124
+ },
117
125
  onLine: options.onLine ?? (() => {}),
118
126
  input: '',
119
127
  index: -1,