dt-toolbox 7.1.2 → 7.2.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,13 +1,28 @@
1
1
  ## Release History
2
2
 
3
+
4
+ ### 7.2.0 (2023-09-18)
5
+ - [x] Convertors recognize HTML DOM nodes. Makes a copy by reference;
6
+ - [x] Convertors recognize functions. Makes a copy by reference;
7
+ - [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`;
8
+
9
+
10
+
11
+ ### 7.1.3 (2023-09-14)
12
+ - [x] Fix: extractList: Negative value is treated as property does not exist and returns null instead of real value;
13
+
14
+
15
+
3
16
  ### 7.1.2 (2023-09-12)
4
17
  - [x] Fix: Dt-Storage method 'from' is not filtering the list if requested 'breadcrumbs' does not exist;
18
+ - [ ] Bug: extractList: Negative value is treated as property does not exist and returns null instead of real value;
5
19
 
6
20
 
7
21
 
8
22
  ### 7.1.1 (2023-09-05 )
9
23
  - [x] Fix: Multiple queries in same programming scope;
10
24
  - [ ] Bug: Dt-Storage method 'from' is not filtering the list if requested 'breadcrumbs' does not exist;
25
+ - [ ] Bug: extractList: Negative value is treated as property does not exist and returns null instead of real value;
11
26
 
12
27
 
13
28
 
package/README.md CHANGED
@@ -13,7 +13,8 @@ After version 7.1.x `dt-object` api has a new method `extractList` that helps to
13
13
 
14
14
  ## Description
15
15
 
16
- DT-Toolbox is created to simplify the work with deep nested javascript objects. The library was created as an immutable data-storage(dt-object), internally based on data-model called `DT-model`.
16
+ DT-Toolbox is a tool, created to simplify the work with deep nested javascript objects.
17
+ The library creates an immutable data-storage(dt-object). Storage data representation is based on data-model called `DT-model`.
17
18
 
18
19
  ## What is DT-model?
19
20
  It's an internal 'dt-object' data description. Data is an array of lines where each line has 4 components:
@@ -26,12 +27,21 @@ It's an internal 'dt-object' data description. Data is an array of lines where e
26
27
  // Where ->
27
28
  // name: string. Name of the dt-line;
28
29
  // flatData: object or array of primitive types;
29
- // breadcrumbs: string. Bredcrumbs description of the current dt-line;
30
- // edges: string[]. List of breadcrumbs of the related dt-lines;
30
+ // breadcrumbs: string. Bredcrumbs description(identifier) of the current dt-line;
31
+ // edges: string[]. List of breadcrumbs of the related dt-lines(children);
31
32
  ```
32
33
 
33
34
  This data-description is easy to read, saved, or transfered.
34
35
 
36
+ DT-model can become a storage for multiple data blocks - `data-segments`. Each data-segment can be extracted but also can be queried and modeled together with other data-segments in a way to create a new dt-object.
37
+
38
+ Concept `state` - A specific shape of DT-model where all primitive states are stored in 'root' object and the other states as separated data-segments. Root data-segment is a flat object (single row without edges).
39
+
40
+ There is a library [@peter.naydenov/dt-queries](https://github.com/PeterNaydenov/dt-queries) that contains query functions that can be useful with data manipulation:
41
+ - splitSegments: Splits a solid data into multiple data-segments;
42
+ - joinSegments : Consolidate multiple data-segments in a single solid data;
43
+ - updateState : Updates the state with new data. Takes only declared data-segments and root data properties;
44
+
35
45
 
36
46
  ## Installation
37
47
  Install for node.js projects by writing in your terminal:
@@ -52,7 +62,7 @@ import dtbox from 'dt-toolbox'
52
62
  Use Dt-toolbox methods(init and load) to create a `dt-object`.
53
63
 
54
64
  DT-object:
55
- - Provides multiple insertion of data segments. Data from each insertion stays differentiated;
65
+ - Provides multiple insertion of data-segments. Data from each insertion stays differentiated;
56
66
  - Has prebuilded filters for fast search of data;
57
67
  - Can create and register a customized filters for fast search of data;
58
68
  - Can apply `query functions` to find, extract and reshape the data;
@@ -1174,9 +1184,9 @@ console.log ( result )
1174
1184
 
1175
1185
 
1176
1186
  ## External Links
1187
+ - [DT-Queries. Some useful query functions for DT-Toolbox](https://github.com/PeterNaydenov/dt-queries)
1177
1188
  - [History of changes](https://github.com/PeterNaydenov/dt-toolbox/blob/master/Changelog.md)
1178
1189
  - [Migration guide](https://github.com/PeterNaydenov/dt-toolbox/blob/master/Migration.guide.md)
1179
- - [DT-Queries. Some useful query functions for DT-Toolbox](https://github.com/PeterNaydenov/dt-queries)
1180
1190
  - [Documentation v.4.x.x](https://github.com/PeterNaydenov/dt-toolbox/blob/master/README_v.4.x.x.md)
1181
1191
  - [Documentation v.2.x.x](https://github.com/PeterNaydenov/dt-toolbox/blob/master/README_v.2.x.x.md)
1182
1192
 
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.2",
4
+ "version": "7.2.0",
5
5
  "license": "MIT",
6
6
  "author": "Peter Naydenov",
7
7
  "keywords": [
@@ -28,7 +28,7 @@
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.1.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "c8": "^8.0.1",
@@ -65,7 +65,11 @@ function to ( type, dependencies, inData ) { // convert from flat to 'data-typ
65
65
  return tuples.toType ( inData )
66
66
  case 'files':
67
67
  tups = tuples.toType ( inData );
68
- return tups.map ( ([k,v]) => (( k === 'root' ) ? v : `${k}/${v}`) )
68
+ return tups.map ( ([k,v]) => {
69
+ if ( typeof v === 'function' ) return `${k}/function:${v.name}`
70
+ if ( v?.nodeType ) return `${k}/HtmlElement:${v.tagName? v.tagName.toLowerCase() : 'notSpecified'}`
71
+ return (( k === 'root' ) ? v : `${k}/${v}`)
72
+ })
69
73
  case 'breadcrumb' :
70
74
  case 'breadcrumbs':
71
75
  let current;
@@ -3,33 +3,32 @@
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
- , { main:{load} } = dependencies ()
10
- , possibleAs = ['standard', 'std', 'midFlat', 'tuple', 'tuples', 'breadcrumb', 'breadcrumbs', 'files', 'file' ]
9
+ , { main:{load}, INIT_DATA_TYPES } = dependencies ()
11
10
  ;
12
11
  let
13
12
  error = false
14
13
  , errorMsg = ''
15
14
  ;
16
-
15
+
17
16
  if ( options ) {
18
17
  if ( !options.as ) {
19
18
  error = true
20
19
  errorMsg = `Options should be an object and property "as" is required`
21
20
  }
22
- if ( !error && !possibleAs.includes(options.as) ) {
21
+ if ( !error && !INIT_DATA_TYPES.includes(options.as) ) {
23
22
  error = true
24
23
  errorMsg = `Invalid option "as" value: ${options.as}. Choose one of: std, standard, ''`
25
24
  }
26
- if ( error ) throw new Error ( `Invalid option "as" value: ${options.as}` )
25
+ if ( error ) throw new Error ( errorMsg )
27
26
  }
28
27
 
29
28
  return list
30
29
  .map ( name => {
31
30
  let lines = flatIO.export ( name );
32
- if ( lines.length === 0 ) return root[1][name] ? root[1][name] : null
31
+ if ( lines.length === 0 ) return root[1].hasOwnProperty(name) ? root[1][name] : null
33
32
  else return lines
34
33
  })
35
34
  .map ( item => {
@@ -38,9 +38,9 @@ function flatObject ( dependencies, d ) {
38
38
  }
39
39
  ;
40
40
 
41
- function index (n) {
41
+ function index ( n ) {
42
42
  if ( n == null ) return null
43
- let r = flatIO.getLine(n)
43
+ let r = flatIO.getLine ( n )
44
44
  if ( r ) {
45
45
  let [ name, d, breadcrumbs, links ] = r;
46
46
  let copy;