opencode-trim 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hüseyin Hadi Çığ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,35 @@
1
- # Temporary Holding Version
1
+ # opencode-trim
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lightweight, zero-dependency context and text trimming utilities for OpenCode plugins, multi-agent workflows, and AI prompts.
4
+
5
+ ## Features
6
+
7
+ - **Whitespace Normalization:** Cleans up unnecessary spaces and collapses redundant line breaks.
8
+ - **Character & Ellipsis Trimming:** Truncates prompt or response text safely to stay within character limits.
9
+ - **Line Trimming:** Truncates log or stack trace outputs to a fixed number of lines.
10
+ - **Zero Dependencies:** Pure ESM with TypeScript type declarations included.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install opencode-trim
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```javascript
21
+ import { trimWhitespace, trimChars, trimLines } from "opencode-trim";
22
+
23
+ // Normalize whitespace and blank lines
24
+ const cleanText = trimWhitespace(" Hello World \n\n\n\n Foo ");
25
+
26
+ // Trim characters with ellipsis
27
+ const truncated = trimChars("Long context string...", 10);
28
+
29
+ // Trim lines
30
+ const firstFiveLines = trimLines(multiLineLogs, 5);
31
+ ```
32
+
33
+ ## License
34
+
35
+ MIT © [Hüseyin Hadi Çığ](https://github.com/huseyincig)
package/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export declare function trimWhitespace(text: string): string;
2
+ export declare function trimChars(text: string, maxLength: number, ellipsis?: string): string;
3
+ export declare function trimLines(text: string, maxLines: number): string;
4
+
5
+ declare const _default: {
6
+ trimWhitespace: typeof trimWhitespace;
7
+ trimChars: typeof trimChars;
8
+ trimLines: typeof trimLines;
9
+ };
10
+
11
+ export default _default;
package/index.js ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Trims leading and trailing whitespace per line, collapses multiple spaces and excessive empty lines.
3
+ * @param {string} text
4
+ * @returns {string}
5
+ */
6
+ export function trimWhitespace(text) {
7
+ if (typeof text !== "string") return "";
8
+ return text
9
+ .split(/\r?\n/)
10
+ .map((line) => line.trim().replace(/[ \t]+/g, " "))
11
+ .join("\n")
12
+ .replace(/\n{3,}/g, "\n\n")
13
+ .trim();
14
+ }
15
+
16
+ /**
17
+ * Trims a text string to a maximum character length with an optional ellipsis.
18
+ * @param {string} text
19
+ * @param {number} maxLength
20
+ * @param {string} [ellipsis="..."]
21
+ * @returns {string}
22
+ */
23
+ export function trimChars(text, maxLength, ellipsis = "...") {
24
+ if (typeof text !== "string") return "";
25
+ if (maxLength <= 0) return "";
26
+ if (text.length <= maxLength) return text;
27
+ return text.slice(0, Math.max(0, maxLength - ellipsis.length)) + ellipsis;
28
+ }
29
+
30
+ /**
31
+ * Trims excess lines from text to fit within maxLines.
32
+ * @param {string} text
33
+ * @param {number} maxLines
34
+ * @returns {string}
35
+ */
36
+ export function trimLines(text, maxLines) {
37
+ if (typeof text !== "string") return "";
38
+ if (maxLines <= 0) return "";
39
+ const lines = text.split(/\r?\n/);
40
+ if (lines.length <= maxLines) return text;
41
+ return lines.slice(0, maxLines).join("\n");
42
+ }
43
+
44
+ export default {
45
+ trimWhitespace,
46
+ trimChars,
47
+ trimLines,
48
+ };
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "opencode-trim",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Context and text trimming utilities for OpenCode plugins and workflows",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "types": "./index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "import": "./index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "index.js",
16
+ "index.d.ts",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "test": "node --test"
22
+ },
23
+ "keywords": [
24
+ "opencode",
25
+ "trim",
26
+ "prompt-trimming",
27
+ "context-window",
28
+ "ai"
29
+ ],
30
+ "author": "Hüseyin Hadi Çığ",
31
+ "license": "MIT"
32
+ }