dt-toolbox 5.0.0 → 6.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 (82) hide show
  1. package/Changelog.md +7 -15
  2. package/LICENSE +1 -1
  3. package/Migration.guide.md +14 -1
  4. package/README.md +978 -347
  5. package/README_v.2.x.x.md +0 -1
  6. package/README_v.4.x.x.md +532 -0
  7. package/package.json +22 -25
  8. package/src/convertors/index.js +43 -34
  9. package/src/convertors/midflat.js +76 -132
  10. package/src/convertors/standard.js +61 -86
  11. package/src/convertors/tuples.js +171 -0
  12. package/src/flatData/connect.js +50 -0
  13. package/src/flatData/export.js +46 -0
  14. package/src/flatData/filters/list.js +11 -0
  15. package/src/flatData/filters/listObject.js +13 -0
  16. package/src/flatData/filters/object.js +12 -0
  17. package/src/flatData/filters/root.js +12 -0
  18. package/src/flatData/find.js +20 -0
  19. package/src/flatData/from.js +33 -0
  20. package/src/flatData/get.js +29 -0
  21. package/src/flatData/index.js +101 -0
  22. package/src/flatData/insert.js +24 -0
  23. package/src/flatData/like.js +24 -0
  24. package/src/flatData/look.js +49 -0
  25. package/src/flatData/push.js +19 -0
  26. package/src/flatData/save.js +17 -0
  27. package/src/flatData/set.js +26 -0
  28. package/src/flatData/setupFilter.js +21 -0
  29. package/src/flatData/use.js +16 -0
  30. package/src/flatObject/copy.js +19 -0
  31. package/src/flatObject/export.js +13 -0
  32. package/src/flatObject/index.js +47 -0
  33. package/src/flatObject/insert.js +28 -0
  34. package/src/flatObject/model.js +32 -0
  35. package/src/flatObject/query.js +24 -0
  36. package/src/flatObject/setupFilter.js +12 -0
  37. package/src/main.js +21 -689
  38. package/src/mainLib.js +105 -0
  39. package/src/compareMethod/change.js +0 -21
  40. package/src/compareMethod/different.js +0 -18
  41. package/src/compareMethod/identical.js +0 -21
  42. package/src/compareMethod/index.js +0 -13
  43. package/src/compareMethod/missing.js +0 -18
  44. package/src/compareMethod/same.js +0 -18
  45. package/src/convertors/breadcrumbs.js +0 -148
  46. package/src/help/extractSelection.js +0 -12
  47. package/src/help/filterObject.js +0 -25
  48. package/src/help/hasNumbers.js +0 -14
  49. package/src/help/index.js +0 -35
  50. package/src/help/isItPrimitive.js +0 -10
  51. package/src/help/objectsByLevel.js +0 -16
  52. package/src/help/reduceTuples.js +0 -29
  53. package/src/help/sanitizeFlatKeys.js +0 -30
  54. package/src/help/toBreadcrumbsKeys.js +0 -28
  55. package/src/help/tuplesToBreadcrumbs.js +0 -25
  56. package/src/help/updateSelection.js +0 -12
  57. package/src/help/zipObject.js +0 -24
  58. package/src/lib/assemble.js +0 -45
  59. package/src/lib/attach.js +0 -20
  60. package/src/lib/block.js +0 -33
  61. package/src/lib/combine.js +0 -38
  62. package/src/lib/deep.js +0 -23
  63. package/src/lib/find.js +0 -36
  64. package/src/lib/folder.js +0 -42
  65. package/src/lib/index.js +0 -56
  66. package/src/lib/modify.js +0 -22
  67. package/src/lib/parent.js +0 -51
  68. package/src/lib/purify.js +0 -37
  69. package/src/lib/transform.js +0 -55
  70. package/src/modifiers/add.js +0 -18
  71. package/src/modifiers/append.js +0 -18
  72. package/src/modifiers/combineShallow.js +0 -119
  73. package/src/modifiers/flatten.js +0 -38
  74. package/src/modifiers/index.js +0 -34
  75. package/src/modifiers/insert.js +0 -21
  76. package/src/modifiers/keyPrefix.js +0 -27
  77. package/src/modifiers/mix.js +0 -25
  78. package/src/modifiers/overwrite.js +0 -18
  79. package/src/modifiers/prepend.js +0 -19
  80. package/src/modifiers/reverse.js +0 -23
  81. package/src/modifiers/update.js +0 -18
  82. package/src/simple.js +0 -49
package/src/main.js CHANGED
@@ -1,11 +1,10 @@
1
1
  'use strict'
2
2
 
3
-
4
3
  /*
5
4
  DT object & DT Toolbox
6
5
  =======================
7
6
 
8
- Version 4.0.7
7
+ Version 6.0.0
9
8
 
10
9
  History notes:
11
10
  - Idea was born on March 17th, 2016.
@@ -15,6 +14,7 @@
15
14
  - Invert selection method was added. February 19th, 2017
16
15
  - String format support introduces. April 22th, 2017
17
16
  - Works in browsers. December 24th, 2017
17
+
18
18
  - Refactoring and version 3.0.0 April 14th, 2020 - February 24th, 2020
19
19
  * Much faster and memory efficient algorithms;
20
20
  * Multiple convertors for switching among different data-type;
@@ -22,701 +22,33 @@
22
22
  * Old internal data-type have a new name(breadcrumbs) and is fully supported(import/export);
23
23
  * Support for tuples(import and export);
24
24
  * Complete code refactoring;
25
-
25
+
26
+ - Refactoring and version 6.0.0 May 12th 2023
27
+ * Keeps only the idea, changes everything else;
28
+ * Simplified API interface;
29
+ * New internal data model;
30
+ * Data inserts;
31
+ * Filters for faster data scan;
32
+ * Model and query functions to shape results;
26
33
  */
27
34
 
28
-
29
- import walk from '@peter.naydenov/walk'
30
-
31
- import dtlib from './lib/index.js'
32
- import help from './help/index.js'
33
- import modifier from './modifiers/index.js'
34
- import convert from './convertors/index.js'
35
- import compareMethod from './compareMethod/index.js'
36
-
37
- const
38
- INIT_DATA_TYPES = [
39
- 'std', 'standard'
40
- , 'tuple', 'tuples'
41
- , 'breadcrumb', 'breadcrumbs'
42
- , 'file', 'files'
43
- , 'midFlat'
44
- , 'shortFlat'
45
- ];
46
-
47
-
48
-
49
-
50
-
51
- const mainlib = {
52
-
53
-
54
-
55
- dependencies () {
56
- const h = Object.create ( API );
57
- function simpleDT () {
58
- const dt = Object.create ( API );
59
- dt.value = dt.empty ()
60
- dt.structure = []
61
- dt._select = { structure:[], value:[], result: null }
62
- dt._error = []
63
- return dt
64
- } // simpleDT func.
65
- return {
66
- simpleDT
67
- , empty: h.empty
68
- , convert
69
- , help
70
- , modifier
71
- , walk
72
- }
73
- } // dependencies func.
74
-
75
- /**
76
- * Init options:
77
- * modifier(modify):
78
- * keys - take keys as value. Ignore original values.
79
- * nokeys - ignore keys. Convert objects to arrays
80
- * values - use values as keys
81
- * reverse - keys will become values and values - keys
82
- *
83
- * data-type(type):
84
- * std - standard js object
85
- * breadcrumb - key as a folder. Separate value
86
- * file - keys and values in a single string
87
- * tuples - array of tuples. Tuple[0] is the key, tuple[1] is the value
88
- */
89
-
90
- , init ( inData, options ) { // dataType is instruction to convertor
91
- let
92
- dependencies = mainlib.dependencies ()
93
- , dt = dependencies.simpleDT ()
94
- , help = dependencies.help
95
- , defaultOptions = {type:'std', modify:false }
96
- , { type, modify } = { ...defaultOptions,...options }
97
- ;
98
- if ( !INIT_DATA_TYPES.includes(type) ) {
99
- this._error.push ( `Can't understand your data-type: ${type}. Please, find what is possible on https://github.com/PeterNaydenov/dt-toolbox` )
100
- return
101
- }
102
- if ( inData != null ) {
103
- // Note: Use method 'load' instead of 'init' if your data is 'flat'
104
- const [structure, value] = ( type == 'flat' || type == 'shortFlat' ) ? inData : convert.from(type).toFlat ( dependencies, inData )
105
- dt.structure = walk ({ data:structure })
106
- dt.value = value
107
- }
108
- if ( !modify ) return dt
109
- else {
110
- let [structure, value] = dtlib.transform ( {...dependencies, modify }, [dt.structure, dt.value] );
111
- let missingValues = ( Object.keys ( value ).length <= 0 );
112
- if ( missingValues ) {
113
- dt._error.push ( `Modifier "${modify}" is not a valid modifier and was ignored. Data: ${JSON.stringify(inData)}` )
114
- }
115
- dt.structure = structure
116
- dt.value = value
117
- return dt
118
- }
119
- } // init func.
120
-
121
-
122
-
123
-
124
-
125
- , load ( flatData ) { // Load dt content - dtShort and dtLong data types
126
- return ( flatData._select )
127
- ? dtlib.loadLong ( mainlib.dependencies(), flatData )
128
- : dtlib.loadShort ( mainlib.dependencies(), flatData )
129
- } // load
130
-
131
-
132
-
133
-
134
-
135
- , preprocess ( inData, fn, options ) {
136
- let
137
- defaultOptions = { type:'std', modify:false }
138
- , { type='std' } = { ...defaultOptions,...options }
139
- , shortFlat = convert.from (type).toFlat ( mainlib.dependencies(), inData )
140
- , afterProcess = fn ( shortFlat ) // afterProcess should be in 'shortFlat' data-type
141
- ;
142
- if ( !afterProcess ) {
143
- this._error.push ( 'Method "preprocess" should always return a shortFlat data-type: [structure, value]' )
144
- return mainlib.init () // On preprocess error, create an empty object
145
- }
146
- return dtlib.loadShort ( mainlib.dependencies(), afterProcess )
147
- } // preprocess func.
148
-
149
-
150
-
151
- , combine ( inData, options ) {
152
- const
153
- me = this
154
- , updateData = mainlib.init ( inData, options )
155
- ;
156
- return dtlib.combine ( {...mainlib.dependencies()}, me, updateData)
157
- } // combine func.
158
-
159
-
160
- , modify ( method ) {
161
- return function ( inData, options ) {
162
- const me = this;
163
- let updateData;
164
-
165
- if ( options ) updateData = mainlib.init ( inData, options )
166
- else updateData = {
167
- structure : walk ({ data:inData.structure })
168
- , value : {...inData.value }
169
- }
170
- return dtlib.modify ( { ...mainlib.dependencies(), action:method}, me, updateData )
171
- }} // modify func.
172
-
173
-
174
-
175
- , errorLog ( callback ) { // Executes callback with errors as argument
176
- callback ( this._error )
177
- return this
178
- } // errorLog func.
179
-
180
-
181
-
182
-
183
- , replace () { // Convert _select.result to me.value and me.structure
184
- const
185
- me = this
186
- , { result } = me._select
187
- ;
188
- if ( !result ) return me
189
- let [struct, val] = convert.from ( 'midFlat').toFlat ( mainlib.dependencies(), result )
190
- me.structure = walk ({ data:struct })
191
- me.value = {...val}
192
- me._select.result = null
193
- return me
194
- } // replace func.
195
-
196
-
197
-
198
-
199
-
200
- , attach ( location ) {
201
- const
202
- me = this
203
- , dependencies = { ...mainlib.dependencies(), location }
204
- ;
205
- let [structure, value ] = dtlib.attach ( dependencies, me )
206
- me.structure = walk ({ data:structure })
207
- me.value = {...value}
208
- me._select.result = null
209
- return me
210
- } // attach func.
211
-
212
-
213
-
214
-
215
-
216
- , select () { // Init a new selection
217
- this._select = { structure:[], value:[], result : null }
218
- return this
219
- }
220
-
221
-
222
-
223
-
224
-
225
- , find ( search='root', deep ) {
226
- // *** Find if string exists in a bradcrumb keys.
227
- const
228
- me = this
229
- , dependencies = { ...mainlib.dependencies(), search, deep }
230
- ;
231
- me._select.result = null
232
- return dtlib.find ( dependencies, me )
233
- } // find func.
234
-
235
-
236
-
237
-
238
-
239
- , parent ( prop, where ) {
240
- const
241
- me = this
242
- , dependencies = { ...mainlib.dependencies(), prop, where }
243
- ;
244
- me._select.result = null
245
- return dtlib.parent ( dependencies, me )
246
- } // parent func.
247
-
248
-
249
-
250
-
251
- , folder ( prop='root', where ) {
252
- const
253
- me = this
254
- , dependencies = { ...mainlib.dependencies(), prop, where }
255
- ;
256
- me._select.result = null
257
- return dtlib.folder ( dependencies, me )
258
- } // folder func.
259
-
260
-
261
-
262
-
263
-
264
- , limit ( num ) {
265
- // *** Filter. Limit number of selected items
266
- this._select.value = this._select.value.slice ( 0, num )
267
- this._select.result = null
268
- return this
269
- }
270
-
271
-
272
-
273
-
274
-
275
- , keep ( fx ) {
276
- // *** Filter. Reduce selected item by testing their values. If pass the test will stay.
277
- const
278
- me = this
279
- , breadcrumbKeys = help.toBreadcrumbKeys ( me._select.value, me.structure )
280
- ;
281
- if ( fx === undefined ) return me
282
- me._select.result = null
283
- me._select.value = me._select.value.reduce ( (res, flatKey, i ) => {
284
- let breadcrumbKey = breadcrumbKeys[i];
285
- if ( fx(me.value[flatKey], breadcrumbKey, flatKey) ) res.push ( flatKey )
286
- return res
287
- },[])
288
- return me
289
- } // keep func.
290
-
291
-
292
-
293
-
294
- , remove ( fx ) {
295
- // *** Filter. Reduce selected item by testing their values. If pass the test will remove.
296
- const
297
- me = this
298
- , breadcrumbKeys = help.toBreadcrumbKeys ( me._select.value, me.structure )
299
- ;
300
- if ( fx === undefined ) return me
301
- me._select.result = null
302
- me._select.value = me._select.value.reduce ( (res, flatKey,i) => {
303
- let breadcrumbKey = breadcrumbKeys[i];
304
- if ( !fx(me.value[flatKey],breadcrumbKey,flatKey) ) res.push ( flatKey )
305
- return res
306
- }, [] )
307
- return me
308
- } // remove func.
309
-
310
-
311
-
312
-
313
-
314
- , deep ( num, direction='less') {
315
- // *** Filter. Direction is 'more' or 'less'. Less is by default. Deep '0' mean root members;
316
- let
317
- me = this
318
- , dependencies = { ...mainlib.dependencies(), num, direction }
319
- ;
320
- me._select.result = null
321
- return dtlib.deep ( dependencies, me )
322
- } // deep func.
323
-
324
-
325
-
326
- , withData () {
327
- let me = this;
328
- me._select.result = convert.to ( 'midFlat', mainlib.dependencies(), [ me.structure, me.value] )
329
- return me
330
- } // withData func.
331
-
332
35
 
333
36
 
334
- , withSelection () {
335
- let
336
- me = this
337
- , { structure } = me._select
338
- ;
339
- me._select.result = convert.to ( 'midFlat', mainlib.dependencies(), [structure, help.extractSelection(me)] )
340
- return me
341
- } // withSelection func.
37
+ import mainLib from './mainLib.js'
38
+ const { init, load, flating, converting, getWalk } = mainLib;
342
39
 
343
40
 
344
41
 
345
-
346
-
347
- , flatten () {
348
- const
349
- me = this
350
- , { result } = me._select
351
- ;
352
- if ( !result ) return me
353
- me._select.result = modifier['flatten'] ( result, {})
354
- return me
355
- } // flatten func.
356
-
357
-
358
-
359
-
360
- , mix ( host='root', guestList=[] ) {
361
- const
362
- me = this
363
- , { result } = me._select
364
- ;
365
- if ( !result ) return me
366
- me._select.result = modifier ['mix'] ( result, [...guestList,host])
367
- return me
368
- } // mix func.
369
-
370
-
371
-
372
- , reverse ( namespace = ['root'] ) {
373
- const
374
- me = this
375
- , { result } = me._select
376
- ;
377
- if ( !result ) return me
378
- me._select.result = modifier['reverse'] ( result, namespace )
379
- return me
380
- } // reverse func.
381
-
382
-
383
-
384
- , keyPrefix ( separationSymbol='' ) {
385
- const
386
- me = this
387
- , { result } = me._select
388
- ;
389
- if ( !result ) return me
390
- me._select.result = modifier['keyPrefix'] ( result, {separationSymbol})
391
- return me
392
- } // keyPrefix func.
393
-
394
-
395
-
396
-
397
- , block ( type ) {
398
- // *** Selector. Fullfil '_select' with deepest structure elements
399
- return function () {
400
- const
401
- me = this
402
- , dependencies = { ...mainlib.dependencies(), type }
403
- ;
404
- me._select.result = null
405
- return dtlib.block ( dependencies, me )
406
- }} // block func.
407
-
408
-
409
-
410
-
411
-
412
- , invert ( ) {
413
- // *** Selector. Invert the selection
414
- const
415
- me = this
416
- , selection = me._select.value
417
- , valueKeys = Object.keys ( me.value )
418
- ;
419
- me._select.result = null
420
- me._select.value = valueKeys.reduce ( (res,item) => {
421
- if ( !selection.includes(item) ) res.push(item)
422
- return res
423
- }, [] )
424
- return me
425
- } // invert func.
426
-
427
-
428
-
429
-
430
-
431
- , assemble () {
432
- const
433
- me = this
434
- , dependencies = { ...mainlib.dependencies() }
435
- ;
436
- return dtlib.assemble ( dependencies, me )
437
- } // assemble func.
438
-
439
-
42
+ const dtbox = {
43
+ init : init
44
+ , load : load
45
+ , flat : flating
46
+ , convert : converting
47
+ , getWalk
48
+ } // dtbox func.
440
49
 
441
50
 
442
51
 
443
- , purify () {
444
- const
445
- me = this
446
- , dependencies = { ...mainlib.dependencies() }
447
- ;
448
- return dtlib.purify ( dependencies, me )
449
- } // purify func.
450
-
451
-
452
-
453
-
454
-
455
-
456
-
457
-
458
-
459
-
460
- , compare ( methodName) {
461
- return function ( data, callback ) {
462
- if (
463
- !data.hasOwnProperty ( 'value' )
464
- ||
465
- !data.hasOwnProperty ( 'structure' )
466
- ) {
467
- const errorMsg = 'Error: Compared object should be data-type "flat"';
468
- callback ( null )
469
- return this
470
- }
471
-
472
- let
473
- me = this
474
- , mainData = convert.to ( 'breadcrumb', mainlib.dependencies(), [me.structure, me.value] )
475
- , checkData = convert.to ( 'breadcrumb', mainlib.dependencies(), [data.structure, data.value] )
476
- ;
477
- let
478
- result = compareMethod[methodName] ( mainData, checkData )
479
- , [ structure, value ] = convert.from ( 'breadcrumb' ).toFlat ( mainlib.dependencies(), result )
480
- , dt = mainlib.dependencies().simpleDT ()
481
- ;
482
- dt.structure = structure
483
- dt.value = value
484
- callback ( dt )
485
- return me
486
- }} // compare func.
487
-
488
-
489
-
490
-
491
-
492
-
493
-
494
-
495
-
496
- , spread ( instruction, callback ) {
497
- // *** Returns result of the selection in a callback
498
- // If callback is missing - returns result of the selection directly
499
- const
500
- me = this
501
- , hasSelection = me._select.result ? true : false
502
- , { help } = mainlib.dependencies ()
503
- ;
504
- let selection, modify, vals;
505
- /**
506
- * Instructions:
507
- * - standard/std: standard js object;
508
- * - breadcrumb(s): keys position described as breadcrumb and values are primitives(number,boolean,string);
509
- * - file(s): Array of combined breadcrumb keys and value in single string;
510
- * - midFlat: Mix. Breadcrumb keys and values are object with primitive properties;
511
- * - tuples: Object described as array of arrays with two elements. First is the key, second is the value;
512
- * - flat: Library internal description of the object
513
- * - key(s): Array of all keys
514
- * - value(s): Array of all values
515
- */
516
- switch ( instruction ) {
517
- case 'value' :
518
- case 'values' :
519
- modify = 'values'
520
- if ( hasSelection ) {
521
- let data = convert.from ( 'midFlat' ).toFlat ( mainlib.dependencies(), me._select.result );
522
- vals = dtlib.transform ( {...mainlib.dependencies(),modify}, data )
523
- }
524
- else {
525
- vals = dtlib.transform ( {...mainlib.dependencies(), modify }, [me.structure, me.value] );
526
- }
527
- selection = convert
528
- .to ( 'std', mainlib.dependencies(), vals )
529
- .map ( v => {
530
- switch ( typeof v ) {
531
- case 'string' : return Number(v) || v
532
- default : return v
533
- }
534
- })
535
- break
536
- case 'key' :
537
- case 'keys' :
538
- modify = 'keys'
539
- if ( hasSelection ) {
540
- let data = convert.from ( 'midFlat' ).toFlat ( mainlib.dependencies(), me._select.result )
541
- vals = dtlib.transform ( {...mainlib.dependencies(), modify}, data )
542
- modify = 'values'
543
- vals = dtlib.transform ( {...mainlib.dependencies(), modify}, vals )
544
- }
545
- else {
546
- vals = dtlib.transform ( {...mainlib.dependencies(),modify},[me.structure, me.value])
547
- }
548
- selection = convert.to ( 'std', mainlib.dependencies(), vals )
549
- break
550
- case 'standard' :
551
- case 'std' :
552
- if ( hasSelection ) {
553
- let temp = convert.from ( 'midFlat').toFlat ( mainlib.dependencies(), me._select.result );
554
- selection = convert.to ( 'std', mainlib.dependencies(), temp )
555
- }
556
- else selection = convert.to ( 'std', mainlib.dependencies(), [me._select.structure, help.extractSelection(me)] )
557
- break
558
- case 'breadcrumb' :
559
- case 'breadcrumbs' :
560
- if ( hasSelection ) {
561
- let breadData = convert.from ( 'midFlat' ).toFlat ( mainlib.dependencies(), me._select.result );
562
- selection = convert.to ( 'breadcrumbs', mainlib.dependencies(), breadData )
563
- }
564
- else {
565
- selection = convert.to ( 'breadcrumbs', mainlib.dependencies(), [me._select.structure, help.extractSelection(me)])
566
- }
567
- break
568
- case 'tuple' :
569
- case 'tuples' :
570
- if ( hasSelection ) {
571
- let tupSelect = convert.from ( 'midFlat' ).toFlat ( mainlib.dependencies(), me._select.result );
572
- selection = convert.to ( 'tuples', mainlib.dependencies(), tupSelect )
573
- }
574
- else {
575
- selection = convert.to ( 'tuples', mainlib.dependencies(), [me._select.structure, help.extractSelection(me)]);
576
- }
577
- break
578
- case 'file' :
579
- case 'files' :
580
- let fileData, tuples;
581
- if ( hasSelection ) {
582
- let fileSelect = convert.from ( 'midFlat').toFlat ( mainlib.dependencies(), me._select.result );
583
- fileData = convert.to ( 'breadcrumbs', mainlib.dependencies(), fileSelect )
584
- }
585
- else fileData = convert.to ( 'breadcrumbs', mainlib.dependencies, [me._select.structure, help.extractSelection(me)])
586
- tuples = help.reduceTuples ( mainlib.dependencies(), fileData )
587
- selection = tuples.map ( ([k,v])=> {
588
- if ( k ) return `${k}/${v}`
589
- else return v
590
- })
591
- break
592
- case 'midFlat' :
593
- if ( hasSelection ) selection = { ...me._select.result }
594
- else selection = convert.to ( 'midFlat', mainlib.dependencies(), [me._select.structure, help.extractSelection(me)])
595
- break
596
- case 'flat' :
597
- // NOTE:
598
- // The 'flat' is internal only data-type. Spread 'flat'
599
- // always means 'shortFlat'.
600
- //
601
- case 'shortFlat' :
602
- default : {
603
- if ( hasSelection ) {
604
- selection = convert.from ( 'midFlat').toFlat ( mainlib.dependencies(), me._select.result )
605
- }
606
- else {
607
- let
608
- set = help.extractSelection ( me )
609
- , struct = walk ({ data:me._select.structure })
610
- ;
611
- selection = [ struct, set ]
612
- }
613
- }
614
- } // switch instruction
615
-
616
- if ( callback ) {
617
- callback ( selection )
618
- return me
619
- }
620
- else {
621
- return selection
622
- }
623
- } // spread func.
624
-
625
-
626
-
627
- , spreadAll ( instruction, callback ) {
628
- this.all ()
629
- return this.spread ( instruction, callback )
630
- } // spreadAll func..
631
-
632
- } // mainlib
633
-
634
-
635
-
636
-
637
-
638
-
639
-
640
-
641
-
642
-
643
-
644
- const exportAPI = {
645
- hi () { return 'hi' }
646
- }
647
-
648
-
649
-
650
-
651
-
652
-
653
-
654
-
655
-
656
-
657
- // * Official API
658
- const API = {
659
- // DT I/O Operations
660
- init : mainlib.init // Convert any object to flat data-type
661
- , load : mainlib.load // Load a flat data-type
662
- , loadFast : mainlib.load // Important! Method is depricated. Use load instead
663
-
664
- , preprocess : mainlib.preprocess // Apply custom modifier to initial data.
665
- , add : mainlib.modify ( 'add' ) // Add data and keep existing data
666
- , update : mainlib.modify ( 'update' ) // Updates only existing data
667
- , overwrite : mainlib.modify ( 'overwrite' ) // Add new data to DT object. Overwrite existing fields
668
- , insert : mainlib.modify ( 'insert' ) // Insert data on specified key, when the key represents an array.
669
- , combine : mainlib.combine // Combine values for simular keys in arrays
670
- , append : mainlib.modify ( 'append' ) // Combine values for duplicated keys. main + update
671
- , prepend : mainlib.modify ( 'prepend' ) // Combine values for duplicated keys. update + main
672
- , log : mainlib.errorLog // Executes callback with errors list as argument
673
- , empty : () => Object.create ( exportAPI ) // Empty object with export methods
674
-
675
- // Provide Results
676
- , replace : mainlib.replace // Get this._selection.result as a main data
677
- , attach : mainlib.attach // Attach this._selection.result to the main data. Set point of connection
678
- , spread : mainlib.spread // Returns result of selection in a callback
679
- , spreadAll : mainlib.spreadAll // Select all and returns it with one command in a callback
680
- , export : mainlib.spread // Returns result of selection
681
- , exportAll : mainlib.spreadAll // Select all and returns it with one command
682
-
683
- // Compare Operations
684
- , identical : mainlib.compare ( 'identical' ) // Value compare. Reduce data to identical key/value pairs.
685
- , change : mainlib.compare ( 'change' ) // Value compare. Reduce to key/value pairs with different values.
686
- , same : mainlib.compare ( 'same' ) // Key compare. Returns key/value pairs where keys are the same.
687
- , different : mainlib.compare ( 'different' ) // Key compare. Returns key/value pairs where key does not exist.
688
- , missing : mainlib.compare ( 'missing' ) // Key compare. Returns key/value pairs that are missing.
689
-
690
- // Selectors
691
- , select : mainlib.select // Initialize a new selection.
692
- , parent : mainlib.parent // Selector. Apply conditions starting from parent level
693
- , find : mainlib.find // Selector. Fullfil select with list of arguments that contain specific string
694
- , all : mainlib.find // Selector. Same as find ('root')
695
- , folder : mainlib.folder // Selector. Fullfil selection with 'midFlat' object props
696
- , space : mainlib.folder // Selector. Same as 'folder'
697
- , deepObject : mainlib.block ( 'object' ) // Selector. Fullfil '_select' with deepest object elements
698
- , deepArray : mainlib.block ( 'array' ) // Selector. Fullfil '_select' with deepest array elements
699
- , invert : mainlib.invert // Selector. Invert existing selection
700
- , assemble : mainlib.assemble // Converts selection into 'array of objects' or 'single flat object'
701
- , purify : mainlib.purify // Removes all empty structures ( no props ) from the selection
702
-
703
- // Filters
704
- , limit : mainlib.limit // Filter. Reduces amount of records in the selection
705
- , keep : mainlib.keep // Filter. Keeps records in selection if check function returns true
706
- , remove : mainlib.remove // Filter. Removes records from selection if check function returns true
707
- , deep : mainlib.deep // Filter. Arguments ( num, direction - optional). Num mean level of deep. Deep '0' mean root members
708
-
709
- // Modifiers
710
- , withData : mainlib.withData // Generate "this._select.result" from the official data. Modifier will work with this data
711
- , withSelection : mainlib.withSelection // Generate "this._select.result" content. Modifier will work with this data
712
- , flatten : mainlib.flatten // Mix existing objects in a single object.
713
- , mix : mainlib.mix // Mix objects in order. Start with a host and provide guests list [].
714
- , keyPrefix : mainlib.keyPrefix // Modify key as object name+key. Separator-symbol default: emptySpace. It can be modified.
715
- , reverse : mainlib.reverse // Change place of keys and values
716
- }; // API
717
-
718
-
719
-
720
- export default API
721
-
52
+ export default dtbox
53
+
722
54