toon-formatter 2.2.0 โ 2.3.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/CHANGELOG.md +19 -0
- package/README.md +59 -1
- package/package.json +2 -2
- package/src/constants.js +142 -0
- package/src/csv_formatter/index.js +49 -24
- package/src/index.js +27 -13
- package/src/json_formatter/index.js +49 -24
- package/src/utils.js +302 -0
- package/src/xml_formatter/index.js +49 -24
- package/src/yaml_formatter/index.js +25 -13
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,25 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
## [2.3.0] - 2026-01-27
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **๐ง Smart Code Optimization**
|
|
11
|
+
- New preprocessing pipeline to maximize token efficiency for LLM contexts
|
|
12
|
+
- **Code Detection & Reduction**: Automatic identification, comment stripping, and whitespace compression for scripts and commands
|
|
13
|
+
- **Safe Expensive Words Replacement**: Case-insensitive abbreviation of 100+ verbose phrases in natural language text
|
|
14
|
+
- **Security & Integrity**: Replacement logic strictly avoids altering code blocks or data (JSON/XML/CSV) to prevent syntactic issues
|
|
15
|
+
- **Seamless Integration**: Automatically active for all mixed-text conversion methods (`jsonToToon`, `xmlToToon`, `csvToToon`, etc.)
|
|
16
|
+
- **๐งช Expanded Test Infrastructure**
|
|
17
|
+
- Dedicated `code-optimization.test.js` for unit verification
|
|
18
|
+
- New `optimization-integration.test.js` for high-level mixed-content validation
|
|
19
|
+
- Total test suite expanded to 189 tests with 100% pass rate
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Refined `isCode` heuristics to support common Node.js and shell execution patterns
|
|
23
|
+
- Optimized asynchronous pipeline in `dataManagerAsync` for better performance
|
|
24
|
+
- Improved mixed-text extraction robustness in `utils.js`
|
|
25
|
+
|
|
7
26
|
|
|
8
27
|
## [2.1.1] - 2025-12-18
|
|
9
28
|
|
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ users[3]{id,name,active}:
|
|
|
61
61
|
|
|
62
62
|
## ๐ป CLI Utility
|
|
63
63
|
|
|
64
|
-
**NEW in v2.
|
|
64
|
+
**NEW in v2.2.0**: TOON Formatter now includes a powerful CLI utility for fast data conversion directly from your terminal!
|
|
65
65
|
|
|
66
66
|
### Global Installation
|
|
67
67
|
To use the `toon-formatter` command anywhere:
|
|
@@ -305,6 +305,64 @@ All conversion functions are available in both **synchronous** and **asynchronou
|
|
|
305
305
|
|
|
306
306
|
---
|
|
307
307
|
|
|
308
|
+
## ๐ง Smart Code Optimization
|
|
309
|
+
|
|
310
|
+
**NEW in v2.3.0**: The TOON Converter now features **Smart Code Optimization**, a preprocessing pipeline designed to maximize token efficiency when dealing with mixed text and code blocks.
|
|
311
|
+
|
|
312
|
+
### Overview
|
|
313
|
+
|
|
314
|
+
LLMs often process documentation or chat history that contains a mix of natural language, code snippets, and data (JSON/XML/CSV). Smart Code Optimization automatically cleans and compresses this content before conversion, resulting in even lower token counts.
|
|
315
|
+
|
|
316
|
+
### Core Components
|
|
317
|
+
|
|
318
|
+
#### 1. Code Detection & Reduction
|
|
319
|
+
The library uses heuristics to detect code blocks (npm/git commands, shebangs, common programming patterns). Detected blocks are:
|
|
320
|
+
- **Comment Stripped**: Single-line comments (`#` or `//`) are removed.
|
|
321
|
+
- **Whitespace Compressed**: Multiple newlines are collapsed into single breaks.
|
|
322
|
+
- **Preserved**: The semantic structure of the code is maintained while removing "token noise".
|
|
323
|
+
|
|
324
|
+
#### 2. Expensive Words Replacement (Safe)
|
|
325
|
+
The library contains a dictionary of **100+ verbose phrases** (Contracted/Common/Technical) and automatically replaces them with token-efficient abbreviations.
|
|
326
|
+
|
|
327
|
+
> [!IMPORTANT]
|
|
328
|
+
> To maintain syntactic integrity, these replacements are **ONLY applied to natural language text**. Both **code blocks and data blocks (JSON/XML/CSV/TOON) are strictly preserved** and never modified by this process.
|
|
329
|
+
|
|
330
|
+
#### 3. Targeted Data Extraction
|
|
331
|
+
When using `jsonToToon`, `xmlToToon`, or `csvToToon`, the library:
|
|
332
|
+
1. Extracts valid data blocks and code snippets from the text.
|
|
333
|
+
2. Applies phrase replacements **only** to the remaining natural language text.
|
|
334
|
+
3. Re-inserts the converted data and reduced code blocks into the resulting string.
|
|
335
|
+
|
|
336
|
+
### How it works (Example)
|
|
337
|
+
|
|
338
|
+
**Input Mixed Text:**
|
|
339
|
+
```
|
|
340
|
+
Please review this large language model configuration as soon as possible:
|
|
341
|
+
{"model": "gpt-4", "temp": 0.7}
|
|
342
|
+
|
|
343
|
+
npm install openai // install the helper library
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
**Optimized TOON Output:**
|
|
347
|
+
```
|
|
348
|
+
pls review this llm configuration asap:
|
|
349
|
+
model: "gpt-4"
|
|
350
|
+
temp: 0.7
|
|
351
|
+
|
|
352
|
+
npm install openai
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### Supported Formats
|
|
356
|
+
|
|
357
|
+
Smart Code Optimization is active by default for all methods starting with `jsonTo`, `xmlTo`, and `csvTo`:
|
|
358
|
+
|
|
359
|
+
- โ
`jsonToToon()`, `jsonToYaml()`, `jsonToXml()`...
|
|
360
|
+
- โ
`xmlToToon()`, `xmlToJson()`, `xmlToCsv()`...
|
|
361
|
+
- โ
`csvToToon()`, `csvToJson()`, `csvToXml()`...
|
|
362
|
+
- โ `yamlToToon()`, `toonToJson()` (These remain **Pure Data** only)
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
308
366
|
## ๐ฏ Mixed Text Support
|
|
309
367
|
|
|
310
368
|
### What is Mixed Text?
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toon-formatter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"funding": {
|
|
5
5
|
"type": "github",
|
|
6
6
|
"url": "https://github.com/sponsors/ankitpal181"
|
|
@@ -72,4 +72,4 @@
|
|
|
72
72
|
"./xml-converter": "./src/xml_formatter/index.js",
|
|
73
73
|
"./csv-converter": "./src/csv_formatter/index.js"
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOON Converter Constants
|
|
3
|
+
*
|
|
4
|
+
* Contains configuration values and optimization dictionaries.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* EXPENSIVE_WORDS Dictionary
|
|
9
|
+
*
|
|
10
|
+
* Maps verbose phrases to their token-efficient abbreviations.
|
|
11
|
+
* Used by Smart Code Optimization to reduce token count in text.
|
|
12
|
+
*
|
|
13
|
+
* These replacements are ONLY applied to non-code text to preserve
|
|
14
|
+
* code syntax integrity.
|
|
15
|
+
*/
|
|
16
|
+
export const EXPENSIVE_WORDS = {
|
|
17
|
+
// Contractions
|
|
18
|
+
"i am": "i'm",
|
|
19
|
+
"do not": "don't",
|
|
20
|
+
"would not": "wouldn't",
|
|
21
|
+
"i will": "i'll",
|
|
22
|
+
"i have": "i've",
|
|
23
|
+
"you are": "you're",
|
|
24
|
+
"we will": "we'll",
|
|
25
|
+
"they are": "they're",
|
|
26
|
+
"it is": "it's",
|
|
27
|
+
"could have": "could've",
|
|
28
|
+
"should not": "shouldn't",
|
|
29
|
+
"has not": "hasn't",
|
|
30
|
+
"there is": "there's",
|
|
31
|
+
|
|
32
|
+
// Abbreviations - Common Phrases
|
|
33
|
+
"as soon as possible": "asap",
|
|
34
|
+
"frequently asked questions": "faq",
|
|
35
|
+
"user interface": "ui",
|
|
36
|
+
"to be determined": "tbd",
|
|
37
|
+
"by the way": "btw",
|
|
38
|
+
"artificial intelligence": "ai",
|
|
39
|
+
"large language model": "llm",
|
|
40
|
+
"point of view": "pov",
|
|
41
|
+
"for your information": "fyi",
|
|
42
|
+
"estimated time of arrival": "eta",
|
|
43
|
+
"end of day": "eod",
|
|
44
|
+
|
|
45
|
+
// Informal Contractions
|
|
46
|
+
"going to": "gonna",
|
|
47
|
+
"want to": "wanna",
|
|
48
|
+
"got to": "gotta",
|
|
49
|
+
"give me": "gimme",
|
|
50
|
+
"kind of": "kinda",
|
|
51
|
+
"don't know": "dunno",
|
|
52
|
+
"thank you": "thanks",
|
|
53
|
+
|
|
54
|
+
// Abbreviations - Titles/Places
|
|
55
|
+
"doctor": "dr.",
|
|
56
|
+
"street": "st.",
|
|
57
|
+
"avenue": "ave.",
|
|
58
|
+
"incorporated": "inc.",
|
|
59
|
+
|
|
60
|
+
// Abbreviations - General
|
|
61
|
+
"utility": "util",
|
|
62
|
+
"laboratory": "lab",
|
|
63
|
+
"photograph": "photo",
|
|
64
|
+
"refrigerator": "fridge",
|
|
65
|
+
"vegetables": "veggies",
|
|
66
|
+
"mathematics": "math",
|
|
67
|
+
"gymnasium": "gym",
|
|
68
|
+
"advertisement": "ad",
|
|
69
|
+
"vegetarian": "veg",
|
|
70
|
+
|
|
71
|
+
// Synonym Simplifications
|
|
72
|
+
"approximate": "approx",
|
|
73
|
+
"regarding": "re:",
|
|
74
|
+
"information": "info",
|
|
75
|
+
"amount": "amt",
|
|
76
|
+
"reference": "ref",
|
|
77
|
+
"management": "mgmt",
|
|
78
|
+
"number": "no.",
|
|
79
|
+
"because": "as",
|
|
80
|
+
"without": "w/o",
|
|
81
|
+
"before": "b4",
|
|
82
|
+
"between": "btw",
|
|
83
|
+
"example": "e.g.",
|
|
84
|
+
"demonstrate": "show",
|
|
85
|
+
"utilize": "use",
|
|
86
|
+
"purchase": "buy",
|
|
87
|
+
"sufficient": "enough",
|
|
88
|
+
"assist": "help",
|
|
89
|
+
"request": "ask",
|
|
90
|
+
"inexpensive": "cheap",
|
|
91
|
+
"tomorrow": "tmrw",
|
|
92
|
+
"message": "msg",
|
|
93
|
+
"people": "ppl",
|
|
94
|
+
"please": "pls",
|
|
95
|
+
"business": "biz",
|
|
96
|
+
"favorite": "fav",
|
|
97
|
+
"every": "ea.",
|
|
98
|
+
"minute": "min",
|
|
99
|
+
"second": "sec",
|
|
100
|
+
"annually": "yearly",
|
|
101
|
+
"and": "&",
|
|
102
|
+
"resulting in": "leads to",
|
|
103
|
+
"important": "imp.",
|
|
104
|
+
"versus": "vs",
|
|
105
|
+
"determine": "find",
|
|
106
|
+
"terminate": "end",
|
|
107
|
+
"initialize": "start",
|
|
108
|
+
"commence": "begin",
|
|
109
|
+
"equivalent": "same",
|
|
110
|
+
"acquire": "get",
|
|
111
|
+
"maximum": "max",
|
|
112
|
+
"minimum": "min",
|
|
113
|
+
"miscellaneous": "misc",
|
|
114
|
+
"introduction": "intro",
|
|
115
|
+
"definition": "def",
|
|
116
|
+
"character": "char",
|
|
117
|
+
"equation": "eq",
|
|
118
|
+
"weight": "wt",
|
|
119
|
+
"height": "ht",
|
|
120
|
+
"quantity": "qty",
|
|
121
|
+
"average": "avg",
|
|
122
|
+
"standard": "std",
|
|
123
|
+
"package": "pkg",
|
|
124
|
+
"document": "doc",
|
|
125
|
+
"government": "govt",
|
|
126
|
+
|
|
127
|
+
// Days/Months
|
|
128
|
+
"january": "jan",
|
|
129
|
+
"february": "feb",
|
|
130
|
+
"august": "aug",
|
|
131
|
+
"september": "sept",
|
|
132
|
+
"october": "oct",
|
|
133
|
+
"november": "nov",
|
|
134
|
+
"december": "dec",
|
|
135
|
+
"monday": "mon",
|
|
136
|
+
"tuesday": "tue",
|
|
137
|
+
"wednesday": "wed",
|
|
138
|
+
"thursday": "thur",
|
|
139
|
+
"friday": "fri",
|
|
140
|
+
"saturday": "sat",
|
|
141
|
+
"sunday": "sun"
|
|
142
|
+
};
|
|
@@ -7,6 +7,7 @@ import { csvToJson, csvToJsonSync, jsonToCsv, jsonToCsvSync } from '../json_form
|
|
|
7
7
|
import { csvToYaml, csvToYamlSync, yamlToCsv, yamlToCsvSync } from '../yaml_formatter/csv.js';
|
|
8
8
|
import { csvToXml, csvToXmlSync, xmlToCsv, xmlToCsvSync } from '../xml_formatter/csv.js';
|
|
9
9
|
import { validateCsvString, validateCsvStringSync } from './validator.js';
|
|
10
|
+
import { dataManager, dataManagerAsync, extractJsonFromString, extractXmlFromString, extractCsvFromString } from '../utils.js';
|
|
10
11
|
|
|
11
12
|
export class CsvConverter {
|
|
12
13
|
/**
|
|
@@ -120,8 +121,9 @@ export class CsvConverter {
|
|
|
120
121
|
*/
|
|
121
122
|
toToon(csvString, options = {}) {
|
|
122
123
|
const { conversionMode = 'no_encryption' } = options;
|
|
124
|
+
const optimizedConverterFn = dataManager(csvToToonSync, extractCsvFromString);
|
|
123
125
|
return this._convertWithEncryption(
|
|
124
|
-
(data) =>
|
|
126
|
+
(data) => optimizedConverterFn(data),
|
|
125
127
|
csvString,
|
|
126
128
|
conversionMode
|
|
127
129
|
);
|
|
@@ -136,8 +138,9 @@ export class CsvConverter {
|
|
|
136
138
|
*/
|
|
137
139
|
async toToonAsync(csvString, options = {}) {
|
|
138
140
|
const { conversionMode = 'no_encryption' } = options;
|
|
141
|
+
const optimizedConverterFn = dataManagerAsync(csvToToon, extractCsvFromString);
|
|
139
142
|
return this._convertWithEncryptionAsync(
|
|
140
|
-
async (data) =>
|
|
143
|
+
async (data) => optimizedConverterFn(data),
|
|
141
144
|
csvString,
|
|
142
145
|
conversionMode
|
|
143
146
|
);
|
|
@@ -154,8 +157,9 @@ export class CsvConverter {
|
|
|
154
157
|
*/
|
|
155
158
|
fromJson(jsonData, options = {}) {
|
|
156
159
|
const { conversionMode = 'no_encryption' } = options;
|
|
160
|
+
const optimizedConverterFn = dataManager(jsonToCsvSync, extractJsonFromString);
|
|
157
161
|
return this._convertWithEncryption(
|
|
158
|
-
(data) =>
|
|
162
|
+
(data) => optimizedConverterFn(data),
|
|
159
163
|
jsonData,
|
|
160
164
|
conversionMode
|
|
161
165
|
);
|
|
@@ -170,8 +174,9 @@ export class CsvConverter {
|
|
|
170
174
|
*/
|
|
171
175
|
async fromJsonAsync(jsonData, options = {}) {
|
|
172
176
|
const { conversionMode = 'no_encryption' } = options;
|
|
177
|
+
const optimizedConverterFn = dataManagerAsync(jsonToCsv, extractJsonFromString);
|
|
173
178
|
return this._convertWithEncryptionAsync(
|
|
174
|
-
async (data) =>
|
|
179
|
+
async (data) => optimizedConverterFn(data),
|
|
175
180
|
jsonData,
|
|
176
181
|
conversionMode
|
|
177
182
|
);
|
|
@@ -186,8 +191,9 @@ export class CsvConverter {
|
|
|
186
191
|
*/
|
|
187
192
|
toJson(csvString, options = {}) {
|
|
188
193
|
const { conversionMode = 'no_encryption' } = options;
|
|
194
|
+
const optimizedConverterFn = dataManager(csvToJsonSync, extractCsvFromString);
|
|
189
195
|
return this._convertWithEncryption(
|
|
190
|
-
(data) =>
|
|
196
|
+
(data) => optimizedConverterFn(data),
|
|
191
197
|
csvString,
|
|
192
198
|
conversionMode
|
|
193
199
|
);
|
|
@@ -202,8 +208,9 @@ export class CsvConverter {
|
|
|
202
208
|
*/
|
|
203
209
|
async toJsonAsync(csvString, options = {}) {
|
|
204
210
|
const { conversionMode = 'no_encryption' } = options;
|
|
211
|
+
const optimizedConverterFn = dataManagerAsync(csvToJson, extractCsvFromString);
|
|
205
212
|
return this._convertWithEncryptionAsync(
|
|
206
|
-
async (data) =>
|
|
213
|
+
async (data) => optimizedConverterFn(data),
|
|
207
214
|
csvString,
|
|
208
215
|
conversionMode
|
|
209
216
|
);
|
|
@@ -245,8 +252,9 @@ export class CsvConverter {
|
|
|
245
252
|
*/
|
|
246
253
|
toYaml(csvString, options = {}) {
|
|
247
254
|
const { conversionMode = 'no_encryption' } = options;
|
|
255
|
+
const optimizedConverterFn = dataManager(csvToYamlSync, extractCsvFromString);
|
|
248
256
|
return this._convertWithEncryption(
|
|
249
|
-
(data) =>
|
|
257
|
+
(data) => optimizedConverterFn(data),
|
|
250
258
|
csvString,
|
|
251
259
|
conversionMode
|
|
252
260
|
);
|
|
@@ -254,8 +262,9 @@ export class CsvConverter {
|
|
|
254
262
|
|
|
255
263
|
async toYamlAsync(csvString, options = {}) {
|
|
256
264
|
const { conversionMode = 'no_encryption' } = options;
|
|
265
|
+
const optimizedConverterFn = dataManagerAsync(csvToYaml, extractCsvFromString);
|
|
257
266
|
return this._convertWithEncryptionAsync(
|
|
258
|
-
async (data) =>
|
|
267
|
+
async (data) => optimizedConverterFn(data),
|
|
259
268
|
csvString,
|
|
260
269
|
conversionMode
|
|
261
270
|
);
|
|
@@ -272,8 +281,9 @@ export class CsvConverter {
|
|
|
272
281
|
*/
|
|
273
282
|
fromXml(xmlString, options = {}) {
|
|
274
283
|
const { conversionMode = 'no_encryption' } = options;
|
|
284
|
+
const optimizedConverterFn = dataManager(xmlToCsvSync, extractXmlFromString);
|
|
275
285
|
return this._convertWithEncryption(
|
|
276
|
-
(data) =>
|
|
286
|
+
(data) => optimizedConverterFn(data),
|
|
277
287
|
xmlString,
|
|
278
288
|
conversionMode
|
|
279
289
|
);
|
|
@@ -281,8 +291,9 @@ export class CsvConverter {
|
|
|
281
291
|
|
|
282
292
|
async fromXmlAsync(xmlString, options = {}) {
|
|
283
293
|
const { conversionMode = 'no_encryption' } = options;
|
|
294
|
+
const optimizedConverterFn = dataManagerAsync(xmlToCsv, extractXmlFromString);
|
|
284
295
|
return this._convertWithEncryptionAsync(
|
|
285
|
-
async (data) =>
|
|
296
|
+
async (data) => optimizedConverterFn(data),
|
|
286
297
|
xmlString,
|
|
287
298
|
conversionMode
|
|
288
299
|
);
|
|
@@ -297,8 +308,9 @@ export class CsvConverter {
|
|
|
297
308
|
*/
|
|
298
309
|
toXml(csvString, options = {}) {
|
|
299
310
|
const { conversionMode = 'no_encryption' } = options;
|
|
311
|
+
const optimizedConverterFn = dataManager(csvToXmlSync, extractCsvFromString);
|
|
300
312
|
return this._convertWithEncryption(
|
|
301
|
-
(data) =>
|
|
313
|
+
(data) => optimizedConverterFn(data),
|
|
302
314
|
csvString,
|
|
303
315
|
conversionMode
|
|
304
316
|
);
|
|
@@ -306,8 +318,9 @@ export class CsvConverter {
|
|
|
306
318
|
|
|
307
319
|
async toXmlAsync(csvString, options = {}) {
|
|
308
320
|
const { conversionMode = 'no_encryption' } = options;
|
|
321
|
+
const optimizedConverterFn = dataManagerAsync(csvToXml, extractCsvFromString);
|
|
309
322
|
return this._convertWithEncryptionAsync(
|
|
310
|
-
async (data) =>
|
|
323
|
+
async (data) => optimizedConverterFn(data),
|
|
311
324
|
csvString,
|
|
312
325
|
conversionMode
|
|
313
326
|
);
|
|
@@ -356,7 +369,8 @@ export class CsvConverter {
|
|
|
356
369
|
* @returns {string} TOON formatted string
|
|
357
370
|
*/
|
|
358
371
|
static toToon(csvString) {
|
|
359
|
-
|
|
372
|
+
const optimizedConverterFn = dataManager(csvToToonSync, extractCsvFromString);
|
|
373
|
+
return optimizedConverterFn(csvString);
|
|
360
374
|
}
|
|
361
375
|
|
|
362
376
|
/**
|
|
@@ -365,7 +379,8 @@ export class CsvConverter {
|
|
|
365
379
|
* @returns {Promise<string>} TOON formatted string
|
|
366
380
|
*/
|
|
367
381
|
static async toToonAsync(csvString) {
|
|
368
|
-
|
|
382
|
+
const optimizedConverterFn = dataManagerAsync(csvToToon, extractCsvFromString);
|
|
383
|
+
return optimizedConverterFn(csvString);
|
|
369
384
|
}
|
|
370
385
|
|
|
371
386
|
/**
|
|
@@ -374,7 +389,8 @@ export class CsvConverter {
|
|
|
374
389
|
* @returns {string} CSV formatted string
|
|
375
390
|
*/
|
|
376
391
|
static fromJson(jsonData) {
|
|
377
|
-
|
|
392
|
+
const optimizedConverterFn = dataManager(jsonToCsvSync, extractJsonFromString);
|
|
393
|
+
return optimizedConverterFn(jsonData);
|
|
378
394
|
}
|
|
379
395
|
|
|
380
396
|
/**
|
|
@@ -383,7 +399,8 @@ export class CsvConverter {
|
|
|
383
399
|
* @returns {Promise<string>} CSV formatted string
|
|
384
400
|
*/
|
|
385
401
|
static async fromJsonAsync(jsonData) {
|
|
386
|
-
|
|
402
|
+
const optimizedConverterFn = dataManagerAsync(jsonToCsv, extractJsonFromString);
|
|
403
|
+
return optimizedConverterFn(jsonData);
|
|
387
404
|
}
|
|
388
405
|
|
|
389
406
|
/**
|
|
@@ -392,7 +409,8 @@ export class CsvConverter {
|
|
|
392
409
|
* @returns {Array|string} JSON result
|
|
393
410
|
*/
|
|
394
411
|
static toJson(csvString) {
|
|
395
|
-
|
|
412
|
+
const optimizedConverterFn = dataManager(csvToJsonSync, extractCsvFromString);
|
|
413
|
+
return optimizedConverterFn(csvString);
|
|
396
414
|
}
|
|
397
415
|
|
|
398
416
|
/**
|
|
@@ -401,7 +419,8 @@ export class CsvConverter {
|
|
|
401
419
|
* @returns {Promise<Array|string>} JSON result
|
|
402
420
|
*/
|
|
403
421
|
static async toJsonAsync(csvString) {
|
|
404
|
-
|
|
422
|
+
const optimizedConverterFn = dataManagerAsync(csvToJson, extractCsvFromString);
|
|
423
|
+
return optimizedConverterFn(csvString);
|
|
405
424
|
}
|
|
406
425
|
|
|
407
426
|
/**
|
|
@@ -428,7 +447,8 @@ export class CsvConverter {
|
|
|
428
447
|
* @returns {string} YAML formatted string
|
|
429
448
|
*/
|
|
430
449
|
static toYaml(csvString) {
|
|
431
|
-
|
|
450
|
+
const optimizedConverterFn = dataManager(csvToYamlSync, extractCsvFromString);
|
|
451
|
+
return optimizedConverterFn(csvString);
|
|
432
452
|
}
|
|
433
453
|
|
|
434
454
|
/**
|
|
@@ -437,7 +457,8 @@ export class CsvConverter {
|
|
|
437
457
|
* @returns {Promise<string>} YAML formatted string
|
|
438
458
|
*/
|
|
439
459
|
static async toYamlAsync(csvString) {
|
|
440
|
-
|
|
460
|
+
const optimizedConverterFn = dataManagerAsync(csvToYaml, extractCsvFromString);
|
|
461
|
+
return optimizedConverterFn(csvString);
|
|
441
462
|
}
|
|
442
463
|
|
|
443
464
|
/**
|
|
@@ -446,7 +467,8 @@ export class CsvConverter {
|
|
|
446
467
|
* @returns {string} CSV formatted string
|
|
447
468
|
*/
|
|
448
469
|
static fromXml(xmlString) {
|
|
449
|
-
|
|
470
|
+
const optimizedConverterFn = dataManager(xmlToCsvSync, extractXmlFromString);
|
|
471
|
+
return optimizedConverterFn(xmlString);
|
|
450
472
|
}
|
|
451
473
|
|
|
452
474
|
/**
|
|
@@ -455,7 +477,8 @@ export class CsvConverter {
|
|
|
455
477
|
* @returns {Promise<string>} CSV formatted string
|
|
456
478
|
*/
|
|
457
479
|
static async fromXmlAsync(xmlString) {
|
|
458
|
-
|
|
480
|
+
const optimizedConverterFn = dataManagerAsync(xmlToCsv, extractXmlFromString);
|
|
481
|
+
return optimizedConverterFn(xmlString);
|
|
459
482
|
}
|
|
460
483
|
|
|
461
484
|
/**
|
|
@@ -464,7 +487,8 @@ export class CsvConverter {
|
|
|
464
487
|
* @returns {string} XML formatted string
|
|
465
488
|
*/
|
|
466
489
|
static toXml(csvString) {
|
|
467
|
-
|
|
490
|
+
const optimizedConverterFn = dataManager(csvToXmlSync, extractCsvFromString);
|
|
491
|
+
return optimizedConverterFn(csvString);
|
|
468
492
|
}
|
|
469
493
|
|
|
470
494
|
/**
|
|
@@ -473,7 +497,8 @@ export class CsvConverter {
|
|
|
473
497
|
* @returns {Promise<string>} XML formatted string
|
|
474
498
|
*/
|
|
475
499
|
static async toXmlAsync(csvString) {
|
|
476
|
-
|
|
500
|
+
const optimizedConverterFn = dataManagerAsync(csvToXml, extractCsvFromString);
|
|
501
|
+
return optimizedConverterFn(csvString);
|
|
477
502
|
}
|
|
478
503
|
|
|
479
504
|
/**
|
package/src/index.js
CHANGED
|
@@ -21,7 +21,9 @@ import {
|
|
|
21
21
|
formatValue,
|
|
22
22
|
extractJsonFromString,
|
|
23
23
|
extractXmlFromString,
|
|
24
|
-
extractCsvFromString
|
|
24
|
+
extractCsvFromString,
|
|
25
|
+
dataManager,
|
|
26
|
+
dataManagerAsync
|
|
25
27
|
} from './utils.js';
|
|
26
28
|
import { Encryptor } from './encryptor.js';
|
|
27
29
|
import { JsonConverter } from './json_formatter/index.js';
|
|
@@ -168,7 +170,8 @@ export class ToonConverter {
|
|
|
168
170
|
*/
|
|
169
171
|
fromJson(jsonData, options = {}) {
|
|
170
172
|
const { conversionMode = 'no_encryption' } = options;
|
|
171
|
-
|
|
173
|
+
const optimizedConverterFn = dataManager(jsonToToonSync, extractJsonFromString);
|
|
174
|
+
return this._convertWithEncryption(optimizedConverterFn, jsonData, conversionMode);
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
/**
|
|
@@ -180,7 +183,8 @@ export class ToonConverter {
|
|
|
180
183
|
*/
|
|
181
184
|
async fromJsonAsync(jsonData, options = {}) {
|
|
182
185
|
const { conversionMode = 'no_encryption' } = options;
|
|
183
|
-
|
|
186
|
+
const optimizedConverterFn = dataManagerAsync(jsonToToon, extractJsonFromString);
|
|
187
|
+
return this._convertWithEncryptionAsync(optimizedConverterFn, jsonData, conversionMode);
|
|
184
188
|
}
|
|
185
189
|
|
|
186
190
|
/**
|
|
@@ -274,7 +278,8 @@ export class ToonConverter {
|
|
|
274
278
|
*/
|
|
275
279
|
fromXml(xmlString, options = {}) {
|
|
276
280
|
const { conversionMode = 'no_encryption' } = options;
|
|
277
|
-
|
|
281
|
+
const optimizedConverterFn = dataManager(xmlToToonSync, extractXmlFromString);
|
|
282
|
+
return this._convertWithEncryption(optimizedConverterFn, xmlString, conversionMode);
|
|
278
283
|
}
|
|
279
284
|
|
|
280
285
|
/**
|
|
@@ -286,7 +291,8 @@ export class ToonConverter {
|
|
|
286
291
|
*/
|
|
287
292
|
async fromXmlAsync(xmlString, options = {}) {
|
|
288
293
|
const { conversionMode = 'no_encryption' } = options;
|
|
289
|
-
|
|
294
|
+
const optimizedConverterFn = dataManagerAsync(xmlToToon, extractXmlFromString);
|
|
295
|
+
return this._convertWithEncryptionAsync(optimizedConverterFn, xmlString, conversionMode);
|
|
290
296
|
}
|
|
291
297
|
|
|
292
298
|
/**
|
|
@@ -322,7 +328,8 @@ export class ToonConverter {
|
|
|
322
328
|
*/
|
|
323
329
|
fromCsv(csvString, options = {}) {
|
|
324
330
|
const { conversionMode = 'no_encryption' } = options;
|
|
325
|
-
|
|
331
|
+
const optimizedConverterFn = dataManager(csvToToonSync, extractCsvFromString);
|
|
332
|
+
return this._convertWithEncryption(optimizedConverterFn, csvString, conversionMode);
|
|
326
333
|
}
|
|
327
334
|
|
|
328
335
|
/**
|
|
@@ -334,7 +341,8 @@ export class ToonConverter {
|
|
|
334
341
|
*/
|
|
335
342
|
async fromCsvAsync(csvString, options = {}) {
|
|
336
343
|
const { conversionMode = 'no_encryption' } = options;
|
|
337
|
-
|
|
344
|
+
const optimizedConverterFn = dataManagerAsync(csvToToon, extractCsvFromString);
|
|
345
|
+
return this._convertWithEncryptionAsync(optimizedConverterFn, csvString, conversionMode);
|
|
338
346
|
}
|
|
339
347
|
|
|
340
348
|
/**
|
|
@@ -391,7 +399,8 @@ export class ToonConverter {
|
|
|
391
399
|
* @returns {string} TOON formatted string
|
|
392
400
|
*/
|
|
393
401
|
static fromJson(jsonData) {
|
|
394
|
-
|
|
402
|
+
const optimizedConverterFn = dataManager(jsonToToonSync, extractJsonFromString);
|
|
403
|
+
return optimizedConverterFn(jsonData);
|
|
395
404
|
}
|
|
396
405
|
|
|
397
406
|
/**
|
|
@@ -400,7 +409,8 @@ export class ToonConverter {
|
|
|
400
409
|
* @returns {Promise<string>} TOON formatted string
|
|
401
410
|
*/
|
|
402
411
|
static async fromJsonAsync(jsonData) {
|
|
403
|
-
|
|
412
|
+
const optimizedConverterFn = dataManagerAsync(jsonToToon, extractJsonFromString);
|
|
413
|
+
return optimizedConverterFn(jsonData);
|
|
404
414
|
}
|
|
405
415
|
|
|
406
416
|
/**
|
|
@@ -465,7 +475,8 @@ export class ToonConverter {
|
|
|
465
475
|
* @returns {string} TOON formatted string
|
|
466
476
|
*/
|
|
467
477
|
static fromXml(xmlString) {
|
|
468
|
-
|
|
478
|
+
const optimizedConverterFn = dataManager(xmlToToonSync, extractXmlFromString);
|
|
479
|
+
return optimizedConverterFn(xmlString);
|
|
469
480
|
}
|
|
470
481
|
|
|
471
482
|
/**
|
|
@@ -474,7 +485,8 @@ export class ToonConverter {
|
|
|
474
485
|
* @returns {Promise<string>} TOON formatted string
|
|
475
486
|
*/
|
|
476
487
|
static async fromXmlAsync(xmlString) {
|
|
477
|
-
|
|
488
|
+
const optimizedConverterFn = dataManagerAsync(xmlToToon, extractXmlFromString);
|
|
489
|
+
return optimizedConverterFn(xmlString);
|
|
478
490
|
}
|
|
479
491
|
|
|
480
492
|
/**
|
|
@@ -501,7 +513,8 @@ export class ToonConverter {
|
|
|
501
513
|
* @returns {Promise<string>} TOON formatted string
|
|
502
514
|
*/
|
|
503
515
|
static async fromCsvAsync(csvString) {
|
|
504
|
-
|
|
516
|
+
const optimizedConverterFn = dataManagerAsync(csvToToon, extractCsvFromString);
|
|
517
|
+
return optimizedConverterFn(csvString);
|
|
505
518
|
}
|
|
506
519
|
|
|
507
520
|
/**
|
|
@@ -510,7 +523,8 @@ export class ToonConverter {
|
|
|
510
523
|
* @returns {string} TOON formatted string
|
|
511
524
|
*/
|
|
512
525
|
static fromCsv(csvString) {
|
|
513
|
-
|
|
526
|
+
const optimizedConverterFn = dataManager(csvToToonSync, extractCsvFromString);
|
|
527
|
+
return optimizedConverterFn(csvString);
|
|
514
528
|
}
|
|
515
529
|
|
|
516
530
|
/**
|