dt-toolbox 6.0.0 → 7.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 +13 -0
- package/Migration.guide.md +51 -2
- package/README.md +60 -41
- package/README_v.6.x.x.md +1158 -0
- package/package.json +3 -3
- package/src/flatData/look.js +12 -5
- package/src/flatObject/index.js +9 -1
- package/src/flatObject/insert.js +16 -6
- package/src/mainLib.js +12 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dt-toolbox",
|
|
3
3
|
"description": "Data manipulation tool",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Peter Naydenov",
|
|
7
7
|
"keywords": [
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"start": "node src/main.js",
|
|
19
19
|
"test": "mocha test",
|
|
20
|
-
"cover"
|
|
20
|
+
"cover": "c8 mocha test"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@peter.naydenov/walk": "4.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"c8": "^
|
|
34
|
+
"c8": "^8.0.1",
|
|
35
35
|
"chai": "^4.3.7",
|
|
36
36
|
"mocha": "^10.2.0"
|
|
37
37
|
},
|
package/src/flatData/look.js
CHANGED
|
@@ -8,7 +8,10 @@ return function look ( fn ) {
|
|
|
8
8
|
const
|
|
9
9
|
[ name, flatData, breadcrumbs, edges ] = line
|
|
10
10
|
, isArray = flatData instanceof Array ? true : false
|
|
11
|
+
, next = () => '$__NEXT__LOOK_'
|
|
12
|
+
, finish = () => '$__FINISH__WITH__THE__LOOKING_'
|
|
11
13
|
;
|
|
14
|
+
let endLooking = false;
|
|
12
15
|
|
|
13
16
|
const links = edges.map ( edge => {
|
|
14
17
|
let child = edge.replace ( `${breadcrumbs}/`, '')
|
|
@@ -19,8 +22,10 @@ return function look ( fn ) {
|
|
|
19
22
|
if ( flatData.length === 0 ) empty([])
|
|
20
23
|
else {
|
|
21
24
|
flatData.every ( (value,key) => {
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
if ( endLooking ) return false // Cancel other iterations
|
|
26
|
+
const callback = fn({ value, key, name, flatData, breadcrumbs, links, next, finish });
|
|
27
|
+
if ( callback === finish() ) endLooking = true
|
|
28
|
+
return ( [ finish(), next() ].includes ( callback )) ? false : true
|
|
24
29
|
})
|
|
25
30
|
}
|
|
26
31
|
}
|
|
@@ -29,14 +34,16 @@ return function look ( fn ) {
|
|
|
29
34
|
if ( test.length === 0 ) empty({})
|
|
30
35
|
else {
|
|
31
36
|
test.every ( ([key, value]) => {
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
if ( endLooking ) return false // Cancel other iterations
|
|
38
|
+
const callback = fn ({ value, key, name, flatData, breadcrumbs, links, next, finish });
|
|
39
|
+
if ( callback === finish() ) endLooking = true
|
|
40
|
+
return ( [ finish(), next()].includes ( callback )) ? false : true
|
|
34
41
|
})
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
}
|
|
38
45
|
function empty ( flatData ) {
|
|
39
|
-
fn ({ value:null, key:null, name, flatData, breadcrumbs, links, empty: true })
|
|
46
|
+
fn ({ value:null, key:null, name, flatData, breadcrumbs, links, empty: true, next, finish })
|
|
40
47
|
} // empty func.
|
|
41
48
|
flatIO.resetScan ()
|
|
42
49
|
})
|
package/src/flatObject/index.js
CHANGED
|
@@ -17,12 +17,20 @@ function flatObject ( dependencies, d ) {
|
|
|
17
17
|
, [ flatIO, flatStore ] = flatData ( dependencies, d )
|
|
18
18
|
, objectAPI = {
|
|
19
19
|
// I/O Operations
|
|
20
|
-
|
|
20
|
+
insertSegment : insert ( dependencies, flatIO ) // Extends available data with new data segment;
|
|
21
21
|
, export : ex ( dependencies, flatIO ) // Returns flat data;
|
|
22
22
|
, copy : copy ( dependencies, flatIO ) // Creates deep copy of original data
|
|
23
23
|
, model : model ( dependencies, flatIO, flatStore ) // Arrange data according specific data-model. Model should come as a function;
|
|
24
24
|
, query : query ( dependencies, flatIO, flatStore ) // Request, and evaluate data. Returns a new flat object;
|
|
25
25
|
, setupFilter : setupFilter ( flatIO ) // Functions should filter content according some criteria. Generated indexes will help for data search in
|
|
26
|
+
, listSegments : () => {
|
|
27
|
+
const ix = Object.keys ( flatIO.getIndexes() );
|
|
28
|
+
return ix.reduce ( (res,item) => {
|
|
29
|
+
if ( item.includes('/') ) return res
|
|
30
|
+
res.push ( item )
|
|
31
|
+
return res
|
|
32
|
+
}, [] )
|
|
33
|
+
}
|
|
26
34
|
, index : n => {
|
|
27
35
|
if ( n == null ) return null
|
|
28
36
|
let r = flatIO.getLine(n)
|
package/src/flatObject/insert.js
CHANGED
|
@@ -2,12 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
function insert ( dependencies, flatIO ) {
|
|
4
4
|
return function insert ( name, inData ) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
const { convert, isDTO, isDTM, walk } = dependencies();
|
|
6
|
+
let d, copy;
|
|
7
|
+
|
|
8
|
+
if ( isDTO(inData) ) {
|
|
9
|
+
d = inData.export ()
|
|
10
|
+
copy = inData.copy ()
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
else if ( isDTM(inData) ) {
|
|
14
|
+
d = walk ({ data : inData })
|
|
15
|
+
copy = walk ({ data : inData })
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
[ copy,, d ] = convert.from ( 'std' ).toFlat ( dependencies, inData )
|
|
19
|
+
console.warn ( 'A non "dt-object" data segment was inserted. Autoconverted to "dt-object".' )
|
|
20
|
+
}
|
|
11
21
|
|
|
12
22
|
const search = new RegExp ( `^root\/` );
|
|
13
23
|
d.forEach ( line => { // Word 'root' should be changed to the argument 'name'.
|
package/src/mainLib.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import walk from '@peter.naydenov/walk'
|
|
6
6
|
|
|
7
|
-
import flatObject from './flatObject/index.js'
|
|
8
|
-
import flatData
|
|
9
|
-
import convert
|
|
7
|
+
import flatObject from './flatObject/index.js' // Flat data api.
|
|
8
|
+
import flatData from './flatData/index.js' // Query data api. Used in model functions
|
|
9
|
+
import convert from './convertors/index.js' // Convertors
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -32,6 +32,15 @@ const mainLib = {
|
|
|
32
32
|
, convert
|
|
33
33
|
, INIT_DATA_TYPES
|
|
34
34
|
, main : () => ({ load : mainLib.load })
|
|
35
|
+
, isDTO : d => typeof d.insertSegment === 'function'
|
|
36
|
+
, isDTM : d => {
|
|
37
|
+
if ( !(d instanceof Array)) return false
|
|
38
|
+
if ( !(d[0] instanceof Array)) return false
|
|
39
|
+
if ( d[0].length !== 4 ) return false
|
|
40
|
+
if ( d[0][0] !== 'root' ) return false
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
,
|
|
35
44
|
}
|
|
36
45
|
} // dependencies func.
|
|
37
46
|
|