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