@forwardimpact/libutil 0.1.62 → 0.1.63

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.
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ import { countTokens } from "@forwardimpact/libutil";
3
+
4
+ /**
5
+ * Counts tokens in the provided text
6
+ * Usage: fit-tiktoken <text>
7
+ * echo "text" | fit-tiktoken
8
+ * @returns {Promise<void>}
9
+ */
10
+ async function main() {
11
+ let text = process.argv.slice(2).join(" ");
12
+
13
+ if (!text && !process.stdin.isTTY) {
14
+ const chunks = [];
15
+ for await (const chunk of process.stdin) {
16
+ chunks.push(chunk);
17
+ }
18
+ text = Buffer.concat(chunks).toString().trim();
19
+ }
20
+
21
+ if (!text) {
22
+ console.error("Usage: fit-tiktoken <text>");
23
+ console.error(' echo "text" | fit-tiktoken');
24
+ process.exit(1);
25
+ }
26
+
27
+ console.log(countTokens(text));
28
+ }
29
+
30
+ main().catch((error) => {
31
+ console.error(error.message);
32
+ process.exit(1);
33
+ });
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@forwardimpact/libutil",
3
- "version": "0.1.62",
3
+ "version": "0.1.63",
4
4
  "description": "Utility functions and utilities for Guide",
5
5
  "license": "Apache-2.0",
6
6
  "author": "D. Olsson <hi@senzilla.io>",
7
7
  "type": "module",
8
8
  "main": "index.js",
9
9
  "bin": {
10
- "fit-download-bundle": "./bin/fit-download-bundle.js"
10
+ "fit-download-bundle": "./bin/fit-download-bundle.js",
11
+ "fit-tiktoken": "./bin/fit-tiktoken.js"
11
12
  },
12
13
  "engines": {
13
14
  "node": ">=22.0.0"