dt-toolbox 7.4.9 → 7.5.1

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/README_v.2.x.x.md DELETED
@@ -1,540 +0,0 @@
1
- # DT Toolbox
2
-
3
-
4
-
5
- Data manipulation tool:
6
- - Converts object to flatten version(DT) and reverse(ST);
7
- - Modify DT objects: add/update/overwrite;
8
- - Compare DT objects: identical/change/same/different/missing;
9
- - Select data in DT objects: find/folder/parent;
10
- - Accumulative filter selection: limit/keep/remove/deep;
11
- - Extract and manipulate data chunks;
12
- - Converts objects in key-value string;
13
- - Replacement for underscore/lodash libraries;
14
-
15
- Deliberately designed to work nicely with JSON and simplify data creation, searching and extracting data processes. **Works in node projects and browsers**.
16
-
17
-
18
-
19
-
20
-
21
- ## What is DT?
22
-
23
- DT model is a flatten version of the standard javascript object. **Keys** are structured like folders - `'root/sub_object/property'`. **Values** are always primitives. In this documentation are mentioned two models - ST(standard) and DT(data). ST means non-flatten version of the object. Convertion between ST and DT is possible in both direction with one important note: If ST object contains empty structure like `key: []` (*key with empty array value*), then this structure will be lost. **Purpose of DT is to strip all boilerplate structure and keep only that is value related**.
24
-
25
-
26
-
27
-
28
-
29
- ## Installation
30
-
31
- Install for node.js projects by writing in your terminal:
32
- ```
33
- npm install dt-toolbox --save
34
- ```
35
-
36
- Once it has been installed, it can be used by writing this line of JavaScript:
37
- ```js
38
- let dtbox = require ( 'dt-toolbox')
39
- ```
40
-
41
- **Installation for browsers**: Grab file 'dist/dt-toolbox.min.js' and put it inside the project. Request the file from HTML page. Global variable 'dtbox' is available for use.
42
-
43
-
44
-
45
- ## APIs Reference
46
- Dtbox contains two different APIs. First is related to the library itself:
47
-
48
- ```js
49
- API = {
50
- // * DT I/O Operations
51
- init : 'Start chain with data or empty'
52
- , load : 'Load DT object or value'
53
- , preprocess : 'Convert ST to DT object. Change income data before add, update, overwrite'
54
- , add : 'Add data and keep existing data'
55
- , update : 'Updates only existing data'
56
- , overwrite : 'Add new data to DT object. Overwrite existing fields'
57
- , insert : 'Insert data on specified key, when the key represents an array'
58
- , spread : 'Export DT object'
59
- , spreadAll : 'Shortcut for chain: .select().all().spread()'
60
- , log : 'Executes callback with errors list as argument'
61
- , empty : 'Returns empty DT object'
62
-
63
- // Compare Operations
64
- , identical : 'Value compare. Reduce data to identical key/value pairs'
65
- , change : 'Value compare. Reduce to key/value pairs with different values'
66
- , same : 'Key compare. Returns key/value pairs where keys are the same'
67
- , different : 'Key compare. Reduce data to key/value pairs that differ'
68
- , missing : 'Key compare. Gets from DT key/value pairs that are missing'
69
-
70
- // * Selectors and Filters
71
- , select : 'Init new selection'
72
- , parent : 'Selector. Apply conditions starting from parent level'
73
- , folder : 'Selector. Fullfil select with list of arguments that have specific string'
74
- , all : 'Selector. Same as folder'
75
- , space : 'Selector. Fullfil select with namespace members'
76
- , deepArray : 'Selector. Fullfil '_select' with deepest array elements'
77
- , deepObject : 'Selector. Fullfil '_select' with deepest object elements'
78
- , invert : 'Selector. Invert existing selection'
79
- , limit : 'Filter. Reduces amount of records in the selection'
80
- , keep : 'Filter. Keeps records in selection if check function returns true'
81
- , remove : 'Filter. Removes records from selection if check function returns true'
82
- , deep : 'Filter. Arguments ( num, direction - optional). Num mean level of deep. Deep '0' mean root members'
83
- }
84
-
85
- ```
86
-
87
- Second set of functions are available for DT object in a callback of 'spread' and 'preprocess' functions. More details can be found later in the example section.
88
-
89
- ```js
90
- exportAPI = {
91
- // * Structure Manipulation
92
- assemble : 'Remove all duplications in the keys and shrinks th possible'
93
- , ignoreKeys : 'Converts object with nosense keys in array'
94
- , cut : 'Cut out number of key elements'
95
- , keyList : 'Returns array of DT object keys'
96
- , valueList : 'Returns array of DT object values'
97
- , list : 'Returns array of items'
98
- , map : 'Standard map function'
99
- , json : 'Return JSON model of DT object'
100
- , file : 'Returns file model array'
101
- , keyValue : 'Returns key-value string'
102
- , build : 'Build ST object'
103
-
104
- // * Data Manipulation
105
- , modifyKeys : 'Add modified keys back to DT object'
106
- , keepKeys : 'Apply test on array of keys. Keep met the criteria'
107
- , removeKeys : 'Apply test on array of keys. Remove met the criteria'
108
- , keepValues : 'Apply test on values. Keep met the criteria'
109
- , removeValues : 'Apply test on values. Remove met the criteria'
110
- }
111
- ```
112
-
113
-
114
-
115
- # How it works?
116
-
117
- 1. First: Create data inside DT toolbox. Load already existing DT or init with some ST object. Mix if you need with other objects by using 'add/update/overwrite'. Use 'preprocess' to adapt data package before assimilate it.
118
-
119
- 2. Select! Without selection, DT Toolbox will always return empty object. Selectors will search in dt.value and result will be accumulated. Filters will be applied to already selected data.
120
-
121
- 3. Spread the data.
122
-
123
- DT Toolbox supports chaining syntax and is that simple. Let's see some examples...
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
- ## Examples
135
-
136
- ### Basics
137
- Let's have a ST object:
138
-
139
- ```js
140
- let st = {
141
- name : {
142
- firstName : 'Peter'
143
- , surname : 'Naydenov'
144
- }
145
- , friends : [ 'Tisho', 'Dibo', 'Ivo', 'Vasil' ]
146
- }
147
-
148
- ```
149
- Same object in DT will look like:
150
-
151
- ```js
152
- {
153
- 'root/name/firstName' : 'Peter'
154
- , 'root/name/surname' : 'Naydenov'
155
- , 'root/friends/0' : 'Tisho'
156
- , 'root/friends/1' : 'Dibo'
157
- , 'root/friends/2' : 'Ivo'
158
- , 'root/friends/3' : 'Vasil'
159
- }
160
- ```
161
-
162
- Convert any standard javascript object to DT using dt-toolbox:
163
-
164
- ```js
165
- let dt = dtbox.init ( standard ).value
166
- ```
167
-
168
-
169
-
170
-
171
-
172
- Let's play with DT Toolbox:
173
-
174
- ```js
175
- let
176
- dtResult
177
- , stResult
178
- , friendList
179
- ;
180
-
181
- dtbox
182
- .init(st) // Init data. Converts ST to DT
183
- .select() // Starting new selection
184
- .all() // Select all data
185
- .spread ( 'dt', dt => dtResult = dt ) // returns DT object
186
- .spread ( 'dt', dt => stResult == dt.build() ) // convert back to ST
187
- .select () // Start new selection. Will remove previous selection.
188
- .folder('friends') // select keys that contain 'friends'
189
- .spread ( 'dt', dt => friendList = dt.build() ) //= { friends :[ 'Tisho', 'Dibo', 'Ivo', 'Vasil' ] }
190
- .spread ( 'dt', dt => friendList = dt.assemble().build() ) // = [ 'Tisho', 'Dibo', 'Ivo', 'Vasil' ]
191
- // 'assemble' removes all duplicated elements in the keys and simplifies the result.
192
-
193
- ```
194
-
195
- ### Convert ST to DT objects
196
-
197
- ```js
198
- let dt = dtbox.init(st).value;
199
-
200
- ```
201
-
202
- ### Mixing objects - Add/Update/Overwrite
203
-
204
- Add and update will consider existing data:
205
- - 'Add' method will be applied only for non-existing properties;
206
- - 'Update' method will works only on existing properties;
207
-
208
- Overwrite will 'add' and 'update'.
209
-
210
- ```js
211
-
212
- let user = {
213
- name : 'Peter'
214
- , age : 42
215
- }
216
-
217
- dtbox
218
- .init ( user )
219
- .add ({
220
- age : 25 // 'add' will ignore this. Age is already defined.
221
- , gender : 'male' // Will add this.
222
- })
223
- .update ({
224
- age : 50 // Will update
225
- eyes : 'blue' // Will ignore this.
226
- })
227
- .overwrite ({
228
- age : 43 // Will update
229
- , hobby : 'skating' // Will add
230
- })
231
-
232
- // DT object (dtbox.value) will look like:
233
- /*
234
- {
235
- 'root/name' : 'Peter'
236
- , 'root/age' : 43
237
- , 'root/gender' : 'male'
238
- , 'root/hobby' : 'skating'
239
- }
240
-
241
- /*
242
-
243
- ```
244
-
245
-
246
- ### Parent
247
-
248
- ```js
249
-
250
- let result;
251
- let data = {
252
- 'school' : [
253
- { name: 'Ivan', age: 14 }
254
- , { name: 'Georgy', age: 15 }
255
- , { name: 'Adi', age: 11 }
256
- , { name: 'Kati', age: 11 }
257
- ]
258
- , 'sports' : [
259
- { name: 'Iva', age: 28 }
260
- , { name: 'Stoyan', age: 36 }
261
- ]
262
- , 'work' : [
263
- { name: 'Hristo', age: 38 }
264
- , { name: 'Lachezar', age: 33 }
265
- , { name: 'Veselina', age: 35 }
266
-
267
- ]
268
- , 'recent' : {
269
- 'classmates' : [
270
- { name: 'Anton', age: 42 }
271
- , { name: 'Miroslava', age: 42 }
272
- ]
273
- , 'social' : [
274
- { name: 'Iliana', age: 61 }
275
- , { name: 'Tzvetan', age: 19 }
276
- ]
277
- }
278
- }
279
-
280
- // Let's create list of all contacts uder 40 years old:
281
-
282
- dtbox
283
- .init ( data )
284
- .select ()
285
- .parent ( 'name', person => person.age < 40 )
286
- .spread ( 'dt' , dt => result = dt.assemble().ignoreKeys().build() )
287
-
288
- /*
289
- result will look like this:
290
-
291
- [
292
- { name: 'Tzvetan', age: 19 },
293
- { name: 'Ivan', age: 14 },
294
- { name: 'Iva', age: 28 },
295
- { name: 'Hristo', age: 38 },
296
- { name: 'Georgy', age: 15 },
297
- { name: 'Stoyan', age: 36 },
298
- { name: 'Lachezar', age: 33 },
299
- { name: 'Adi', age: 11 },
300
- { name: 'Veselina', age: 35 },
301
- { name: 'Kati', age: 11 }
302
- ]
303
-
304
- */
305
- ```
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
314
- ## More
315
- Find more examples in `./test` folder. Almost 90 unit tests are on your disposal. Find what is possible start experimenting with the library.
316
-
317
- Let me know what you think by using twitter tag #dttoolbox.
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
-
326
-
327
-
328
- ## Tips
329
-
330
- - DT model not depends on DT Toolbox. Use toolbox when language cannot provide better tools;
331
- - Iteration on data with DT Toolbox could bring performance issues(anti-pattern). Iterate over data first and then use DT Toolbox;
332
- - Working with flat objects (DT) could be relieving experience with extras - performance and readability gain;
333
-
334
-
335
-
336
-
337
-
338
-
339
-
340
-
341
-
342
-
343
- ## Known bugs
344
- _(Nothing yet)_
345
-
346
-
347
-
348
-
349
-
350
- ## Roadmap
351
- - Upgrade error handling. Add proper error messages;
352
- - Create API methods documentation;
353
-
354
-
355
-
356
-
357
-
358
-
359
-
360
-
361
-
362
-
363
- ## Release History
364
-
365
- ### 3.0.0 (2021-02-20)
366
-
367
-
368
-
369
-
370
- ### 2.1.2 (2019-09-12)
371
- - [x] Fix: Similar namespaces bug - Overwrite of object properties values. Ex: "s1" and "s11";
372
- - [x] Browser version was updated;
373
-
374
-
375
-
376
-
377
-
378
- ### 2.1.1 (2019-06-06)
379
- - [x] Fix: Build a ST object with repeating structure;
380
- - [x] Browser version was updated;
381
- - [ ] Bug: Similar namespaces bug - Overwrite of object properties values. Ex: "s1" and "s11";
382
-
383
-
384
-
385
-
386
-
387
- ### 2.1.0 (2019-06-02)
388
- - [x] Modify methods ( add/update/overwrite ) can receive DT data model;
389
- - [x] Browser version was updated;
390
- - [ ] Bug: Build a ST object with repeating structure;
391
- - [ ] Bug: Similar namespaces bug - Overwrite of object properties values. Ex: "s1" and "s11";
392
-
393
-
394
-
395
-
396
-
397
- ### 2.0.2 (2019-05-30)
398
- - [x] Fix: ST Build regression with boolean values;
399
- - [x] Browser version was updated;
400
- - [ ] Bug: Build a ST object with repeating structure;
401
- - [ ] Bug: Similar namespaces bug - Overwrite of object properties values. Ex: "s1" and "s11";
402
-
403
-
404
-
405
-
406
- ### 2.0.1 (2019-05-30)
407
- - [x] Fix: ST Build (lib._build) was refactored;
408
- - [x] Improvment: Method 'lib._toFolderFiles' has array of counters in sync with duplications;
409
- - [x] Browser version was updated;
410
- - [ ] Bug: ST Build regression with boolean values;
411
- - [ ] Bug: Build a ST object with repeating structure;
412
- - [ ] Bug: Similar namespaces bug - Overwrite of object properties values. Ex: "s1" and "s11".;
413
-
414
-
415
-
416
-
417
-
418
- ### 2.0.0 (2017-12-28)
419
- - [x] Breaking change: Method ‘modifyKeys’ argument should be a function;
420
- - [x] Test cases updates;
421
- - [x] Browser version was updated;
422
- - [ ] Problems with building heavy ST structures;
423
- - [ ] Build a wrong ST object when similar namespaces are available. Example: "sample1" and "sample11";
424
-
425
-
426
-
427
- ### 1.8.0 (2017-12-28)
428
- - [x] Method 'remove' has new argument-key. Evaluate the key name;
429
- - [x] Method 'keep' has new argument-key. Evaluate the key name;
430
- - [x] Test coverage - 100%;
431
-
432
-
433
-
434
- ### 1.7.0 (2017-12-24)
435
- - [x] Browser version is available;
436
- - [x] Dependencies updates ( Mocha, chai );
437
- - [x] Istambul coverage tool was added;
438
- - [x] Some minor project structure changes;
439
- - [x] Unit tests updates for Mocha v.4;
440
-
441
-
442
-
443
- ### 1.6.0 (2017-04-22)
444
- - [x] ExportAPI method `keyValue` returns a key-value string;
445
-
446
-
447
-
448
- ### 1.5.0 (2017-04-17)
449
- - [x] ExportAPI method 'cut' will cut out number of key elements;
450
- - [x] ExportAPI method 'file' will convert dt data to a 'file' model;
451
- - [x] Fix: ExportAPI method 'map' could break the app if callback function does not return a string;
452
-
453
-
454
-
455
- ### 1.4.0 (2017-03-28)
456
- - [x] Fix: Very large files can cause 'stack overflow';
457
- - [ ] Warning: ExportAPI method 'map' could break the app if callback function does not return a string;
458
-
459
-
460
- ### 1.3.0 (2017-02-19)
461
- - [x] API method 'invert' - selector. Invert existing selection;
462
- - [ ] Warning: Very large files can cause 'stack overflow';
463
- - [ ] Warning: ExportAPI method 'map' could break the app if callback function does not return a string;
464
-
465
-
466
-
467
- ### 1.2.0 (2017-02-16)
468
- - [x] ExportAPI method 'list'. Returns findings in an array.
469
- - [x] API method 'deepArray' - selector
470
- - [x] API method 'deepObject' - selector
471
- - [x] API method 'loadFast' - load DT data without meta information calculation.
472
- - [x] ExportLib method `map` is 'root/' aware.
473
- - [ ] Warning: Very large files can cause 'stack overflow';
474
- - [ ] Warning: ExportAPI method 'map' could break the app if callback function does not return a string;
475
-
476
-
477
-
478
-
479
- ### 1.1.2 (2017-02-05)
480
-
481
- - [x] Fix: ExportAPI method `map` has `index` argument;
482
- - [ ] ExportAPI method `map` is not aware of 'root/'. Add 'root/' explicitly;
483
- - [ ] Warning: Very large files can cause 'stack overflow';
484
- - [ ] Warning: ExportAPI method 'map' could break the app if callback function does not return a string;
485
-
486
-
487
-
488
-
489
- ### 1.1.1 (2017-02-04)
490
-
491
- - [x] Fix: Method `empty` now works as it was intended;
492
- - [x] Method `spreadAll` was added and could be used instead the chain: .select().all().spread()
493
- - [ ] ExportAPI method `map` is not aware of 'root/'. Add 'root/' explicitly;
494
- - [ ] Error: ExportAPI method `map` has no `index` argument;
495
- - [ ] Warning: Very large files can cause 'stack overflow';
496
- - [ ] Warning: ExportAPI method 'map' could break the app if callback function does not return a string;
497
-
498
-
499
-
500
-
501
- ### 1.1.0
502
-
503
- - [x] Method `empty` returns empty DT object;
504
- - [x] Compare method were added: `identical`, `change`, `same`, `different`, `missing`
505
- - [ ] Error: Method `empty` is actually an object;
506
- - [ ] Error: ExportAPI method `map` has no `index` argument;
507
- - [ ] Warning: Very large files can cause 'stack overflow';
508
- - [ ] Warning: ExportAPI method `map` is not aware of 'root/'. Add 'root/' explicitly;
509
- - [ ] Warning: ExportAPI method `map` could break the app if callback function does not return a string;
510
-
511
-
512
-
513
-
514
- ### 1.0.2 (2017-01-14)
515
- - [x] Bug fix - init with files;
516
-
517
-
518
-
519
- ### 1.0.0 (2017-01-14)
520
-
521
- - [x] Initial code;
522
- - [x] Test package;
523
- - [x] Documentation;
524
-
525
-
526
-
527
-
528
-
529
- ## Credits
530
- 'dt-toolbox' was created by Peter Naydenov.
531
-
532
-
533
-
534
-
535
-
536
- ## License
537
- 'dt-toolbox' is released under the [MIT License](http://opensource.org/licenses/MIT).
538
-
539
-
540
-