utilium 3.0.0 → 3.1.1

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/shell.d.ts CHANGED
@@ -1,8 +1,9 @@
1
+ import type { Terminal } from '@xterm/xterm';
1
2
  /**
2
- * A simple wrapper for xterm.js that makes implementing shells easier
3
- * Copyright (c) 2025 James Prevett
3
+ * Parse a line into arguments.
4
+ * Supports single and double quoted strings as well as backslash escaping.
4
5
  */
5
- import type { Terminal } from '@xterm/xterm';
6
+ export declare function splitIntoArgs(input: string): string[];
6
7
  export interface ShellOptions {
7
8
  /**
8
9
  * The terminal associated with the context
@@ -40,6 +41,6 @@ export interface ShellContext extends Required<ShellOptions> {
40
41
  inputs: string[];
41
42
  }
42
43
  /**
43
- * Creates a new shell using the provided options
44
+ * A simple wrapper for xterm.js that makes implementing shells easier.
44
45
  */
45
46
  export declare function createShell(options: ShellOptions): ShellContext;
package/dist/shell.js CHANGED
@@ -1,8 +1,40 @@
1
- // SPDX-License-Identifier: LGPL-3.0-or-later
2
1
  /**
3
- * A simple wrapper for xterm.js that makes implementing shells easier
4
- * Copyright (c) 2025 James Prevett
2
+ * Parse a line into arguments.
3
+ * Supports single and double quoted strings as well as backslash escaping.
5
4
  */
5
+ export function splitIntoArgs(input) {
6
+ const args = [];
7
+ let current = '', inQuote = null, escape = false;
8
+ for (const char of input) {
9
+ if (escape) {
10
+ current += char;
11
+ escape = false;
12
+ }
13
+ else if (char === '\\') {
14
+ escape = true;
15
+ }
16
+ else if (inQuote) {
17
+ if (char === inQuote)
18
+ inQuote = null;
19
+ else
20
+ current += char;
21
+ }
22
+ else if (char === '"' || char === "'")
23
+ inQuote = char;
24
+ else if (/\s/.test(char)) {
25
+ if (current.length) {
26
+ args.push(current);
27
+ current = '';
28
+ }
29
+ }
30
+ else {
31
+ current += char;
32
+ }
33
+ }
34
+ if (current.length)
35
+ args.push(current);
36
+ return args;
37
+ }
6
38
  async function handleData($, data) {
7
39
  if ($.index == -1) {
8
40
  $.currentInput = $.input;
@@ -67,7 +99,7 @@ async function handleData($, data) {
67
99
  }
68
100
  }
69
101
  /**
70
- * Creates a new shell using the provided options
102
+ * A simple wrapper for xterm.js that makes implementing shells easier.
71
103
  */
72
104
  export function createShell(options) {
73
105
  const context = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "description": "Typescript utilities",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -57,5 +57,14 @@
57
57
  },
58
58
  "engines": {
59
59
  "node": ">=22.0.0"
60
+ },
61
+ "prettier": {
62
+ "singleQuote": true,
63
+ "useTabs": true,
64
+ "trailingComma": "es5",
65
+ "tabWidth": 4,
66
+ "printWidth": 120,
67
+ "arrowParens": "avoid",
68
+ "experimentalOperatorPosition": "start"
60
69
  }
61
70
  }