dt-toolbox 4.0.2 → 4.0.3

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 CHANGED
@@ -1,6 +1,12 @@
1
1
  ## Release History
2
2
 
3
3
 
4
+
5
+ ### 4.0.3 (2022-02-23)
6
+ - [x] Fix: Initialize with breadcrumbs is not working at all;
7
+
8
+
9
+
4
10
  ### 4.0.2 (2022-02-21)
5
11
  - [x] Fix: Methods 'keep' and 'remove' received `flat keys` instead of `breadcrumbs keys`. If need a `flat key`, its still available as third argument.
6
12
  ```js
@@ -8,12 +14,14 @@
8
14
  // ... set your filter here...
9
15
  })
10
16
  ```
17
+ - [ ] Bug: Initialize with breadcrumbs is not working at all;
11
18
 
12
19
 
13
20
 
14
21
  ### 4.0.1 (2021-04-08)
15
22
  - [x] Fix: Methods "add/update/overwrite/combine/append/prepend" expect by default data-type 'standard'. Should be a 'flat' data-type. This update is coming as major release because may require some changes. Everything else is according documentation for version 3.x.x;
16
- - [] Bug: Methods 'keep' and 'remove' received `flat keys` instead of `breadcrumbs keys`
23
+ - [ ] Bug: Methods 'keep' and 'remove' received `flat keys` instead of `breadcrumbs keys`
24
+ - [ ] Bug: Initialize with breadcrumbs is not working at all;
17
25
 
18
26
 
19
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-toolbox",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Data manipulation tool",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
@@ -35,55 +35,53 @@ function toFlat ( dependencies, rawValue ) {
35
35
  .keys ( rawValue )
36
36
  .map ( x => x.split('/') )
37
37
  .sort ( (a,b) => b.length - a.length )
38
- , maxLength = keyList[0].length
39
- , buffer = [] // List contains items(generators). Item contain props organized by specific deepness
40
- , objectList = [] // Array of objects. Object looks like this - { key: propNames[]}
41
- , deepList = []
42
- , rootObjectNames = [] // Collection of all property names for objects. Evaluate 'root' object type on this.
43
- ;
44
- for (let i=maxLength-1; i >= 0; i--) { // separate keys on deep levels
45
- let selectedKeys = keyList.filter ( k => k.length == i+1 );
46
- buffer.push ( help.generateObject(selectedKeys) )
47
- }
48
- objectList = buffer.map ( x => x.next().value ).reverse () // organize keys as objects in right order
49
- deepList = objectList.map ( (item,i) => help.generateList (i, item) )
50
-
51
- for ( let list of deepList ) {
52
- for (let [id, objName, val] of list ) { // example: [ 0, 'root', [ 'name', 'age'] ]
53
- let
54
- splitName = objName.split ( '/' )
55
- , splitSize = splitName.length
56
- , shortObjName = splitName[splitSize-1]
57
- , structSize = structure.length
58
- , emptyObjects = id - structSize-1
59
- , EMPTY_OBJECTS = emptyObjects > 0
60
- , type = help.hasNumbers ( val ) ? 'array' : 'object'
61
- ;
62
- if ( EMPTY_OBJECTS ) {
63
- for ( let i=0; i <= emptyObjects; i++ ) {
64
- structure.push ( [type, i ])
65
- if ( i > 0 ) {
66
- structure[i-1].push ([i, splitName[i]])
67
- rootObjectNames.push ( splitName[i] )
68
- }
69
- }
70
- structSize = structure.length
71
- }
72
- else {
73
- structure.push ([type, structSize])
74
- structSize = structure.length
75
- if ( id > 1 ) {
76
- structure[id-2].push ([structSize-1, shortObjName])
77
- rootObjectNames.push ( shortObjName )
78
- }
79
- }
80
- type = help.hasNumbers ( rootObjectNames ) ? 'array' : 'object' // Evaluate 'root' object type
81
- structure[0][0] = type
82
- for (let prop of val) {
83
- value [`root/${structSize-1}/${prop}`] = rawValue[`${objName}/${prop}`]
84
- }
85
- }} // for deepList
86
- return [ structure, value ]
38
+ , tProps = {} // { objectLocation<string> : childObjectNames<set> }
39
+ , structRaw = [] // objectLocation strings
40
+ , propDone = []
41
+ ;
42
+ keyList.forEach ( (keyArr) => { // Setup our temp structures: tProps and structRaw
43
+ keyArr.forEach ( (k,i) => {
44
+ let parent = keyArr.slice( 0, i ).join ( '/' );
45
+ if ( !parent ) return
46
+ if ( !tProps[parent] ) {
47
+ tProps[parent] = new Set()
48
+ structRaw.push ( parent )
49
+ }
50
+ tProps[parent].add ( k )
51
+ })
52
+ })
53
+ structRaw.forEach ( (el,i) => { // Build the structure rows
54
+ let elChildren = false;
55
+ if ( !structure[i] ) structure[i] = [ 'object', i ]
56
+ if ( propDone[i] ) el = propDone[i]
57
+ elChildren = Array.from ( tProps[el] )
58
+ elChildren.forEach ( name => { // Setup connections between object
59
+ let test = tProps[`${el}/${name}`];
60
+ if ( !test ) return
61
+ let
62
+ childProps = Array.from (test)
63
+ , type = help.hasNumbers ( childProps ) ? 'array' : 'object'
64
+ , lastIndex = structure.length
65
+ ;
66
+ propDone[lastIndex] = `${el}/${name}`
67
+ structure.push ([type, lastIndex])
68
+ structure[i].push ( [lastIndex, name])
69
+ })
70
+ })
71
+
72
+ keyList.forEach ( k => { // Create flat keys and write values
73
+ let
74
+ name = k.pop()
75
+ , keySearch = k.join ( '/' )
76
+ , objNumber = null
77
+ , theKey = ''
78
+ ;
79
+ objNumber = propDone.indexOf ( keySearch )
80
+ if ( objNumber < 0 ) objNumber = structRaw.indexOf(keySearch)
81
+ theKey = `root/${objNumber}/${name}`
82
+ value[theKey] = rawValue[`${keySearch}/${name}`]
83
+ })
84
+ return [ structure, value ]
87
85
  } // toFlat func.
88
86
 
89
87