@sohqureshi/tokenwise 1.0.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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +260 -0
  3. package/dist/chunk-2IQAGI7Q.js +54 -0
  4. package/dist/chunk-33GBS5YN.js +288 -0
  5. package/dist/chunk-33RRCCAT.js +287 -0
  6. package/dist/chunk-3ECVBELU.js +49 -0
  7. package/dist/chunk-D4CFTFM3.js +105 -0
  8. package/dist/chunk-EUFLW42L.js +13 -0
  9. package/dist/chunk-GQ62V6ZK.js +61 -0
  10. package/dist/chunk-HKCPRPJL.js +294 -0
  11. package/dist/chunk-IAV75SZA.js +36 -0
  12. package/dist/chunk-JBKETSTK.js +270 -0
  13. package/dist/chunk-SURFMVNH.js +285 -0
  14. package/dist/chunk-TM6L7YF2.js +9 -0
  15. package/dist/chunk-YMOSWQGE.js +22 -0
  16. package/dist/cli.cjs +352 -0
  17. package/dist/cli.d.cts +1 -0
  18. package/dist/cli.d.ts +1 -0
  19. package/dist/cli.js +51 -0
  20. package/dist/core/analyze.cjs +181 -0
  21. package/dist/core/analyze.d.cts +13 -0
  22. package/dist/core/analyze.d.ts +13 -0
  23. package/dist/core/analyze.js +11 -0
  24. package/dist/core/compact.cjs +68 -0
  25. package/dist/core/compact.d.cts +3 -0
  26. package/dist/core/compact.d.ts +3 -0
  27. package/dist/core/compact.js +7 -0
  28. package/dist/core/flatten.cjs +46 -0
  29. package/dist/core/flatten.d.cts +18 -0
  30. package/dist/core/flatten.d.ts +18 -0
  31. package/dist/core/flatten.js +6 -0
  32. package/dist/core/natural.cjs +129 -0
  33. package/dist/core/natural.d.cts +28 -0
  34. package/dist/core/natural.d.ts +28 -0
  35. package/dist/core/natural.js +6 -0
  36. package/dist/core/prune.cjs +60 -0
  37. package/dist/core/prune.d.cts +11 -0
  38. package/dist/core/prune.d.ts +11 -0
  39. package/dist/core/prune.js +6 -0
  40. package/dist/core/token.cjs +33 -0
  41. package/dist/core/token.d.cts +12 -0
  42. package/dist/core/token.d.ts +12 -0
  43. package/dist/core/token.js +6 -0
  44. package/dist/core/toon.cjs +73 -0
  45. package/dist/core/toon.d.cts +25 -0
  46. package/dist/core/toon.d.ts +25 -0
  47. package/dist/core/toon.js +6 -0
  48. package/dist/index.cjs +344 -0
  49. package/dist/index.d.cts +40 -0
  50. package/dist/index.d.ts +40 -0
  51. package/dist/index.js +49 -0
  52. package/package.json +78 -0
package/dist/cli.js ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ AIChain
4
+ } from "./chunk-2IQAGI7Q.js";
5
+ import "./chunk-GQ62V6ZK.js";
6
+ import "./chunk-3ECVBELU.js";
7
+ import "./chunk-EUFLW42L.js";
8
+ import "./chunk-YMOSWQGE.js";
9
+ import "./chunk-D4CFTFM3.js";
10
+ import "./chunk-IAV75SZA.js";
11
+ import "./chunk-TM6L7YF2.js";
12
+
13
+ // src/cli.ts
14
+ import fs from "fs";
15
+ import path from "path";
16
+ var args = process.argv.slice(2);
17
+ if (args.length === 0) {
18
+ console.log(`
19
+ Usage:
20
+ tokenwise <file> [options]
21
+
22
+ Options:
23
+ --toon Convert JSON to TOON format
24
+ --compact Convert JSON to compact format
25
+ --analyze Show token analysis
26
+ `);
27
+ process.exit(0);
28
+ }
29
+ var filePath = path.resolve(process.cwd(), args[0]);
30
+ if (!fs.existsSync(filePath)) {
31
+ console.error("\u274C File not found:", filePath);
32
+ process.exit(1);
33
+ }
34
+ var raw = fs.readFileSync(filePath, "utf-8");
35
+ var json;
36
+ try {
37
+ json = JSON.parse(raw);
38
+ } catch (err) {
39
+ console.error("\u274C Invalid JSON file");
40
+ process.exit(1);
41
+ }
42
+ var tool = new AIChain(json);
43
+ if (args.includes("--toon")) {
44
+ console.log(tool.toTOON().value());
45
+ } else if (args.includes("--compact")) {
46
+ console.log(tool.compact().value());
47
+ } else if (args.includes("--analyze")) {
48
+ console.log(tool.analyze());
49
+ } else {
50
+ console.log("\u26A0\uFE0F No valid option provided. Use --toon, --compact or --analyze");
51
+ }
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/core/analyze.ts
21
+ var analyze_exports = {};
22
+ __export(analyze_exports, {
23
+ analyze: () => analyze
24
+ });
25
+ module.exports = __toCommonJS(analyze_exports);
26
+
27
+ // src/core/prune.ts
28
+ function prune(obj, options = {}) {
29
+ const normalizedOptions = Array.isArray(options) ? { removeKeys: options } : options;
30
+ const {
31
+ removeKeys = [],
32
+ removeNull = true,
33
+ removeUndefined = true,
34
+ removeEmptyObjects = true,
35
+ removeEmptyArrays = false
36
+ } = normalizedOptions;
37
+ if (obj === null) return removeNull ? void 0 : obj;
38
+ if (obj === void 0) return removeUndefined ? void 0 : obj;
39
+ if (typeof obj !== "object") return obj;
40
+ if (Array.isArray(obj)) {
41
+ const arr = obj.map((item) => prune(item, normalizedOptions)).filter((item) => item !== void 0);
42
+ if (removeEmptyArrays && arr.length === 0) {
43
+ return void 0;
44
+ }
45
+ return arr;
46
+ }
47
+ const result = {};
48
+ for (const key in obj) {
49
+ if (removeKeys.includes(key)) continue;
50
+ const value = prune(obj[key], normalizedOptions);
51
+ if (value === void 0) continue;
52
+ if (removeEmptyObjects && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0) {
53
+ continue;
54
+ }
55
+ result[key] = value;
56
+ }
57
+ return result;
58
+ }
59
+
60
+ // src/core/compact.ts
61
+ function compact(obj) {
62
+ const pruned = prune(obj);
63
+ return JSON.stringify(pruned) ?? "";
64
+ }
65
+
66
+ // src/core/flatten.ts
67
+ function flatten(obj, prefix = "", res = {}) {
68
+ if (obj === null || obj === void 0) return res;
69
+ if (typeof obj !== "object") {
70
+ res[prefix] = obj;
71
+ return res;
72
+ }
73
+ for (const key in obj) {
74
+ const value = obj[key];
75
+ const newKey = prefix ? `${prefix}.${key}` : key;
76
+ if (typeof value === "object" && value !== null) {
77
+ flatten(value, newKey, res);
78
+ } else {
79
+ res[newKey] = value;
80
+ }
81
+ }
82
+ return res;
83
+ }
84
+
85
+ // src/core/toon.ts
86
+ function toTOON(data, indent = 0) {
87
+ const space = " ".repeat(indent);
88
+ if (Array.isArray(data)) {
89
+ if (data.length === 0) return "[]";
90
+ if (data.every(isPlainObject)) {
91
+ const keys = Array.from(
92
+ new Set(data.flatMap((item) => Object.keys(item)))
93
+ );
94
+ let result = `${space}[${data.length}]{${keys.join(",")}}:
95
+ `;
96
+ for (const item of data) {
97
+ result += space + " " + keys.map((k) => formatValue(item[k])).join(",") + "\n";
98
+ }
99
+ return result;
100
+ }
101
+ return `${space}[${data.length}]: ${data.join(",")}`;
102
+ }
103
+ if (typeof data === "object" && data !== null) {
104
+ let result = "";
105
+ for (const key in data) {
106
+ const value = data[key];
107
+ if (typeof value === "object" && value !== null) {
108
+ result += `${space}${key}:
109
+ ${toTOON(value, indent + 1)}
110
+ `;
111
+ } else {
112
+ const formatted = formatValue(value);
113
+ result += formatted ? `${space}${key}: ${formatted}
114
+ ` : `${space}${key}:
115
+ `;
116
+ }
117
+ }
118
+ return result.trim();
119
+ }
120
+ return formatValue(data);
121
+ }
122
+ function formatValue(val) {
123
+ if (val === null || val === void 0) return "";
124
+ if (typeof val === "string") return val;
125
+ return String(val);
126
+ }
127
+ function isPlainObject(value) {
128
+ return typeof value === "object" && value !== null && !Array.isArray(value);
129
+ }
130
+
131
+ // src/core/token.ts
132
+ function estimateTokens(text) {
133
+ if (!text) return 0;
134
+ return Math.ceil(text.length / 4);
135
+ }
136
+
137
+ // src/core/analyze.ts
138
+ function analyze(input, options = {}) {
139
+ if (!input || typeof input === "object" && input !== null && Object.keys(input).length === 0) {
140
+ return {
141
+ originalTokens: 0,
142
+ optimizedTokens: 0,
143
+ savings: 0,
144
+ savingsPercent: 0,
145
+ optimizedData: null,
146
+ reductionRatio: 1
147
+ };
148
+ }
149
+ let originalTokens = estimateTokens(input);
150
+ if (isNaN(originalTokens) || !isFinite(originalTokens)) originalTokens = 0;
151
+ let optimizedData = input;
152
+ if (options.prune && Array.isArray(options.prune)) {
153
+ optimizedData = prune(optimizedData, options.prune);
154
+ }
155
+ if (options.compact) {
156
+ optimizedData = compact(optimizedData);
157
+ }
158
+ if (options.flatten) {
159
+ optimizedData = flatten(optimizedData);
160
+ }
161
+ if (options.toTOON === true || options.toon === true) {
162
+ optimizedData = toTOON(optimizedData);
163
+ }
164
+ let optimizedTokens = estimateTokens(optimizedData);
165
+ if (isNaN(optimizedTokens) || !isFinite(optimizedTokens)) optimizedTokens = 0;
166
+ const savings = Math.max(0, originalTokens - optimizedTokens);
167
+ const savingsPercent = originalTokens > 0 ? Math.round(savings / originalTokens * 100) : 0;
168
+ const reductionRatio = originalTokens > 0 ? optimizedTokens / originalTokens : 1;
169
+ return {
170
+ originalTokens,
171
+ optimizedTokens,
172
+ savings,
173
+ savingsPercent,
174
+ optimizedData,
175
+ reductionRatio
176
+ };
177
+ }
178
+ // Annotate the CommonJS export names for ESM import in node:
179
+ 0 && (module.exports = {
180
+ analyze
181
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Safe version of analyze() - Prevents NaN values
3
+ */
4
+ declare function analyze(input: any, options?: any): {
5
+ originalTokens: number;
6
+ optimizedTokens: number;
7
+ savings: number;
8
+ savingsPercent: number;
9
+ optimizedData: any;
10
+ reductionRatio: number;
11
+ };
12
+
13
+ export { analyze };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Safe version of analyze() - Prevents NaN values
3
+ */
4
+ declare function analyze(input: any, options?: any): {
5
+ originalTokens: number;
6
+ optimizedTokens: number;
7
+ savings: number;
8
+ savingsPercent: number;
9
+ optimizedData: any;
10
+ reductionRatio: number;
11
+ };
12
+
13
+ export { analyze };
@@ -0,0 +1,11 @@
1
+ import {
2
+ analyze
3
+ } from "../chunk-GQ62V6ZK.js";
4
+ import "../chunk-3ECVBELU.js";
5
+ import "../chunk-EUFLW42L.js";
6
+ import "../chunk-YMOSWQGE.js";
7
+ import "../chunk-IAV75SZA.js";
8
+ import "../chunk-TM6L7YF2.js";
9
+ export {
10
+ analyze
11
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/core/compact.ts
21
+ var compact_exports = {};
22
+ __export(compact_exports, {
23
+ compact: () => compact
24
+ });
25
+ module.exports = __toCommonJS(compact_exports);
26
+
27
+ // src/core/prune.ts
28
+ function prune(obj, options = {}) {
29
+ const normalizedOptions = Array.isArray(options) ? { removeKeys: options } : options;
30
+ const {
31
+ removeKeys = [],
32
+ removeNull = true,
33
+ removeUndefined = true,
34
+ removeEmptyObjects = true,
35
+ removeEmptyArrays = false
36
+ } = normalizedOptions;
37
+ if (obj === null) return removeNull ? void 0 : obj;
38
+ if (obj === void 0) return removeUndefined ? void 0 : obj;
39
+ if (typeof obj !== "object") return obj;
40
+ if (Array.isArray(obj)) {
41
+ const arr = obj.map((item) => prune(item, normalizedOptions)).filter((item) => item !== void 0);
42
+ if (removeEmptyArrays && arr.length === 0) {
43
+ return void 0;
44
+ }
45
+ return arr;
46
+ }
47
+ const result = {};
48
+ for (const key in obj) {
49
+ if (removeKeys.includes(key)) continue;
50
+ const value = prune(obj[key], normalizedOptions);
51
+ if (value === void 0) continue;
52
+ if (removeEmptyObjects && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0) {
53
+ continue;
54
+ }
55
+ result[key] = value;
56
+ }
57
+ return result;
58
+ }
59
+
60
+ // src/core/compact.ts
61
+ function compact(obj) {
62
+ const pruned = prune(obj);
63
+ return JSON.stringify(pruned) ?? "";
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ compact
68
+ });
@@ -0,0 +1,3 @@
1
+ declare function compact(obj: any): string;
2
+
3
+ export { compact };
@@ -0,0 +1,3 @@
1
+ declare function compact(obj: any): string;
2
+
3
+ export { compact };
@@ -0,0 +1,7 @@
1
+ import {
2
+ compact
3
+ } from "../chunk-EUFLW42L.js";
4
+ import "../chunk-IAV75SZA.js";
5
+ export {
6
+ compact
7
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/core/flatten.ts
21
+ var flatten_exports = {};
22
+ __export(flatten_exports, {
23
+ flatten: () => flatten
24
+ });
25
+ module.exports = __toCommonJS(flatten_exports);
26
+ function flatten(obj, prefix = "", res = {}) {
27
+ if (obj === null || obj === void 0) return res;
28
+ if (typeof obj !== "object") {
29
+ res[prefix] = obj;
30
+ return res;
31
+ }
32
+ for (const key in obj) {
33
+ const value = obj[key];
34
+ const newKey = prefix ? `${prefix}.${key}` : key;
35
+ if (typeof value === "object" && value !== null) {
36
+ flatten(value, newKey, res);
37
+ } else {
38
+ res[newKey] = value;
39
+ }
40
+ }
41
+ return res;
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ flatten
46
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Flattens nested JSON into an object with dot-notation keys.
3
+ *
4
+ * Useful for:
5
+ * - Search indexing
6
+ * - AI prompt simplification
7
+ *
8
+ * @param obj - Input object
9
+ * @param prefix - Used internally for recursion
10
+ * @returns Object with dot-notation keys
11
+ *
12
+ * Example:
13
+ * flatten({ user: { name: "Ali" } })
14
+ * -> { "user.name": "Ali" }
15
+ */
16
+ declare function flatten(obj: any, prefix?: string, res?: any): any;
17
+
18
+ export { flatten };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Flattens nested JSON into an object with dot-notation keys.
3
+ *
4
+ * Useful for:
5
+ * - Search indexing
6
+ * - AI prompt simplification
7
+ *
8
+ * @param obj - Input object
9
+ * @param prefix - Used internally for recursion
10
+ * @returns Object with dot-notation keys
11
+ *
12
+ * Example:
13
+ * flatten({ user: { name: "Ali" } })
14
+ * -> { "user.name": "Ali" }
15
+ */
16
+ declare function flatten(obj: any, prefix?: string, res?: any): any;
17
+
18
+ export { flatten };
@@ -0,0 +1,6 @@
1
+ import {
2
+ flatten
3
+ } from "../chunk-YMOSWQGE.js";
4
+ export {
5
+ flatten
6
+ };
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/core/natural.ts
21
+ var natural_exports = {};
22
+ __export(natural_exports, {
23
+ toNatural: () => toNatural
24
+ });
25
+ module.exports = __toCommonJS(natural_exports);
26
+ function toNatural(data, depth = 0) {
27
+ if (data === null || data === void 0) return "nothing";
28
+ if (typeof data === "string") return data;
29
+ if (typeof data === "number") return String(data);
30
+ if (typeof data === "boolean") return data ? "yes" : "no";
31
+ if (Array.isArray(data)) {
32
+ if (data.length === 0) return "empty list";
33
+ if (data.every(isPlainObject)) {
34
+ return data.map((item, index) => `${index + 1}. ${stripTrailingPeriod(toNatural(item, depth + 1))}.`).join(" ");
35
+ }
36
+ const items = data.map((item) => toNatural(item, depth + 1));
37
+ return joinNaturalList(items);
38
+ }
39
+ if (typeof data === "object") {
40
+ return buildContextualStory(data, depth);
41
+ }
42
+ return String(data);
43
+ }
44
+ function buildContextualStory(obj, depth = 0) {
45
+ let name = obj.name || obj.userName || obj.user;
46
+ if (typeof name === "object" && name !== null && name.name) {
47
+ name = name.name;
48
+ }
49
+ const entries = Object.entries(obj).filter(([key]) => {
50
+ return !["id", "timestamp", "apiKey"].includes(key);
51
+ });
52
+ if (entries.length === 0) return "";
53
+ let story = name && typeof name === "string" ? `User ${name}` : "";
54
+ const clauses = entries.map(([key, value]) => {
55
+ if (key === "user" && name && typeof value === "object" && value !== null && !Array.isArray(value)) {
56
+ const userProps = Object.entries(value).filter(([k]) => !["id", "name", "timestamp", "apiKey"].includes(k)).map(([k, v]) => formatPropertyClause(k, v, depth + 1)).filter((c) => c !== null && c !== "").join(", ");
57
+ return userProps ? `(${userProps})` : null;
58
+ }
59
+ return formatPropertyClause(key, value, depth);
60
+ }).filter((c) => c !== null && c !== "");
61
+ if (clauses.length === 0) return story;
62
+ if (story) {
63
+ story += " " + clauses.join(", ");
64
+ } else {
65
+ story = clauses.join(", ");
66
+ }
67
+ return story + ".";
68
+ }
69
+ function formatPropertyClause(key, value, depth) {
70
+ const naturalKey = camelToWords(key);
71
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
72
+ if (["internal", "metadata", "debug"].includes(key)) {
73
+ return null;
74
+ }
75
+ const nested = Object.entries(value).filter(([k]) => !["id", "timestamp", "apiKey", "createdAt", "updatedAt"].includes(k)).map(([k, v]) => {
76
+ if (typeof v === "object" && v !== null) {
77
+ return formatPropertyClause(k, v, depth + 1);
78
+ }
79
+ const propValue = toNatural(v, depth + 1);
80
+ if (propValue === "yes" || propValue === "no") {
81
+ return `${camelToWords(k)} ${propValue === "yes" ? "enabled" : "disabled"}`;
82
+ }
83
+ return `${camelToWords(k)} ${propValue}`;
84
+ }).filter((c) => c && c.trim()).join(", ");
85
+ if (!nested) return null;
86
+ return `${naturalKey}: ${nested}`;
87
+ }
88
+ if (Array.isArray(value)) {
89
+ if (value.length === 0) return null;
90
+ if (["skills", "hobbies", "interests", "tags", "languages", "items"].includes(key)) {
91
+ const items2 = value.map((item) => {
92
+ const str = String(item);
93
+ return str.charAt(0).toUpperCase() + str.slice(1);
94
+ });
95
+ return `Having ${joinNaturalList(items2)}`;
96
+ }
97
+ const items = joinNaturalList(value.map((item) => toNatural(item, depth + 1)));
98
+ return `${naturalKey}: ${items}`;
99
+ }
100
+ const naturalValue = toNatural(value, depth + 1);
101
+ if (naturalValue === "yes") return `${naturalKey} enabled`;
102
+ if (naturalValue === "no") return `${naturalKey} disabled`;
103
+ if (key === "theme") return `prefers the ${naturalValue} ${key}`;
104
+ if (key === "age") return `age: ${naturalValue}`;
105
+ if (key === "email") return `email: ${naturalValue}`;
106
+ if (key === "city") return `address: ${naturalValue}`;
107
+ if (key === "debug" && naturalValue === "yes") return `debug enabled`;
108
+ return `${naturalKey}: ${naturalValue}`;
109
+ }
110
+ function camelToWords(str) {
111
+ return str.replace(/([A-Z])/g, " $1").toLowerCase().trim();
112
+ }
113
+ function isPlainObject(value) {
114
+ return typeof value === "object" && value !== null && !Array.isArray(value);
115
+ }
116
+ function joinNaturalList(items) {
117
+ if (items.length === 0) return "";
118
+ if (items.length === 1) return items[0];
119
+ if (items.length === 2) return `${items[0]} and ${items[1]}`;
120
+ const lastItem = items[items.length - 1];
121
+ return `${items.slice(0, -1).join(", ")} and ${lastItem}`;
122
+ }
123
+ function stripTrailingPeriod(value) {
124
+ return value.replace(/\.+$/, "");
125
+ }
126
+ // Annotate the CommonJS export names for ESM import in node:
127
+ 0 && (module.exports = {
128
+ toNatural
129
+ });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Converts JSON into natural language story format.
3
+ *
4
+ * Goal:
5
+ * - Transform structured data into human-readable narratives
6
+ * - Identify subjects (names, users) and describe their properties
7
+ * - Support arrays, nested objects, and primitive types
8
+ * - Skip technical metadata fields for cleaner output
9
+ *
10
+ * @param data - Input JSON data
11
+ * @returns Natural language story string
12
+ *
13
+ * Example:
14
+ * Input:
15
+ * {
16
+ * "user": {
17
+ * "name": "Alice Johnson",
18
+ * "email": "alice@example.com",
19
+ * "skills": ["Python", "JavaScript"]
20
+ * }
21
+ * }
22
+ *
23
+ * Output:
24
+ * "User Alice Johnson (email: alice@example.com, Having Python and JavaScript)."
25
+ */
26
+ declare function toNatural(data: any, depth?: number): string;
27
+
28
+ export { toNatural };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Converts JSON into natural language story format.
3
+ *
4
+ * Goal:
5
+ * - Transform structured data into human-readable narratives
6
+ * - Identify subjects (names, users) and describe their properties
7
+ * - Support arrays, nested objects, and primitive types
8
+ * - Skip technical metadata fields for cleaner output
9
+ *
10
+ * @param data - Input JSON data
11
+ * @returns Natural language story string
12
+ *
13
+ * Example:
14
+ * Input:
15
+ * {
16
+ * "user": {
17
+ * "name": "Alice Johnson",
18
+ * "email": "alice@example.com",
19
+ * "skills": ["Python", "JavaScript"]
20
+ * }
21
+ * }
22
+ *
23
+ * Output:
24
+ * "User Alice Johnson (email: alice@example.com, Having Python and JavaScript)."
25
+ */
26
+ declare function toNatural(data: any, depth?: number): string;
27
+
28
+ export { toNatural };
@@ -0,0 +1,6 @@
1
+ import {
2
+ toNatural
3
+ } from "../chunk-D4CFTFM3.js";
4
+ export {
5
+ toNatural
6
+ };