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.
- package/Changelog.md +7 -12
- package/LICENSE +1 -1
- package/Migration.guide.md +14 -1
- package/README.md +976 -352
- package/README_v.2.x.x.md +0 -1
- package/README_v.4.x.x.md +532 -0
- package/package.json +24 -32
- package/src/convertors/index.js +44 -37
- package/src/convertors/midflat.js +77 -133
- package/src/convertors/standard.js +62 -87
- 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 -690
- package/src/mainLib.js +105 -0
- package/dist/dt-toolbox.min.js +0 -1
- package/dist/index.html +0 -65
- 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 -16
- 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 -37
- 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 -14
- 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 -58
- package/src/lib/modify.js +0 -22
- package/src/lib/parent.js +0 -51
- package/src/lib/purify.js +0 -39
- 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 -39
- 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/webpack.config.js +0 -28
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
function sanitizeFlatKeys ( list ) { // fn(string[]) -> string[]
|
|
2
|
-
// *** Sanitize 'file' and 'breadcrumb' data-type keys. Adds 'root/' and indexes where it is needed
|
|
3
|
-
let keys = list.map ( x => { // Keys should start with 'root/'
|
|
4
|
-
let key = x.split ( '/' )
|
|
5
|
-
if ( key[0] != 'root' ) return [ 'root', ...key].join('/')
|
|
6
|
-
else return key.join ( '/' )
|
|
7
|
-
})
|
|
8
|
-
let
|
|
9
|
-
usedKeys = []
|
|
10
|
-
, duplicatedKeys = new Set()
|
|
11
|
-
;
|
|
12
|
-
keys.forEach ( k => {
|
|
13
|
-
if ( usedKeys.includes(k) ) duplicatedKeys.add(k)
|
|
14
|
-
else usedKeys.push ( k )
|
|
15
|
-
})
|
|
16
|
-
for (const marker of duplicatedKeys ) {
|
|
17
|
-
let counter = 0;
|
|
18
|
-
keys = keys.map ( k => {
|
|
19
|
-
if ( k == marker ) return `${k}/${counter++}`
|
|
20
|
-
else return k
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
return keys
|
|
24
|
-
} // sanitizeFlatKeys func.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
module.exports = sanitizeFlatKeys
|
|
29
|
-
|
|
30
|
-
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
function toBreadcrumbKeys ( keys, structure ) { // (flatKey[], structure ) => breadcrumbKeys[]
|
|
2
|
-
// *** Map convertion of flat keys to breadcrumb keys.
|
|
3
|
-
let containerNames = [ 'root' ];
|
|
4
|
-
structure.forEach ( level => {
|
|
5
|
-
level.forEach ( (obj,i) => { // Find container names
|
|
6
|
-
let
|
|
7
|
-
objectID = level[1]
|
|
8
|
-
, container = containerNames[objectID]
|
|
9
|
-
;
|
|
10
|
-
if ( i > 1 ) containerNames.push ( `${container}/${obj[1]}`)
|
|
11
|
-
})
|
|
12
|
-
})
|
|
13
|
-
return keys.map ( k => {
|
|
14
|
-
let
|
|
15
|
-
splited = k.split ( '/' )
|
|
16
|
-
, containerID = splited [ 1 ]
|
|
17
|
-
, prop = splited [ 2 ]
|
|
18
|
-
, long = containerNames [ containerID ]
|
|
19
|
-
;
|
|
20
|
-
return `${long}/${prop}`
|
|
21
|
-
})
|
|
22
|
-
} // toBreadcrumbKeys func.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
module.exports = toBreadcrumbKeys
|
|
27
|
-
|
|
28
|
-
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
function tuplesToBreadcrumbs ( dependencies, data ) {
|
|
4
|
-
const { walk } = dependencies;
|
|
5
|
-
let result = {};
|
|
6
|
-
|
|
7
|
-
function objectCalls ({ value:obj, breadcrumbs }) {
|
|
8
|
-
if ( breadcrumbs === 'root' ) return obj; // ignore root object
|
|
9
|
-
let [ key, val ] = obj;
|
|
10
|
-
result[key] = val
|
|
11
|
-
return obj
|
|
12
|
-
} // objectCalls func.
|
|
13
|
-
|
|
14
|
-
walk ({
|
|
15
|
-
data,
|
|
16
|
-
objectCallback : objectCalls
|
|
17
|
-
})
|
|
18
|
-
return result
|
|
19
|
-
} // tuplesToBradcrumbs func.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
module.exports = tuplesToBreadcrumbs
|
|
24
|
-
|
|
25
|
-
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const update = require("../modifiers/update")
|
|
2
|
-
|
|
3
|
-
function updateSelection ( [...selection], updates ) {
|
|
4
|
-
updates.forEach ( key => {
|
|
5
|
-
if ( !selection.includes(key) ) selection.push ( key )
|
|
6
|
-
})
|
|
7
|
-
return selection
|
|
8
|
-
} // updateSelection
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
module.exports = updateSelection
|
|
13
|
-
|
|
14
|
-
|
package/src/help/zipObject.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
function zipObject ( keys, values ) { // (string[], string[] ) -> object
|
|
2
|
-
// *** Conect two arrays in a single object
|
|
3
|
-
return keys.reduce ( (res,k,i) => {
|
|
4
|
-
let
|
|
5
|
-
income = values[i]
|
|
6
|
-
, val
|
|
7
|
-
;
|
|
8
|
-
switch ( typeof income ) {
|
|
9
|
-
case 'string' :
|
|
10
|
-
val = Number(income) || income
|
|
11
|
-
break
|
|
12
|
-
default:
|
|
13
|
-
val = income
|
|
14
|
-
}
|
|
15
|
-
res[k] = val
|
|
16
|
-
return res
|
|
17
|
-
}, {} )
|
|
18
|
-
} // zipObject func.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
module.exports = zipObject
|
|
23
|
-
|
|
24
|
-
|
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
|
-
module.exports = 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 ( k in result ) {
|
|
9
|
-
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
|
-
module.exports = 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
|
-
module.exports = 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
|
-
module.exports = 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
|
-
module.exports = 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
|
-
module.exports = 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
|
-
module.exports = folder
|
|
41
|
-
|
|
42
|
-
|
package/src/lib/index.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
find = require ( './find' )
|
|
5
|
-
, parent = require ( './parent' )
|
|
6
|
-
, block = require ( './block' )
|
|
7
|
-
, deep = require ( './deep' )
|
|
8
|
-
, folder = require ( './folder' )
|
|
9
|
-
, modify = require ( './modify' )
|
|
10
|
-
, transform = require ( './transform' )
|
|
11
|
-
, attach = require ( './attach' )
|
|
12
|
-
, combine = require ( './combine' )
|
|
13
|
-
, assemble = require ( './assemble' )
|
|
14
|
-
, purify = require ( './purify' )
|
|
15
|
-
;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const dtlib = {
|
|
20
|
-
|
|
21
|
-
loadLong ( dependencies, flatData ) {
|
|
22
|
-
let { structure, value } = flatData;
|
|
23
|
-
return dtlib._loadData ( dependencies, structure, value )
|
|
24
|
-
} // loadLong func.
|
|
25
|
-
|
|
26
|
-
, loadShort ( dependencies, flatData ) {
|
|
27
|
-
let [structure, value] = flatData;
|
|
28
|
-
return dtlib._loadData ( dependencies, structure, value )
|
|
29
|
-
} // loadShort func.
|
|
30
|
-
|
|
31
|
-
, _loadData ( dependencies, structure, value ) {
|
|
32
|
-
const { simpleDT, walk } = dependencies;
|
|
33
|
-
let res = simpleDT ();
|
|
34
|
-
res.structure = walk ({ data : structure })
|
|
35
|
-
for ( const k in value ) {
|
|
36
|
-
res.value[k] = value[k]
|
|
37
|
-
}
|
|
38
|
-
return res
|
|
39
|
-
} // loadData
|
|
40
|
-
|
|
41
|
-
, modify
|
|
42
|
-
, find
|
|
43
|
-
, parent
|
|
44
|
-
, folder
|
|
45
|
-
, deep
|
|
46
|
-
, block
|
|
47
|
-
, transform
|
|
48
|
-
, attach
|
|
49
|
-
, combine
|
|
50
|
-
, assemble
|
|
51
|
-
, purify
|
|
52
|
-
} // dtlib
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
module.exports = dtlib
|
|
57
|
-
|
|
58
|
-
|
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
|
-
module.exports = 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
|
-
module.exports = parent
|
|
50
|
-
|
|
51
|
-
|
package/src/lib/purify.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const update = require("../modifiers/update");
|
|
2
|
-
|
|
3
|
-
function purify ( dependencies, me ) {
|
|
4
|
-
const
|
|
5
|
-
{ structure, value } = me._select
|
|
6
|
-
, structReverse = structure.reverse ()
|
|
7
|
-
;
|
|
8
|
-
let objectIndexes = value.reduce ( (res,item) => {
|
|
9
|
-
let num = parseInt (item.split ( '/' )[1]);
|
|
10
|
-
if ( !res.includes( num) ) res.push ( num )
|
|
11
|
-
return res
|
|
12
|
-
},[]);
|
|
13
|
-
|
|
14
|
-
me._select.structure = structReverse.reduce ( (res, strObject ) => {
|
|
15
|
-
let
|
|
16
|
-
[ type, item, ...nums ] = strObject
|
|
17
|
-
, ln = strObject.length
|
|
18
|
-
, updated = [ type, item ]
|
|
19
|
-
;
|
|
20
|
-
if ( ln == 2 && !objectIndexes.includes(item) ) return res
|
|
21
|
-
nums.forEach ( x => {
|
|
22
|
-
let id = x[0];
|
|
23
|
-
if ( objectIndexes.includes(id) ) {
|
|
24
|
-
updated.push ( [...x] )
|
|
25
|
-
if ( !objectIndexes.includes(item) ) objectIndexes.push ( item )
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
if ( !objectIndexes.includes(item) ) return res
|
|
29
|
-
res.push ( [...updated] )
|
|
30
|
-
return res
|
|
31
|
-
},[]).reverse ()
|
|
32
|
-
return me
|
|
33
|
-
} // assemble func..
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
module.exports = purify
|
|
38
|
-
|
|
39
|
-
|
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
|
-
module.exports = 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
|
-
module.exports = 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
|
-
module.exports = append
|
|
17
|
-
|
|
18
|
-
|