dt-toolbox 7.2.0 → 7.3.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 +10 -0
- package/README.md +2 -2
- package/package.json +3 -3
- package/src/convertors/index.js +5 -0
- package/src/flatObject/extractList.js +4 -3
- package/src/flatObject/model.js +6 -5
- package/src/mainLib.js +5 -3
package/Changelog.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
## Release History
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
|
|
5
|
+
### 7.3.0 ( 2023-10-19 )
|
|
6
|
+
- [x] Model function recognize a `dt-model` model. Result is equal to result of `export`;
|
|
7
|
+
- [x] Model function recognize a `dt-object` model. Returns a new dt-object;
|
|
8
|
+
- [x] Method `extractList` recognize a `dt-model` and `dt-object` models;
|
|
9
|
+
- [x] Method `init` recognize a `dt-model` model. Result is equal to result of `load`;
|
|
10
|
+
- [x] Update of @peter.naydenov/walk to version 4.2.0;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
4
14
|
### 7.2.0 (2023-09-18)
|
|
5
15
|
- [x] Convertors recognize HTML DOM nodes. Makes a copy by reference;
|
|
6
16
|
- [x] Convertors recognize functions. Makes a copy by reference;
|
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
## Last Updates
|
|
9
|
-
|
|
10
|
-
After version 7.1.x `dt-object` api has a new method `extractList` that helps to extract a multiple segments or properties, defined as a list. Use '**options**'(the second argument) to define a model of extracted data if needed. Reed about `extractList` bellow.
|
|
9
|
+
- After version 7.3.0 extractList options.as can receive a `dt-model` and `dt-object`;
|
|
10
|
+
- After version 7.1.x `dt-object` api has a new method `extractList` that helps to extract a multiple segments or properties, defined as a list. Use '**options**'(the second argument) to define a model of extracted data if needed. Reed about `extractList` bellow.
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dt-toolbox",
|
|
3
3
|
"description": "Data manipulation tool",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.3.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Peter Naydenov",
|
|
7
7
|
"keywords": [
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/PeterNaydenov/dt-toolbox#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@peter.naydenov/walk": "4.
|
|
31
|
+
"@peter.naydenov/walk": "4.2.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"c8": "^8.0.1",
|
|
35
|
-
"chai": "^4.3.
|
|
35
|
+
"chai": "^4.3.10",
|
|
36
36
|
"mocha": "^10.2.0"
|
|
37
37
|
},
|
|
38
38
|
"c8": {
|
package/src/convertors/index.js
CHANGED
|
@@ -50,14 +50,19 @@ function from ( type ) { // convert from something to flat...
|
|
|
50
50
|
function to ( type, dependencies, inData ) { // convert from flat to 'data-type'...
|
|
51
51
|
const
|
|
52
52
|
breadcrumbs = {}
|
|
53
|
+
, { walk } = dependencies ()
|
|
53
54
|
, check = new Set()
|
|
54
55
|
, extend = new Set()
|
|
55
56
|
;
|
|
56
57
|
let tups, count = 0;
|
|
57
58
|
switch ( type ) {
|
|
59
|
+
case 'flat':
|
|
60
|
+
case 'dt-model':
|
|
61
|
+
return walk ({data:inData })
|
|
58
62
|
case 'std' :
|
|
59
63
|
case 'standard':
|
|
60
64
|
return std.toType ( inData )
|
|
65
|
+
case 'midflat' :
|
|
61
66
|
case 'midFlat' :
|
|
62
67
|
return midFlat.toType ( inData )
|
|
63
68
|
case 'tuple':
|
|
@@ -7,6 +7,7 @@ return function extractList ( list, options ) {
|
|
|
7
7
|
const
|
|
8
8
|
root = indexFn ( 'root' )
|
|
9
9
|
, { main:{load}, INIT_DATA_TYPES } = dependencies ()
|
|
10
|
+
, asTypes = [ ...INIT_DATA_TYPES, 'dt-object' ]
|
|
10
11
|
;
|
|
11
12
|
let
|
|
12
13
|
error = false
|
|
@@ -18,9 +19,9 @@ return function extractList ( list, options ) {
|
|
|
18
19
|
error = true
|
|
19
20
|
errorMsg = `Options should be an object and property "as" is required`
|
|
20
21
|
}
|
|
21
|
-
if ( !error && !
|
|
22
|
+
if ( !error && !asTypes.includes(options.as) ) {
|
|
22
23
|
error = true
|
|
23
|
-
errorMsg = `Invalid option "as" value: ${options.as}
|
|
24
|
+
errorMsg = `Invalid option "as" value: ${options.as}.`
|
|
24
25
|
}
|
|
25
26
|
if ( error ) throw new Error ( errorMsg )
|
|
26
27
|
}
|
|
@@ -34,7 +35,7 @@ return function extractList ( list, options ) {
|
|
|
34
35
|
.map ( item => {
|
|
35
36
|
if ( item == null ) return null
|
|
36
37
|
if ( !(item instanceof Array)) return item
|
|
37
|
-
return
|
|
38
|
+
return load(item).model(() => options )
|
|
38
39
|
})
|
|
39
40
|
}} // extractList func.
|
|
40
41
|
|
package/src/flatObject/model.js
CHANGED
|
@@ -9,7 +9,7 @@ return function model () {
|
|
|
9
9
|
, selectionIx = {}
|
|
10
10
|
;
|
|
11
11
|
const
|
|
12
|
-
{ convert, draft } = dependencies ()
|
|
12
|
+
{ convert, draft, INIT_DATA_TYPES, main:{load} } = dependencies ()
|
|
13
13
|
, draft_API = {
|
|
14
14
|
set : draft.set ( selection, selectionIx ) // Selection: Creates a new row;
|
|
15
15
|
, connect : draft.connect ( selectionIx ) // Selection: Creates an edges among rows;
|
|
@@ -19,18 +19,19 @@ return function model () {
|
|
|
19
19
|
, [ fn, ...args ] = arguments
|
|
20
20
|
, { as } = fn ( {...flatStore,...draft_API}, ...args ) || {}
|
|
21
21
|
, data = ( selection.length === 0 ) ? flatIO.export() : selection
|
|
22
|
-
,
|
|
23
|
-
, hasConvertor = as ? CONVERTOR_NAMES.includes ( as ) : false
|
|
22
|
+
, hasConvertor = as ? INIT_DATA_TYPES.includes ( as ) : false
|
|
24
23
|
;
|
|
25
24
|
|
|
26
25
|
let result;
|
|
26
|
+
if ( as === 'dt-object' ) {
|
|
27
|
+
return load ( data )
|
|
28
|
+
}
|
|
27
29
|
if ( as && !hasConvertor ) {
|
|
28
30
|
console.error ( `Model '${as}' is unknown data-model.` )
|
|
29
31
|
return null
|
|
30
32
|
}
|
|
31
|
-
|
|
32
33
|
if ( as ) result = convert.to ( as, dependencies, data )
|
|
33
|
-
else result = data
|
|
34
|
+
else result = load ( data )
|
|
34
35
|
flatIO.resetScan ()
|
|
35
36
|
return result
|
|
36
37
|
}} // model func.
|
package/src/mainLib.js
CHANGED
|
@@ -16,8 +16,8 @@ const INIT_DATA_TYPES = [
|
|
|
16
16
|
, 'tuple', 'tuples'
|
|
17
17
|
, 'breadcrumb', 'breadcrumbs'
|
|
18
18
|
, 'file', 'files'
|
|
19
|
-
, 'midFlat'
|
|
20
|
-
, 'flat'
|
|
19
|
+
, 'midFlat', 'midflat'
|
|
20
|
+
, 'flat', 'dt-model'
|
|
21
21
|
]
|
|
22
22
|
;
|
|
23
23
|
|
|
@@ -57,7 +57,9 @@ const mainLib = {
|
|
|
57
57
|
console.error ( `Can't understand your data-model: ${model}. Please, find what is possible on https://github.com/PeterNaydenov/dt-toolbox` )
|
|
58
58
|
return null
|
|
59
59
|
}
|
|
60
|
-
const d =
|
|
60
|
+
const d = ['flat', 'dt-model'].includes ( model ) ?
|
|
61
|
+
mainLib.load ( inData ) :
|
|
62
|
+
convert.from ( model ).toFlat ( dependencies, inData );
|
|
61
63
|
return flatObject ( dependencies, d )
|
|
62
64
|
} // init func.
|
|
63
65
|
|