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.
- package/Changelog.md +7 -15
- package/LICENSE +1 -1
- package/Migration.guide.md +14 -1
- package/README.md +978 -347
- package/README_v.2.x.x.md +0 -1
- package/README_v.4.x.x.md +532 -0
- package/package.json +22 -25
- package/src/convertors/index.js +43 -34
- package/src/convertors/midflat.js +76 -132
- package/src/convertors/standard.js +61 -86
- package/src/convertors/tuples.js +171 -0
- package/src/flatData/connect.js +50 -0
- package/src/flatData/export.js +46 -0
- package/src/flatData/filters/list.js +11 -0
- package/src/flatData/filters/listObject.js +13 -0
- package/src/flatData/filters/object.js +12 -0
- package/src/flatData/filters/root.js +12 -0
- package/src/flatData/find.js +20 -0
- package/src/flatData/from.js +33 -0
- package/src/flatData/get.js +29 -0
- package/src/flatData/index.js +101 -0
- package/src/flatData/insert.js +24 -0
- package/src/flatData/like.js +24 -0
- package/src/flatData/look.js +49 -0
- package/src/flatData/push.js +19 -0
- package/src/flatData/save.js +17 -0
- package/src/flatData/set.js +26 -0
- package/src/flatData/setupFilter.js +21 -0
- package/src/flatData/use.js +16 -0
- package/src/flatObject/copy.js +19 -0
- package/src/flatObject/export.js +13 -0
- package/src/flatObject/index.js +47 -0
- package/src/flatObject/insert.js +28 -0
- package/src/flatObject/model.js +32 -0
- package/src/flatObject/query.js +24 -0
- package/src/flatObject/setupFilter.js +12 -0
- package/src/main.js +21 -689
- package/src/mainLib.js +105 -0
- package/src/compareMethod/change.js +0 -21
- package/src/compareMethod/different.js +0 -18
- package/src/compareMethod/identical.js +0 -21
- package/src/compareMethod/index.js +0 -13
- package/src/compareMethod/missing.js +0 -18
- package/src/compareMethod/same.js +0 -18
- package/src/convertors/breadcrumbs.js +0 -148
- package/src/help/extractSelection.js +0 -12
- package/src/help/filterObject.js +0 -25
- package/src/help/hasNumbers.js +0 -14
- package/src/help/index.js +0 -35
- package/src/help/isItPrimitive.js +0 -10
- package/src/help/objectsByLevel.js +0 -16
- package/src/help/reduceTuples.js +0 -29
- package/src/help/sanitizeFlatKeys.js +0 -30
- package/src/help/toBreadcrumbsKeys.js +0 -28
- package/src/help/tuplesToBreadcrumbs.js +0 -25
- package/src/help/updateSelection.js +0 -12
- package/src/help/zipObject.js +0 -24
- package/src/lib/assemble.js +0 -45
- package/src/lib/attach.js +0 -20
- package/src/lib/block.js +0 -33
- package/src/lib/combine.js +0 -38
- package/src/lib/deep.js +0 -23
- package/src/lib/find.js +0 -36
- package/src/lib/folder.js +0 -42
- package/src/lib/index.js +0 -56
- package/src/lib/modify.js +0 -22
- package/src/lib/parent.js +0 -51
- package/src/lib/purify.js +0 -37
- package/src/lib/transform.js +0 -55
- package/src/modifiers/add.js +0 -18
- package/src/modifiers/append.js +0 -18
- package/src/modifiers/combineShallow.js +0 -119
- package/src/modifiers/flatten.js +0 -38
- package/src/modifiers/index.js +0 -34
- package/src/modifiers/insert.js +0 -21
- package/src/modifiers/keyPrefix.js +0 -27
- package/src/modifiers/mix.js +0 -25
- package/src/modifiers/overwrite.js +0 -18
- package/src/modifiers/prepend.js +0 -19
- package/src/modifiers/reverse.js +0 -23
- package/src/modifiers/update.js +0 -18
- package/src/simple.js +0 -49
package/src/lib/assemble.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
function assemble ( dependencies, me ) {
|
|
2
|
-
const
|
|
3
|
-
{ structure, value } = me._select
|
|
4
|
-
, listIndex = new Set ()
|
|
5
|
-
, countObjects = new Set ()
|
|
6
|
-
, firstRow = [ 'array', 0 ]
|
|
7
|
-
;
|
|
8
|
-
let small = value.reduce ( (res, k) => {
|
|
9
|
-
let num = parseInt ( k.split ( '/' )[1] );
|
|
10
|
-
listIndex.add ( num )
|
|
11
|
-
if ( num < res ) res = num
|
|
12
|
-
return res
|
|
13
|
-
}, 100000 )
|
|
14
|
-
// small -> id of first object with primitive values
|
|
15
|
-
me._select.structure = structure.reduce ( (res,item) => { // Build structure of selection
|
|
16
|
-
let
|
|
17
|
-
ix = item[1]
|
|
18
|
-
, inScope = ( ix >= small )
|
|
19
|
-
;
|
|
20
|
-
if ( inScope && listIndex.has(ix) ) {
|
|
21
|
-
res.push ([...item])
|
|
22
|
-
countObjects.add ( ix )
|
|
23
|
-
}
|
|
24
|
-
return res
|
|
25
|
-
}, [ firstRow ] )
|
|
26
|
-
|
|
27
|
-
if ( listIndex.has(0) ) me._select.structure.splice ( 1, 1 )
|
|
28
|
-
if ( countObjects.size > 1 ) { // Selection has more than one object. Connect objects to root element
|
|
29
|
-
let countIx = 0;
|
|
30
|
-
countObjects.forEach ( i => {
|
|
31
|
-
let rec = me._select.structure[0];
|
|
32
|
-
if ( i != 0 ) rec.push ( [i, countIx++])
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
else { // Data comes from a single source. Use that source object as 'root'.
|
|
36
|
-
me._select.structure.splice ( 0, 1 )
|
|
37
|
-
}
|
|
38
|
-
return me
|
|
39
|
-
} // assemble func..
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export default assemble
|
|
44
|
-
|
|
45
|
-
|
package/src/lib/attach.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
function attach ( dependencies, me ) {
|
|
2
|
-
const
|
|
3
|
-
{ convert, location } = dependencies
|
|
4
|
-
, mainData = convert.to ( 'midFlat', dependencies, [ me.structure, me.value ] )
|
|
5
|
-
, { result } = me._select
|
|
6
|
-
;
|
|
7
|
-
if ( !result ) return me
|
|
8
|
-
for ( let k in result ) {
|
|
9
|
-
const newKey = k.replace ( 'root', location )
|
|
10
|
-
if ( mainData[newKey] ) mainData[newKey] = { ...mainData[newKey],...result[k] } // Merge two objects
|
|
11
|
-
else mainData[newKey] = { ...result[k]}
|
|
12
|
-
} // for k
|
|
13
|
-
return convert.from ( 'midFlat').toFlat ( dependencies, mainData )
|
|
14
|
-
} // attach func.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export default attach
|
|
19
|
-
|
|
20
|
-
|
package/src/lib/block.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
function block ( dependencies, me ) {
|
|
2
|
-
/**
|
|
3
|
-
* Selects deeper structure 'array' or 'object'
|
|
4
|
-
*/
|
|
5
|
-
const
|
|
6
|
-
{ type } = dependencies
|
|
7
|
-
, keys = Object.keys ( me.value )
|
|
8
|
-
;
|
|
9
|
-
let selectedIDs = me.structure.reduce ( (res,row) => {
|
|
10
|
-
let rowType = row[0];
|
|
11
|
-
if ( rowType != type ) return res
|
|
12
|
-
if ( row.length == 2 ) res.push ( row[1] )
|
|
13
|
-
return res
|
|
14
|
-
},[])
|
|
15
|
-
me._select.value = keys.filter ( key => {
|
|
16
|
-
let objectID = parseInt ( key.split('/')[1]);
|
|
17
|
-
return selectedIDs.includes ( objectID )
|
|
18
|
-
})
|
|
19
|
-
// Prepare structure as array of objects and update selected keys
|
|
20
|
-
me._select.structure = [[ 'array', 0 ]]
|
|
21
|
-
selectedIDs.forEach ( (id,i) => {
|
|
22
|
-
let localType = me.structure[id][0];
|
|
23
|
-
me._select.structure[0].push ( [id, i])
|
|
24
|
-
me._select.structure.push ( [localType, id])
|
|
25
|
-
})
|
|
26
|
-
return me
|
|
27
|
-
} // block func.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export default block
|
|
32
|
-
|
|
33
|
-
|
package/src/lib/combine.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
function combine ( dependencies, main, addData ) {
|
|
2
|
-
// *** Modify combine
|
|
3
|
-
const
|
|
4
|
-
{ convert, modifier, walk } = dependencies
|
|
5
|
-
, mainData = convert.to ( 'midFlat', dependencies, [main.structure, main.value])
|
|
6
|
-
, update = convert.to ( 'midFlat', dependencies, [addData.structure, addData.value] )
|
|
7
|
-
, keyList = Object.keys ( update )
|
|
8
|
-
;
|
|
9
|
-
let result;
|
|
10
|
-
main._error = main._error.concat ( addData._error )
|
|
11
|
-
result = keyList.reduce ( (res,k) => {
|
|
12
|
-
let
|
|
13
|
-
check = k.split('/').pop()
|
|
14
|
-
, rootKeys = Object.keys(res['root'])
|
|
15
|
-
;
|
|
16
|
-
if ( check !='root' && res[k] ) {
|
|
17
|
-
let up = {}
|
|
18
|
-
up[k] = {...update[k]}
|
|
19
|
-
return modifier ['combineShallow'] ( res, up )
|
|
20
|
-
}
|
|
21
|
-
if ( check!='root' && rootKeys.includes(check) ) {
|
|
22
|
-
let up = {};
|
|
23
|
-
up[k] = {...update[k]}
|
|
24
|
-
return modifier['combineShallow'] ( res, up)
|
|
25
|
-
}
|
|
26
|
-
else return modifier['combineShallow'] ( res, { root: {...update[k]}} )
|
|
27
|
-
}, mainData )
|
|
28
|
-
let [structure, value ] = convert.from ( 'midFlat').toFlat ( dependencies, result )
|
|
29
|
-
main.structure = walk ({ data:structure })
|
|
30
|
-
main.value = value
|
|
31
|
-
return main
|
|
32
|
-
} // combine func.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export default combine
|
|
37
|
-
|
|
38
|
-
|
package/src/lib/deep.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
function deep ( dependencies, me ) {
|
|
2
|
-
const { help, num, direction } = dependencies
|
|
3
|
-
let
|
|
4
|
-
usedNumbers = []
|
|
5
|
-
, selectedKeys = [ ...me._select.value ]
|
|
6
|
-
, levels = help.objectsByLevel ( me.structure )
|
|
7
|
-
;
|
|
8
|
-
levels.forEach ( (level,i) => {
|
|
9
|
-
let condition = (direction == 'more') ? ( i >= num ) : ( i <= num );
|
|
10
|
-
if ( condition ) usedNumbers = usedNumbers.concat ( level )
|
|
11
|
-
})
|
|
12
|
-
me._select.value = selectedKeys.filter ( key => {
|
|
13
|
-
let objectID = parseInt (key.split('/')[1]);
|
|
14
|
-
return usedNumbers.includes ( objectID )
|
|
15
|
-
})
|
|
16
|
-
return me
|
|
17
|
-
} // deep func.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export default deep
|
|
22
|
-
|
|
23
|
-
|
package/src/lib/find.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
function find ( dependencies, me ) {
|
|
2
|
-
// * Find if string exists in value attribute name.
|
|
3
|
-
let
|
|
4
|
-
searchDefault = 'root'
|
|
5
|
-
, deepDefault = 9999
|
|
6
|
-
, deepMax
|
|
7
|
-
, keys = Object.keys ( me.value )
|
|
8
|
-
, { help, deep, search, walk } = dependencies
|
|
9
|
-
, longKeys = help.toBreadcrumbKeys ( keys, me.structure )
|
|
10
|
-
;
|
|
11
|
-
|
|
12
|
-
search = search || searchDefault
|
|
13
|
-
deep = (deep == null) ? deepDefault : deep
|
|
14
|
-
deep = deep + 1 // because we add default wrapper 'root'
|
|
15
|
-
deepMax = search.split('/').length + deep
|
|
16
|
-
|
|
17
|
-
let collection = longKeys
|
|
18
|
-
.filter ( el => el.match (search) )
|
|
19
|
-
.reduce ( (res, el) => {
|
|
20
|
-
let
|
|
21
|
-
index = longKeys.indexOf(el)
|
|
22
|
-
, elDeep = el.split('/').length
|
|
23
|
-
;
|
|
24
|
-
if ( elDeep <= deepMax ) res.push(keys[index])
|
|
25
|
-
return res
|
|
26
|
-
},[] )
|
|
27
|
-
me._select.value = help.updateSelection ( me._select.value, collection )
|
|
28
|
-
me._select.structure = walk ({ data : me.structure })
|
|
29
|
-
return me
|
|
30
|
-
} // find func.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export default find
|
|
35
|
-
|
|
36
|
-
|
package/src/lib/folder.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
function folder ( dependencies, me ) {
|
|
2
|
-
const { help, prop, walk, where } = dependencies;
|
|
3
|
-
let
|
|
4
|
-
usedNumbers = []
|
|
5
|
-
, selectedKeys = []
|
|
6
|
-
, result = []
|
|
7
|
-
;
|
|
8
|
-
if ( prop == 'root' ) usedNumbers.push ( 0 )
|
|
9
|
-
me.structure.forEach ( row => { // Find if structures
|
|
10
|
-
row.forEach ( (item,i) => {
|
|
11
|
-
if ( i > 1 ) {
|
|
12
|
-
let [id, name] = item;
|
|
13
|
-
if ( name==prop ) usedNumbers.push(id)
|
|
14
|
-
}
|
|
15
|
-
})})
|
|
16
|
-
|
|
17
|
-
selectedKeys = usedNumbers.reduce ( (res,number) => {
|
|
18
|
-
for (let key in me.value ) {
|
|
19
|
-
let splited = key.split('/');
|
|
20
|
-
if ( splited[1] == number ) res.push ( key )
|
|
21
|
-
}
|
|
22
|
-
return res
|
|
23
|
-
},[])
|
|
24
|
-
if ( where ) { // TODO: Still not tested. May be 'where' should receive (key,value)
|
|
25
|
-
result = usedNumbers.reduce ( (res, number) => {
|
|
26
|
-
let [localObject, localKeysSelection] = help.filterObject ( number, selectedKeys, me.value )
|
|
27
|
-
let success = where ( localObject )
|
|
28
|
-
if ( success ) res.push ( ...localKeysSelection )
|
|
29
|
-
return res
|
|
30
|
-
},[])
|
|
31
|
-
} // if where
|
|
32
|
-
else result = selectedKeys
|
|
33
|
-
me._select.value = help.updateSelection ( me._select.value, result )
|
|
34
|
-
me._select.structure = walk ({ data:me.structure })
|
|
35
|
-
return me
|
|
36
|
-
} // folder func.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export default folder
|
|
41
|
-
|
|
42
|
-
|
package/src/lib/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import find from './find.js'
|
|
4
|
-
import parent from './parent.js'
|
|
5
|
-
import block from './block.js'
|
|
6
|
-
import deep from './deep.js'
|
|
7
|
-
import folder from './folder.js'
|
|
8
|
-
import modify from './modify.js'
|
|
9
|
-
import transform from './transform.js'
|
|
10
|
-
import attach from './attach.js'
|
|
11
|
-
import combine from './combine.js'
|
|
12
|
-
import assemble from './assemble.js'
|
|
13
|
-
import purify from './purify.js'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const dtlib = {
|
|
18
|
-
|
|
19
|
-
loadLong ( dependencies, flatData ) {
|
|
20
|
-
let { structure, value } = flatData;
|
|
21
|
-
return dtlib._loadData ( dependencies, structure, value )
|
|
22
|
-
} // loadLong func.
|
|
23
|
-
|
|
24
|
-
, loadShort ( dependencies, flatData ) {
|
|
25
|
-
let [structure, value] = flatData;
|
|
26
|
-
return dtlib._loadData ( dependencies, structure, value )
|
|
27
|
-
} // loadShort func.
|
|
28
|
-
|
|
29
|
-
, _loadData ( dependencies, structure, value ) {
|
|
30
|
-
const { simpleDT, walk } = dependencies;
|
|
31
|
-
let res = simpleDT ();
|
|
32
|
-
res.structure = walk ({ data : structure })
|
|
33
|
-
for ( const k in value ) {
|
|
34
|
-
res.value[k] = value[k]
|
|
35
|
-
}
|
|
36
|
-
return res
|
|
37
|
-
} // loadData
|
|
38
|
-
|
|
39
|
-
, modify
|
|
40
|
-
, find
|
|
41
|
-
, parent
|
|
42
|
-
, folder
|
|
43
|
-
, deep
|
|
44
|
-
, block
|
|
45
|
-
, transform
|
|
46
|
-
, attach
|
|
47
|
-
, combine
|
|
48
|
-
, assemble
|
|
49
|
-
, purify
|
|
50
|
-
} // dtlib
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export default dtlib
|
|
55
|
-
|
|
56
|
-
|
package/src/lib/modify.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
function modify ( dependencies, main, addData ) {
|
|
2
|
-
// *** Modify add | update | overwrite | insert | append | prepend | combine
|
|
3
|
-
const
|
|
4
|
-
{ action, convert, modifier, walk } = dependencies
|
|
5
|
-
, mainData = convert.to ( 'midFlat', dependencies, [main.structure, main.value])
|
|
6
|
-
, update = convert.to ( 'midFlat', dependencies, [addData.structure, addData.value] )
|
|
7
|
-
;
|
|
8
|
-
let result;
|
|
9
|
-
main._error = main._error.concat ( addData._error )
|
|
10
|
-
result = modifier[action] ( mainData, update )
|
|
11
|
-
|
|
12
|
-
let [structure, value ] = convert.from ( 'midFlat').toFlat ( dependencies, result )
|
|
13
|
-
main.structure = walk ({ data : structure })
|
|
14
|
-
main.value = value
|
|
15
|
-
return main
|
|
16
|
-
} // modify func.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export default modify
|
|
21
|
-
|
|
22
|
-
|
package/src/lib/parent.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
function parent ( dependencies, me ) {
|
|
2
|
-
const { help, prop, walk, where } = dependencies;
|
|
3
|
-
let
|
|
4
|
-
usedNumbers = []
|
|
5
|
-
, selectedKeys = []
|
|
6
|
-
, result
|
|
7
|
-
;
|
|
8
|
-
for (let key in me.value ) { // Collect used parent object(ids) from value
|
|
9
|
-
let splited = key.split('/');
|
|
10
|
-
if ( splited[2] == prop ) usedNumbers.push ( splited[1] )
|
|
11
|
-
}
|
|
12
|
-
function findUsedNumbers ({ value:obj, breadcrumbs }) {
|
|
13
|
-
if ( breadcrumbs === 'root' ) return obj // Ignore top object
|
|
14
|
-
let isRow = typeof obj[0] == 'string'; // Ignore row objects
|
|
15
|
-
if ( isRow ) return obj
|
|
16
|
-
let [ location, name ] = obj; // Here are only property descriptions
|
|
17
|
-
if ( name === prop ) usedNumbers.push ( location )
|
|
18
|
-
return null
|
|
19
|
-
}
|
|
20
|
-
walk ({
|
|
21
|
-
data : me.structure,
|
|
22
|
-
objectCallback : findUsedNumbers
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
selectedKeys = usedNumbers.reduce ( (res,location) => { // Collect props of used parent objects
|
|
26
|
-
for (let key in me.value ) {
|
|
27
|
-
let objectID = key.split('/')[1];
|
|
28
|
-
if ( objectID == location ) res.push ( key )
|
|
29
|
-
}
|
|
30
|
-
return res
|
|
31
|
-
},[] )
|
|
32
|
-
|
|
33
|
-
if ( where ) { // Apply where fn if is defined
|
|
34
|
-
result = usedNumbers.reduce ( (res, number) => {
|
|
35
|
-
let [localObject, localKeysSelection] = help.filterObject ( number, selectedKeys, me.value )
|
|
36
|
-
let success = where ( localObject )
|
|
37
|
-
if ( success ) res.push ( ...localKeysSelection )
|
|
38
|
-
return res
|
|
39
|
-
},[])
|
|
40
|
-
} // if where
|
|
41
|
-
else result = selectedKeys
|
|
42
|
-
me._select.value = help.updateSelection ( me._select.value, result )
|
|
43
|
-
me._select.structure = walk ({ data : me.structure })
|
|
44
|
-
return me
|
|
45
|
-
} // parent func.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export default parent
|
|
50
|
-
|
|
51
|
-
|
package/src/lib/purify.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
function purify ( dependencies, me ) {
|
|
2
|
-
const
|
|
3
|
-
{ structure, value } = me._select
|
|
4
|
-
, structReverse = structure.reverse ()
|
|
5
|
-
;
|
|
6
|
-
let objectIndexes = value.reduce ( (res,item) => {
|
|
7
|
-
let num = parseInt (item.split ( '/' )[1]);
|
|
8
|
-
if ( !res.includes( num) ) res.push ( num )
|
|
9
|
-
return res
|
|
10
|
-
},[]);
|
|
11
|
-
|
|
12
|
-
me._select.structure = structReverse.reduce ( (res, strObject ) => {
|
|
13
|
-
let
|
|
14
|
-
[ type, item, ...nums ] = strObject
|
|
15
|
-
, ln = strObject.length
|
|
16
|
-
, updated = [ type, item ]
|
|
17
|
-
;
|
|
18
|
-
if ( ln == 2 && !objectIndexes.includes(item) ) return res
|
|
19
|
-
nums.forEach ( x => {
|
|
20
|
-
let id = x[0];
|
|
21
|
-
if ( objectIndexes.includes(id) ) {
|
|
22
|
-
updated.push ( [...x] )
|
|
23
|
-
if ( !objectIndexes.includes(item) ) objectIndexes.push ( item )
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
if ( !objectIndexes.includes(item) ) return res
|
|
27
|
-
res.push ( [...updated] )
|
|
28
|
-
return res
|
|
29
|
-
},[]).reverse ()
|
|
30
|
-
return me
|
|
31
|
-
} // assemble func..
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export default purify
|
|
36
|
-
|
|
37
|
-
|
package/src/lib/transform.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
function transform ( dependencies, [structure, value] ) {
|
|
2
|
-
// *** Transformer for 'flat' object. Reverse object key and values, or get only keys/values
|
|
3
|
-
let
|
|
4
|
-
{ modify, empty } = dependencies
|
|
5
|
-
, keyList = Object.keys ( value )
|
|
6
|
-
, result
|
|
7
|
-
;
|
|
8
|
-
switch ( modify ) {
|
|
9
|
-
case 'reverse':
|
|
10
|
-
result = keyList.reduce ( (res,item) => {
|
|
11
|
-
let
|
|
12
|
-
arr = item.split ( '/' )
|
|
13
|
-
, onlyNumbers = /^[0-9]+$/
|
|
14
|
-
, pureKey = ( arr[2].match(onlyNumbers) ) ? parseInt(arr[2]) : arr[2]
|
|
15
|
-
, val = value[item]
|
|
16
|
-
;
|
|
17
|
-
res[`root/${arr[1]}/${val}`] = pureKey
|
|
18
|
-
return res
|
|
19
|
-
}, {} )
|
|
20
|
-
break
|
|
21
|
-
case 'key':
|
|
22
|
-
case 'keys':
|
|
23
|
-
result = keyList.reduce ( (res,key,i) => {
|
|
24
|
-
let
|
|
25
|
-
arr = key.split ( '/' )
|
|
26
|
-
, k = `root/0/${i}`
|
|
27
|
-
;
|
|
28
|
-
res[k] = arr[2]
|
|
29
|
-
return res
|
|
30
|
-
}, {} )
|
|
31
|
-
structure = [ [ 'array', 0 ]]
|
|
32
|
-
break
|
|
33
|
-
case 'value' :
|
|
34
|
-
case 'values':
|
|
35
|
-
result = keyList.reduce ( (res,k,i) => {
|
|
36
|
-
let
|
|
37
|
-
item = value [k]
|
|
38
|
-
, key = `root/0/${i}`
|
|
39
|
-
;
|
|
40
|
-
res[key] = item
|
|
41
|
-
return res
|
|
42
|
-
}, empty() )
|
|
43
|
-
structure = [ [ 'array', 0 ] ]
|
|
44
|
-
break
|
|
45
|
-
default:
|
|
46
|
-
result = empty ()
|
|
47
|
-
} // switch instructions
|
|
48
|
-
return [structure, result]
|
|
49
|
-
} // transform func.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
export default transform
|
|
54
|
-
|
|
55
|
-
|
package/src/modifiers/add.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
function add ( mainData, update ) {
|
|
2
|
-
for (const updateKey in update ) {
|
|
3
|
-
let selectObject = mainData[updateKey];
|
|
4
|
-
if ( !selectObject ) mainData[updateKey] = { ...update[updateKey] }
|
|
5
|
-
else {
|
|
6
|
-
for (let prop in update[updateKey]) {
|
|
7
|
-
if ( !mainData[updateKey][prop] ) mainData[updateKey][prop] = update[updateKey][prop]
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return mainData
|
|
12
|
-
} // add func.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export default add
|
|
17
|
-
|
|
18
|
-
|
package/src/modifiers/append.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
function append ( mainData, update ) {
|
|
2
|
-
// *** Concatinate values for duplicated props.
|
|
3
|
-
for (const updateKey in update ) {
|
|
4
|
-
if ( mainData[updateKey] ) {
|
|
5
|
-
for (let prop in update[updateKey]) {
|
|
6
|
-
if ( mainData[updateKey][prop] ) mainData[updateKey][prop] += update[updateKey][prop]
|
|
7
|
-
else mainData[updateKey][prop] = update[updateKey][prop]
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return mainData
|
|
12
|
-
} // append func.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export default append
|
|
17
|
-
|
|
18
|
-
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
function combineShallow ( mainData, update ) {
|
|
2
|
-
let
|
|
3
|
-
mainKeys = Object.keys(mainData)
|
|
4
|
-
, updateKeys = Object.keys ( update )
|
|
5
|
-
, allKeys = [...mainKeys]
|
|
6
|
-
, result = {root:{}}
|
|
7
|
-
, extraContent = {}
|
|
8
|
-
;
|
|
9
|
-
|
|
10
|
-
for ( let key of updateKeys ) {
|
|
11
|
-
if ( !allKeys.includes(key) ) allKeys.push ( key )
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let sortedKeys = allKeys.sort ( (a,b) => b.split('/').length - a.split('/').length )
|
|
15
|
-
|
|
16
|
-
let duplicateNames = sortedKeys.reduce ( (res,key) => {
|
|
17
|
-
let
|
|
18
|
-
mainObject = mainData['root']
|
|
19
|
-
, updateObject = update [key]
|
|
20
|
-
, check = key.split('/').pop ()
|
|
21
|
-
, mainKeys = Object.keys ( mainObject )
|
|
22
|
-
;
|
|
23
|
-
|
|
24
|
-
if ( key!= 'root' && mainData[key] ) { // key already has more than one value in mainData. Converted to object
|
|
25
|
-
res.add ( check )
|
|
26
|
-
if ( !extraContent[check] ) extraContent[check] = []
|
|
27
|
-
extraContent[check] = Object.keys ( mainData[key] ).reduce ( (res,k) => {
|
|
28
|
-
res.push ( mainData[key][k] )
|
|
29
|
-
return res
|
|
30
|
-
}, extraContent[check])
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if ( check!='root' && updateObject ) { // key exists as object in updateObject
|
|
34
|
-
res.add ( check )
|
|
35
|
-
if (!extraContent[check]) extraContent[check] = []
|
|
36
|
-
extraContent[check] = Object.keys ( updateObject ).reduce ( (res,k) => {
|
|
37
|
-
res.push ( updateObject[k] )
|
|
38
|
-
return res
|
|
39
|
-
}, extraContent[check])
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
for ( let k in updateObject ) {
|
|
44
|
-
if ( mainData[`root/${k}`] && updateObject[k] ) {
|
|
45
|
-
res.add ( k )
|
|
46
|
-
if ( !extraContent[k] ) extraContent[k] = []
|
|
47
|
-
extraContent[k].push ( updateObject[k] )
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if ( mainObject[k] && updateObject[k]) {
|
|
51
|
-
res.add ( k )
|
|
52
|
-
if ( extraContent[k] ) extraContent[k].push ( updateObject[k] )
|
|
53
|
-
else extraContent [ k ] = [ mainObject[k], updateObject[k]]
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return res
|
|
57
|
-
}, new Set() )
|
|
58
|
-
|
|
59
|
-
mainKeys.forEach ( key => { // Insert mainKeys but ignore duplicates
|
|
60
|
-
let obj = mainData[key];
|
|
61
|
-
result[key] = {}
|
|
62
|
-
for ( let k in obj ) {
|
|
63
|
-
if ( !duplicateNames.has(k) ) result[key][k] = obj[k]
|
|
64
|
-
}
|
|
65
|
-
}) // forEach mainKeys
|
|
66
|
-
|
|
67
|
-
updateKeys.forEach ( key => {
|
|
68
|
-
let
|
|
69
|
-
obj = update[key]
|
|
70
|
-
, updateKeyList = Object.keys ( obj )
|
|
71
|
-
, check = key.split ( '/' ).pop ()
|
|
72
|
-
;
|
|
73
|
-
if ( duplicateNames.has(check) ) return
|
|
74
|
-
updateKeyList.forEach ( k => {
|
|
75
|
-
let testKey = `root/${k}`;
|
|
76
|
-
if ( result[testKey] ) {
|
|
77
|
-
let digitCount = _findDigitKeys ( result[testKey]);
|
|
78
|
-
if ( obj[k] === '_fake$$$' ) return
|
|
79
|
-
result[testKey][digitCount] = obj[k]
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
if ( !duplicateNames.has(k) ) {
|
|
83
|
-
if ( obj[k] === '_fake$$$' ) return
|
|
84
|
-
result[key][k] = obj[k]
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
}) // forEach updateKeys
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
for ( let k in extraContent ) {
|
|
92
|
-
const resKey = `root/${k}`;
|
|
93
|
-
|
|
94
|
-
result[resKey] = extraContent[k].reduce ( (res,item,i) => {
|
|
95
|
-
res[i] = item
|
|
96
|
-
return res
|
|
97
|
-
},{})
|
|
98
|
-
} // for extraContent
|
|
99
|
-
return result
|
|
100
|
-
} // combineShallow func.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
function _findDigitKeys ( obj ) {
|
|
107
|
-
let count = 0;
|
|
108
|
-
for ( let k in obj ) {
|
|
109
|
-
let isDigit = isNaN ( parseInt(k)) ? false : true;
|
|
110
|
-
if ( isDigit ) count++
|
|
111
|
-
} // for obj
|
|
112
|
-
return count
|
|
113
|
-
} // findDigitKeys func.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
export default combineShallow
|
|
118
|
-
|
|
119
|
-
|
package/src/modifiers/flatten.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import combineShallow from './combineShallow.js'
|
|
2
|
-
const separator = ';';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function flatten ( mainData ) {
|
|
7
|
-
|
|
8
|
-
let keyList = Object
|
|
9
|
-
.keys ( mainData )
|
|
10
|
-
.filter ( x => x != 'root' );
|
|
11
|
-
let flatter = keyList.reduce ( (res,k) => {
|
|
12
|
-
let update = { 'root': {...mainData[k]} }
|
|
13
|
-
return combineShallow ( res, update )
|
|
14
|
-
},{ 'root': {...mainData['root']}})
|
|
15
|
-
|
|
16
|
-
let flatterKeyList = Object
|
|
17
|
-
.keys ( flatter )
|
|
18
|
-
.filter ( x => x != 'root' );
|
|
19
|
-
|
|
20
|
-
return flatterKeyList.reduce ( (res,k) => {
|
|
21
|
-
let
|
|
22
|
-
key = k.split ('/')[1]
|
|
23
|
-
, val = ''
|
|
24
|
-
;
|
|
25
|
-
for ( let prop in flatter[k]) {
|
|
26
|
-
if ( val ) val += separator
|
|
27
|
-
val += flatter[k][prop]
|
|
28
|
-
}
|
|
29
|
-
res['root'][key] = val
|
|
30
|
-
return res
|
|
31
|
-
}, {'root':{...flatter['root']}})
|
|
32
|
-
} //flatten func.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export default flatten
|
|
37
|
-
|
|
38
|
-
|