fable 3.1.72 → 3.1.73
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/docs/README.md +30 -6
- package/docs/_brand.json +18 -0
- package/docs/_playground.json +10 -0
- package/docs/_sidebar.md +2 -0
- package/docs/_version.json +3 -3
- package/docs/architecture.md +201 -39
- package/docs/index.html +6 -7
- package/docs/pict-docuserve.min.js +91 -0
- package/docs/pict-docuserve.min.js.map +1 -0
- package/docs/playground.md +38 -0
- package/docs/retold-catalog.json +1 -1
- package/docs/retold-keyword-index.json +8721 -8105
- package/docs/services/README.md +26 -9
- package/docs/services/anticipate.md +104 -40
- package/docs/services/csv-parser.md +63 -35
- package/docs/services/data-format.md +154 -49
- package/docs/services/data-generation.md +77 -16
- package/docs/services/dates.md +103 -36
- package/docs/services/environment-data.md +13 -2
- package/docs/services/expression-parser.md +280 -68
- package/docs/services/file-persistence.md +142 -150
- package/docs/services/logging.md +93 -37
- package/docs/services/logic.md +70 -22
- package/docs/services/manifest.md +114 -26
- package/docs/services/math.md +168 -63
- package/docs/services/meta-template.md +312 -158
- package/docs/services/object-cache.md +94 -11
- package/docs/services/operation.md +68 -6
- package/docs/services/progress-time.md +74 -13
- package/docs/services/progress-tracker-set.md +101 -3
- package/docs/services/rest-client.md +136 -104
- package/docs/services/settings-manager.md +133 -40
- package/docs/services/template.md +71 -22
- package/docs/services/utility.md +121 -29
- package/docs/services/uuid.md +58 -10
- package/package.json +2 -2
- package/.claude/settings.local.json +0 -8
|
@@ -5,8 +5,11 @@ The DataFormat service provides string manipulation, number formatting, and data
|
|
|
5
5
|
## Access
|
|
6
6
|
|
|
7
7
|
```javascript
|
|
8
|
+
const libFable = require('fable');
|
|
9
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
10
|
+
|
|
8
11
|
// Auto-instantiated, available directly
|
|
9
|
-
fable.DataFormat
|
|
12
|
+
console.log('fable.DataFormat:', typeof fable.DataFormat);
|
|
10
13
|
```
|
|
11
14
|
|
|
12
15
|
## String Manipulation
|
|
@@ -14,42 +17,60 @@ fable.DataFormat
|
|
|
14
17
|
### Reverse String
|
|
15
18
|
|
|
16
19
|
```javascript
|
|
17
|
-
|
|
20
|
+
const libFable = require('fable');
|
|
21
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
22
|
+
|
|
23
|
+
console.log(fable.DataFormat.stringReverse('Hello')); // Returns 'olleH'
|
|
18
24
|
```
|
|
19
25
|
|
|
20
26
|
### String Starts/Ends With
|
|
21
27
|
|
|
22
28
|
```javascript
|
|
23
|
-
|
|
24
|
-
fable
|
|
29
|
+
const libFable = require('fable');
|
|
30
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
31
|
+
|
|
32
|
+
console.log(fable.DataFormat.stringStartsWith('Hello World', 'Hello')); // true
|
|
33
|
+
console.log(fable.DataFormat.stringEndsWith('Hello World', 'World')); // true
|
|
25
34
|
|
|
26
35
|
// With index
|
|
27
|
-
fable.DataFormat.stringStartsWith('Hello World', 'World', 6); // true
|
|
36
|
+
console.log(fable.DataFormat.stringStartsWith('Hello World', 'World', 6)); // true
|
|
28
37
|
```
|
|
29
38
|
|
|
30
39
|
### Capitalize Each Word
|
|
31
40
|
|
|
32
41
|
```javascript
|
|
33
|
-
|
|
42
|
+
const libFable = require('fable');
|
|
43
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
44
|
+
|
|
45
|
+
console.log(fable.DataFormat.capitalizeEachWord('hello world')); // Returns 'Hello World'
|
|
34
46
|
```
|
|
35
47
|
|
|
36
48
|
### Clean Non-Alpha Characters
|
|
37
49
|
|
|
38
50
|
```javascript
|
|
39
|
-
|
|
51
|
+
const libFable = require('fable');
|
|
52
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
53
|
+
|
|
54
|
+
console.log(fable.DataFormat.cleanNonAlphaCharacters('Hello123World!')); // Returns 'HelloWorld'
|
|
40
55
|
```
|
|
41
56
|
|
|
42
57
|
### Sanitize Object Key
|
|
43
58
|
|
|
44
59
|
```javascript
|
|
45
|
-
|
|
60
|
+
const libFable = require('fable');
|
|
61
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
62
|
+
|
|
63
|
+
console.log(fable.DataFormat.sanitizeObjectKey('my-key name!')); // Returns 'my_key_name_'
|
|
46
64
|
```
|
|
47
65
|
|
|
48
66
|
### Clean Enclosure Wrap Characters
|
|
49
67
|
|
|
50
68
|
```javascript
|
|
51
|
-
|
|
52
|
-
fable
|
|
69
|
+
const libFable = require('fable');
|
|
70
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
71
|
+
|
|
72
|
+
console.log(fable.DataFormat.cleanEnclosureWrapCharacters('"', '"hello"')); // Returns 'hello'
|
|
73
|
+
console.log(fable.DataFormat.cleanEnclosureWrapCharacters("'", "'world'")); // Returns 'world'
|
|
53
74
|
```
|
|
54
75
|
|
|
55
76
|
## String Concatenation
|
|
@@ -57,21 +78,30 @@ fable.DataFormat.cleanEnclosureWrapCharacters("'", "'world'"); // Returns 'worl
|
|
|
57
78
|
### Concatenate Strings
|
|
58
79
|
|
|
59
80
|
```javascript
|
|
60
|
-
|
|
81
|
+
const libFable = require('fable');
|
|
82
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
83
|
+
|
|
84
|
+
console.log(fable.DataFormat.concatenateStrings('Hello', ' ', 'World')); // Returns 'Hello World'
|
|
61
85
|
```
|
|
62
86
|
|
|
63
87
|
### Join Strings
|
|
64
88
|
|
|
65
89
|
```javascript
|
|
66
|
-
|
|
90
|
+
const libFable = require('fable');
|
|
91
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
92
|
+
|
|
93
|
+
console.log(fable.DataFormat.joinStrings(', ', 'Apple', 'Banana', 'Cherry'));
|
|
67
94
|
// Returns 'Apple, Banana, Cherry'
|
|
68
95
|
```
|
|
69
96
|
|
|
70
97
|
### Raw Concatenation (includes non-strings)
|
|
71
98
|
|
|
72
99
|
```javascript
|
|
73
|
-
|
|
74
|
-
fable
|
|
100
|
+
const libFable = require('fable');
|
|
101
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
102
|
+
|
|
103
|
+
console.log(fable.DataFormat.concatenateStringsRaw('Value: ', 42)); // Returns 'Value: 42'
|
|
104
|
+
console.log(fable.DataFormat.joinStringsRaw('-', 1, 2, 3)); // Returns '1-2-3'
|
|
75
105
|
```
|
|
76
106
|
|
|
77
107
|
## String Hashing
|
|
@@ -79,7 +109,10 @@ fable.DataFormat.joinStringsRaw('-', 1, 2, 3); // Returns '1-2-3'
|
|
|
79
109
|
Generate a simple (non-cryptographic) hash from a string:
|
|
80
110
|
|
|
81
111
|
```javascript
|
|
82
|
-
|
|
112
|
+
const libFable = require('fable');
|
|
113
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
114
|
+
|
|
115
|
+
console.log(fable.DataFormat.insecureStringHash('hello')); // Returns 'HSH99162322'
|
|
83
116
|
```
|
|
84
117
|
|
|
85
118
|
## Number Formatting
|
|
@@ -87,23 +120,32 @@ fable.DataFormat.insecureStringHash('hello'); // Returns 'HSH99162322'
|
|
|
87
120
|
### Add Commas to Numbers
|
|
88
121
|
|
|
89
122
|
```javascript
|
|
90
|
-
fable
|
|
123
|
+
const libFable = require('fable');
|
|
124
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
125
|
+
|
|
126
|
+
console.log(fable.DataFormat.formatterAddCommasToNumber(1234567.89));
|
|
91
127
|
// Returns '1,234,567.89'
|
|
92
128
|
```
|
|
93
129
|
|
|
94
130
|
### Format as Dollars
|
|
95
131
|
|
|
96
132
|
```javascript
|
|
97
|
-
|
|
98
|
-
fable
|
|
99
|
-
|
|
133
|
+
const libFable = require('fable');
|
|
134
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
135
|
+
|
|
136
|
+
console.log(fable.DataFormat.formatterDollars(1234.5)); // Returns '$1,234.50'
|
|
137
|
+
console.log(fable.DataFormat.formatterDollars(1234.567, 3)); // Returns '$1,234.567' (3 decimals)
|
|
138
|
+
console.log(fable.DataFormat.formatterDollars('invalid')); // Returns '--'
|
|
100
139
|
```
|
|
101
140
|
|
|
102
141
|
### Round Number
|
|
103
142
|
|
|
104
143
|
```javascript
|
|
105
|
-
|
|
106
|
-
fable
|
|
144
|
+
const libFable = require('fable');
|
|
145
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
146
|
+
|
|
147
|
+
console.log(fable.DataFormat.formatterRoundNumber(3.14159, 2)); // Returns '3.14'
|
|
148
|
+
console.log(fable.DataFormat.formatterRoundNumber(3.14159)); // Returns '3.14' (default 2 digits)
|
|
107
149
|
```
|
|
108
150
|
|
|
109
151
|
## String Padding
|
|
@@ -111,15 +153,21 @@ fable.DataFormat.formatterRoundNumber(3.14159); // Returns '3.14' (default 2
|
|
|
111
153
|
### Pad Start
|
|
112
154
|
|
|
113
155
|
```javascript
|
|
114
|
-
|
|
115
|
-
fable
|
|
156
|
+
const libFable = require('fable');
|
|
157
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
158
|
+
|
|
159
|
+
console.log(fable.DataFormat.stringPadStart('5', 3, '0')); // Returns '005'
|
|
160
|
+
console.log(fable.DataFormat.stringPadStart('42', 5, ' ')); // Returns ' 42'
|
|
116
161
|
```
|
|
117
162
|
|
|
118
163
|
### Pad End
|
|
119
164
|
|
|
120
165
|
```javascript
|
|
121
|
-
|
|
122
|
-
fable
|
|
166
|
+
const libFable = require('fable');
|
|
167
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
168
|
+
|
|
169
|
+
console.log(fable.DataFormat.stringPadEnd('5', 3, '0')); // Returns '500'
|
|
170
|
+
console.log(fable.DataFormat.stringPadEnd('Hi', 5, '.')); // Returns 'Hi...'
|
|
123
171
|
```
|
|
124
172
|
|
|
125
173
|
## Time Formatting
|
|
@@ -129,7 +177,10 @@ fable.DataFormat.stringPadEnd('Hi', 5, '.'); // Returns 'Hi...'
|
|
|
129
177
|
Format milliseconds as HH:MM:SS.mmm:
|
|
130
178
|
|
|
131
179
|
```javascript
|
|
132
|
-
|
|
180
|
+
const libFable = require('fable');
|
|
181
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
182
|
+
|
|
183
|
+
console.log(fable.DataFormat.formatTimeSpan(3661234)); // Returns '01:01:01.234'
|
|
133
184
|
```
|
|
134
185
|
|
|
135
186
|
### Format Time Delta
|
|
@@ -137,7 +188,12 @@ fable.DataFormat.formatTimeSpan(3661234); // Returns '01:01:01.234'
|
|
|
137
188
|
Format the difference between two timestamps:
|
|
138
189
|
|
|
139
190
|
```javascript
|
|
140
|
-
|
|
191
|
+
const libFable = require('fable');
|
|
192
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
193
|
+
|
|
194
|
+
const startTime = Date.now() - 3600000;
|
|
195
|
+
const endTime = Date.now();
|
|
196
|
+
console.log(fable.DataFormat.formatTimeDelta(startTime, endTime)); // Returns 'HH:MM:SS.mmm'
|
|
141
197
|
```
|
|
142
198
|
|
|
143
199
|
## Date Formatting
|
|
@@ -145,38 +201,50 @@ fable.DataFormat.formatTimeDelta(startTime, endTime); // Returns 'HH:MM:SS.mmm'
|
|
|
145
201
|
### Get Month Name
|
|
146
202
|
|
|
147
203
|
```javascript
|
|
148
|
-
|
|
204
|
+
const libFable = require('fable');
|
|
205
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
206
|
+
|
|
207
|
+
console.log(fable.DataFormat.getMonthFromDate(new Date('2024-06-15')));
|
|
149
208
|
// Returns 'June'
|
|
150
209
|
|
|
151
|
-
fable.DataFormat.getMonthAbbreviatedFromDate(new Date('2024-06-15'));
|
|
210
|
+
console.log(fable.DataFormat.getMonthAbbreviatedFromDate(new Date('2024-06-15')));
|
|
152
211
|
// Returns 'Jun'
|
|
153
212
|
```
|
|
154
213
|
|
|
155
214
|
### Format Month/Day/Year
|
|
156
215
|
|
|
157
216
|
```javascript
|
|
158
|
-
|
|
217
|
+
const libFable = require('fable');
|
|
218
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
219
|
+
|
|
220
|
+
console.log(fable.DataFormat.formatMonthDayYearFromDate(new Date('2024-06-15')));
|
|
159
221
|
// Returns '6/15/2024'
|
|
160
222
|
|
|
161
223
|
// Strict mode (zero-padded)
|
|
162
|
-
fable.DataFormat.formatMonthDayYearFromDate(new Date('2024-06-05'), true);
|
|
224
|
+
console.log(fable.DataFormat.formatMonthDayYearFromDate(new Date('2024-06-05'), true));
|
|
163
225
|
// Returns '06/05/2024'
|
|
164
226
|
```
|
|
165
227
|
|
|
166
228
|
### Sortable Date String
|
|
167
229
|
|
|
168
230
|
```javascript
|
|
169
|
-
|
|
231
|
+
const libFable = require('fable');
|
|
232
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
233
|
+
|
|
234
|
+
console.log(fable.DataFormat.formatSortableStringFromDate(new Date('2024-06-15')));
|
|
170
235
|
// Returns '20240515'
|
|
171
236
|
```
|
|
172
237
|
|
|
173
238
|
## HTML Entity Resolution
|
|
174
239
|
|
|
175
240
|
```javascript
|
|
176
|
-
|
|
241
|
+
const libFable = require('fable');
|
|
242
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
243
|
+
|
|
244
|
+
console.log(fable.DataFormat.resolveHtmlEntities('& < >'));
|
|
177
245
|
// Returns '& < >'
|
|
178
246
|
|
|
179
|
-
fable.DataFormat.resolveHtmlEntities('A'); // Returns 'A'
|
|
247
|
+
console.log(fable.DataFormat.resolveHtmlEntities('A')); // Returns 'A'
|
|
180
248
|
```
|
|
181
249
|
|
|
182
250
|
## String Tokenization
|
|
@@ -184,8 +252,11 @@ fable.DataFormat.resolveHtmlEntities('A'); // Returns 'A'
|
|
|
184
252
|
### Before/After Match
|
|
185
253
|
|
|
186
254
|
```javascript
|
|
187
|
-
|
|
188
|
-
fable
|
|
255
|
+
const libFable = require('fable');
|
|
256
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
257
|
+
|
|
258
|
+
console.log(fable.DataFormat.stringBeforeMatch('hello-world', '-')); // Returns 'hello'
|
|
259
|
+
console.log(fable.DataFormat.stringAfterMatch('hello-world', '-')); // Returns 'world'
|
|
189
260
|
```
|
|
190
261
|
|
|
191
262
|
### Count Segments
|
|
@@ -193,17 +264,23 @@ fable.DataFormat.stringAfterMatch('hello-world', '-'); // Returns 'world'
|
|
|
193
264
|
Count segments respecting enclosures:
|
|
194
265
|
|
|
195
266
|
```javascript
|
|
196
|
-
|
|
197
|
-
fable
|
|
267
|
+
const libFable = require('fable');
|
|
268
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
269
|
+
|
|
270
|
+
console.log(fable.DataFormat.stringCountSegments('a.b.c', '.')); // Returns 3
|
|
271
|
+
console.log(fable.DataFormat.stringCountSegments('a.{b.c}.d', '.')); // Returns 3 (respects {})
|
|
198
272
|
```
|
|
199
273
|
|
|
200
274
|
### Get Segments
|
|
201
275
|
|
|
202
276
|
```javascript
|
|
203
|
-
|
|
277
|
+
const libFable = require('fable');
|
|
278
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
279
|
+
|
|
280
|
+
console.log(fable.DataFormat.stringGetSegments('a.b.c', '.'));
|
|
204
281
|
// Returns ['a', 'b', 'c']
|
|
205
282
|
|
|
206
|
-
fable.DataFormat.stringGetFirstSegment('a.b.c', '.');
|
|
283
|
+
console.log(fable.DataFormat.stringGetFirstSegment('a.b.c', '.'));
|
|
207
284
|
// Returns 'a'
|
|
208
285
|
```
|
|
209
286
|
|
|
@@ -212,24 +289,33 @@ fable.DataFormat.stringGetFirstSegment('a.b.c', '.');
|
|
|
212
289
|
### Count Enclosures
|
|
213
290
|
|
|
214
291
|
```javascript
|
|
215
|
-
|
|
216
|
-
fable
|
|
292
|
+
const libFable = require('fable');
|
|
293
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
294
|
+
|
|
295
|
+
console.log(fable.DataFormat.stringCountEnclosures('(a) and (b)')); // Returns 2
|
|
296
|
+
console.log(fable.DataFormat.stringCountEnclosures('((nested))')); // Returns 1 (outer only)
|
|
217
297
|
```
|
|
218
298
|
|
|
219
299
|
### Get Enclosure Value
|
|
220
300
|
|
|
221
301
|
```javascript
|
|
222
|
-
|
|
302
|
+
const libFable = require('fable');
|
|
303
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
304
|
+
|
|
305
|
+
console.log(fable.DataFormat.stringGetEnclosureValueByIndex('(first) and (second)', 0));
|
|
223
306
|
// Returns 'first'
|
|
224
307
|
|
|
225
|
-
fable.DataFormat.stringGetEnclosureValueByIndex('(first) and (second)', 1);
|
|
308
|
+
console.log(fable.DataFormat.stringGetEnclosureValueByIndex('(first) and (second)', 1));
|
|
226
309
|
// Returns 'second'
|
|
227
310
|
```
|
|
228
311
|
|
|
229
312
|
### Remove Enclosure
|
|
230
313
|
|
|
231
314
|
```javascript
|
|
232
|
-
|
|
315
|
+
const libFable = require('fable');
|
|
316
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
317
|
+
|
|
318
|
+
console.log(fable.DataFormat.stringRemoveEnclosureByIndex('(remove) keep (this)', 0));
|
|
233
319
|
// Returns ' keep (this)'
|
|
234
320
|
```
|
|
235
321
|
|
|
@@ -238,14 +324,20 @@ fable.DataFormat.stringRemoveEnclosureByIndex('(remove) keep (this)', 0);
|
|
|
238
324
|
### Encode URI Component
|
|
239
325
|
|
|
240
326
|
```javascript
|
|
241
|
-
|
|
327
|
+
const libFable = require('fable');
|
|
328
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
329
|
+
|
|
330
|
+
console.log(fable.DataFormat.stringEncodeURIComponent('hello world'));
|
|
242
331
|
// Returns 'hello%20world'
|
|
243
332
|
```
|
|
244
333
|
|
|
245
334
|
### Decode URI Component
|
|
246
335
|
|
|
247
336
|
```javascript
|
|
248
|
-
|
|
337
|
+
const libFable = require('fable');
|
|
338
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
339
|
+
|
|
340
|
+
console.log(fable.DataFormat.stringDecodeURIComponent('hello%20world'));
|
|
249
341
|
// Returns 'hello world'
|
|
250
342
|
```
|
|
251
343
|
|
|
@@ -254,10 +346,13 @@ fable.DataFormat.stringDecodeURIComponent('hello%20world');
|
|
|
254
346
|
Encode/decode strings for safe embedding in JavaScript:
|
|
255
347
|
|
|
256
348
|
```javascript
|
|
257
|
-
|
|
349
|
+
const libFable = require('fable');
|
|
350
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
351
|
+
|
|
352
|
+
console.log(fable.DataFormat.stringEncodeForJavascript('Hello "World"'));
|
|
258
353
|
// Returns 'Hello \\"World\\"'
|
|
259
354
|
|
|
260
|
-
fable.DataFormat.stringDecodeForJavascript('Hello \\"World\\"');
|
|
355
|
+
console.log(fable.DataFormat.stringDecodeForJavascript('Hello \\"World\\"'));
|
|
261
356
|
// Returns 'Hello "World"'
|
|
262
357
|
```
|
|
263
358
|
|
|
@@ -266,6 +361,9 @@ fable.DataFormat.stringDecodeForJavascript('Hello \\"World\\"');
|
|
|
266
361
|
The service uses configurable values:
|
|
267
362
|
|
|
268
363
|
```javascript
|
|
364
|
+
const libFable = require('fable');
|
|
365
|
+
const fable = new libFable({ Product: 'DataFormatDemo', ProductVersion: '1.0.0' });
|
|
366
|
+
|
|
269
367
|
// Currency symbol (default: '$')
|
|
270
368
|
fable.DataFormat._Value_MoneySign_Currency = '€';
|
|
271
369
|
|
|
@@ -274,4 +372,11 @@ fable.DataFormat._Value_NaN_Currency = 'N/A';
|
|
|
274
372
|
|
|
275
373
|
// Group separator for numbers (default: ',')
|
|
276
374
|
fable.DataFormat._Value_GroupSeparator_Number = '.';
|
|
375
|
+
|
|
376
|
+
console.log('Configured DataFormat:', {
|
|
377
|
+
money: fable.DataFormat._Value_MoneySign_Currency,
|
|
378
|
+
nanCur: fable.DataFormat._Value_NaN_Currency,
|
|
379
|
+
grpSep: fable.DataFormat._Value_GroupSeparator_Number
|
|
380
|
+
});
|
|
381
|
+
console.log(fable.DataFormat.formatterDollars(1234.5));
|
|
277
382
|
```
|
|
@@ -5,8 +5,12 @@ The DataGeneration service provides utilities for generating random data, useful
|
|
|
5
5
|
## Access
|
|
6
6
|
|
|
7
7
|
```javascript
|
|
8
|
+
const libFable = require('fable');
|
|
9
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
10
|
+
|
|
8
11
|
// On-demand service - instantiate when needed
|
|
9
12
|
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
13
|
+
console.log('dataGen:', typeof dataGen);
|
|
10
14
|
```
|
|
11
15
|
|
|
12
16
|
## Random Integers
|
|
@@ -14,19 +18,31 @@ const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
|
14
18
|
### Random Integer (Default Range)
|
|
15
19
|
|
|
16
20
|
```javascript
|
|
17
|
-
|
|
21
|
+
const libFable = require('fable');
|
|
22
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
23
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
24
|
+
|
|
25
|
+
console.log(dataGen.randomInteger()); // Random integer from 0 to default maximum
|
|
18
26
|
```
|
|
19
27
|
|
|
20
28
|
### Random Integer Up To
|
|
21
29
|
|
|
22
30
|
```javascript
|
|
23
|
-
|
|
31
|
+
const libFable = require('fable');
|
|
32
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
33
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
34
|
+
|
|
35
|
+
console.log(dataGen.randomIntegerUpTo(100)); // Random integer from 0 (inclusive) to 100 (exclusive)
|
|
24
36
|
```
|
|
25
37
|
|
|
26
38
|
### Random Integer Between
|
|
27
39
|
|
|
28
40
|
```javascript
|
|
29
|
-
|
|
41
|
+
const libFable = require('fable');
|
|
42
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
43
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
44
|
+
|
|
45
|
+
console.log(dataGen.randomIntegerBetween(10, 50)); // Random integer from 10 (inclusive) to 50 (exclusive)
|
|
30
46
|
```
|
|
31
47
|
|
|
32
48
|
## Random Floats
|
|
@@ -34,13 +50,21 @@ dataGen.randomIntegerBetween(10, 50); // Random integer from 10 (inclusive) to
|
|
|
34
50
|
### Random Float (0 to 1)
|
|
35
51
|
|
|
36
52
|
```javascript
|
|
37
|
-
|
|
53
|
+
const libFable = require('fable');
|
|
54
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
55
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
56
|
+
|
|
57
|
+
console.log(dataGen.randomFloat()); // Random float between 0 and 1 (same as Math.random())
|
|
38
58
|
```
|
|
39
59
|
|
|
40
60
|
### Random Float Up To
|
|
41
61
|
|
|
42
62
|
```javascript
|
|
43
|
-
|
|
63
|
+
const libFable = require('fable');
|
|
64
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
65
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
66
|
+
|
|
67
|
+
console.log(dataGen.randomFloatUpTo(7.65)); // Random float from 0 to 7.65
|
|
44
68
|
```
|
|
45
69
|
|
|
46
70
|
### Random Float Between
|
|
@@ -48,8 +72,12 @@ dataGen.randomFloatUpTo(7.65); // Random float from 0 to 7.65
|
|
|
48
72
|
Uses arbitrary precision math under the hood:
|
|
49
73
|
|
|
50
74
|
```javascript
|
|
51
|
-
|
|
52
|
-
|
|
75
|
+
const libFable = require('fable');
|
|
76
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
77
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
78
|
+
|
|
79
|
+
console.log(dataGen.randomFloatBetween(4.3, 5.1)); // Random float between 4.3 and 5.1
|
|
80
|
+
console.log(dataGen.randomFloatBetween(0, 100)); // Random float between 0 and 100
|
|
53
81
|
```
|
|
54
82
|
|
|
55
83
|
## Random Strings
|
|
@@ -59,8 +87,12 @@ dataGen.randomFloatBetween(0, 100); // Random float between 0 and 100
|
|
|
59
87
|
Generate a zero-padded random numeric string:
|
|
60
88
|
|
|
61
89
|
```javascript
|
|
62
|
-
|
|
63
|
-
|
|
90
|
+
const libFable = require('fable');
|
|
91
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
92
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
93
|
+
|
|
94
|
+
console.log(dataGen.randomNumericString()); // e.g., '0382917456' (default length 10, max 9999999999)
|
|
95
|
+
console.log(dataGen.randomNumericString(6, 999999)); // e.g., '042871' (length 6, max 999999)
|
|
64
96
|
```
|
|
65
97
|
|
|
66
98
|
## Random Selections from Default Data Sets
|
|
@@ -70,31 +102,51 @@ The service includes built-in data sets for generating human-readable random val
|
|
|
70
102
|
### Random Name (First Name)
|
|
71
103
|
|
|
72
104
|
```javascript
|
|
73
|
-
|
|
105
|
+
const libFable = require('fable');
|
|
106
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
107
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
108
|
+
|
|
109
|
+
console.log(dataGen.randomName()); // e.g., 'John'
|
|
74
110
|
```
|
|
75
111
|
|
|
76
112
|
### Random Surname
|
|
77
113
|
|
|
78
114
|
```javascript
|
|
79
|
-
|
|
115
|
+
const libFable = require('fable');
|
|
116
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
117
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
118
|
+
|
|
119
|
+
console.log(dataGen.randomSurname()); // e.g., 'Smith'
|
|
80
120
|
```
|
|
81
121
|
|
|
82
122
|
### Random Month
|
|
83
123
|
|
|
84
124
|
```javascript
|
|
85
|
-
|
|
125
|
+
const libFable = require('fable');
|
|
126
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
127
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
128
|
+
|
|
129
|
+
console.log(dataGen.randomMonth()); // e.g., 'January'
|
|
86
130
|
```
|
|
87
131
|
|
|
88
132
|
### Random Day of Week
|
|
89
133
|
|
|
90
134
|
```javascript
|
|
91
|
-
|
|
135
|
+
const libFable = require('fable');
|
|
136
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
137
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
138
|
+
|
|
139
|
+
console.log(dataGen.randomDayOfWeek()); // e.g., 'Wednesday'
|
|
92
140
|
```
|
|
93
141
|
|
|
94
142
|
### Random Color
|
|
95
143
|
|
|
96
144
|
```javascript
|
|
97
|
-
|
|
145
|
+
const libFable = require('fable');
|
|
146
|
+
const fable = new libFable({ Product: 'DataGenDemo', ProductVersion: '1.0.0' });
|
|
147
|
+
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
148
|
+
|
|
149
|
+
console.log(dataGen.randomColor()); // e.g., 'Blue'
|
|
98
150
|
```
|
|
99
151
|
|
|
100
152
|
## Use Cases
|
|
@@ -102,8 +154,10 @@ dataGen.randomColor(); // e.g., 'Blue'
|
|
|
102
154
|
### Test Data Generation
|
|
103
155
|
|
|
104
156
|
```javascript
|
|
157
|
+
const libFable = require('fable');
|
|
158
|
+
|
|
105
159
|
function generateTestUsers(count) {
|
|
106
|
-
const fable = new
|
|
160
|
+
const fable = new libFable({ Product: 'TestUserGen', ProductVersion: '1.0.0' });
|
|
107
161
|
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
108
162
|
const users = [];
|
|
109
163
|
|
|
@@ -118,14 +172,21 @@ function generateTestUsers(count) {
|
|
|
118
172
|
|
|
119
173
|
return users;
|
|
120
174
|
}
|
|
175
|
+
|
|
176
|
+
console.log(generateTestUsers(3));
|
|
121
177
|
```
|
|
122
178
|
|
|
123
179
|
### Database Seeding
|
|
124
180
|
|
|
125
181
|
```javascript
|
|
182
|
+
const libFable = require('fable');
|
|
183
|
+
const fable = new libFable({ Product: 'SeedDemo', ProductVersion: '1.0.0' });
|
|
126
184
|
const dataGen = fable.instantiateServiceProvider('DataGeneration');
|
|
127
185
|
|
|
128
|
-
|
|
186
|
+
// Stub db so the playground demo runs without a real database.
|
|
187
|
+
const db = { products: { create: async (row) => { console.log('insert:', row); return row; } } };
|
|
188
|
+
|
|
189
|
+
for (let i = 0; i < 3; i++) { // 3 rows for the demo (real code might do 50)
|
|
129
190
|
await db.products.create({
|
|
130
191
|
name: `Product ${dataGen.randomNumericString(6, 999999)}`,
|
|
131
192
|
price: dataGen.randomFloatBetween(9.99, 999.99),
|