dt-toolbox 7.1.3 → 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 CHANGED
@@ -1,5 +1,23 @@
1
1
  ## Release History
2
2
 
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
+
14
+ ### 7.2.0 (2023-09-18)
15
+ - [x] Convertors recognize HTML DOM nodes. Makes a copy by reference;
16
+ - [x] Convertors recognize functions. Makes a copy by reference;
17
+ - [x] Model 'files' is not possible for functions and DOM nodes, so the value in the result will be string. For functions will be `function:functionName` and for DOM nodes will be `htmlElement:elementName`;
18
+
19
+
20
+
3
21
  ### 7.1.3 (2023-09-14)
4
22
  - [x] Fix: extractList: Negative value is treated as property does not exist and returns null instead of real value;
5
23
 
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.1.3",
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.0.0"
31
+ "@peter.naydenov/walk": "4.2.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "c8": "^8.0.1",
35
- "chai": "^4.3.8",
35
+ "chai": "^4.3.10",
36
36
  "mocha": "^10.2.0"
37
37
  },
38
38
  "c8": {
@@ -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':
@@ -65,7 +70,11 @@ function to ( type, dependencies, inData ) { // convert from flat to 'data-typ
65
70
  return tuples.toType ( inData )
66
71
  case 'files':
67
72
  tups = tuples.toType ( inData );
68
- return tups.map ( ([k,v]) => (( k === 'root' ) ? v : `${k}/${v}`) )
73
+ return tups.map ( ([k,v]) => {
74
+ if ( typeof v === 'function' ) return `${k}/function:${v.name}`
75
+ if ( v?.nodeType ) return `${k}/HtmlElement:${v.tagName? v.tagName.toLowerCase() : 'notSpecified'}`
76
+ return (( k === 'root' ) ? v : `${k}/${v}`)
77
+ })
69
78
  case 'breadcrumb' :
70
79
  case 'breadcrumbs':
71
80
  let current;
@@ -3,26 +3,27 @@
3
3
 
4
4
 
5
5
  function extractList ( dependencies, flatIO, indexFn ) {
6
- return function exportList ( list, options={} ) {
6
+ 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
13
14
  , errorMsg = ''
14
15
  ;
15
-
16
+
16
17
  if ( options ) {
17
18
  if ( !options.as ) {
18
19
  error = true
19
20
  errorMsg = `Options should be an object and property "as" is required`
20
21
  }
21
- if ( !error && !INIT_DATA_TYPES.includes(options.as) ) {
22
+ if ( !error && !asTypes.includes(options.as) ) {
22
23
  error = true
23
- errorMsg = `Invalid option "as" value: ${options.as}. Choose one of: std, standard, ''`
24
+ errorMsg = `Invalid option "as" value: ${options.as}.`
24
25
  }
25
- if ( error ) throw new Error ( `Invalid option "as" value: ${options.as}` )
26
+ if ( error ) throw new Error ( errorMsg )
26
27
  }
27
28
 
28
29
  return list
@@ -34,7 +35,7 @@ return function exportList ( list, options={} ) {
34
35
  .map ( item => {
35
36
  if ( item == null ) return null
36
37
  if ( !(item instanceof Array)) return item
37
- return options ? load(item).model(() => options ) : load(item)
38
+ return load(item).model(() => options )
38
39
  })
39
40
  }} // extractList func.
40
41
 
@@ -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
- , CONVERTOR_NAMES = [ 'standard', 'std', 'midFlat', 'tuple', 'tuples', 'breadcrumb', 'breadcrumbs', 'files', 'file' ]
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 = convert.from(model).toFlat ( dependencies, inData );
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