dt-toolbox 7.3.0 → 7.4.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
@@ -2,6 +2,12 @@
2
2
 
3
3
 
4
4
 
5
+ ### 7.4.0 ( 2023-11-3)
6
+ - [x] Types were added to the project;
7
+
8
+
9
+
10
+
5
11
  ### 7.3.0 ( 2023-10-19 )
6
12
  - [x] Model function recognize a `dt-model` model. Result is equal to result of `export`;
7
13
  - [x] Model function recognize a `dt-object` model. Returns a new dt-object;
package/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ![version](https://img.shields.io/github/package-json/v/peterNaydenov/dt-toolbox)
4
4
  ![license](https://img.shields.io/github/license/peterNaydenov/dt-toolbox)
5
+ ![npm](https://img.shields.io/npm/dt/dt-toolbox)
6
+ ![issues](https://img.shields.io/github/issues/peterNaydenov/dt-toolbox)
7
+ ![language](https://img.shields.io/github/languages/top/peterNaydenov/dt-toolbox)
8
+ ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/peterNaydenov/dt-toolbox)
9
+ ![npm bundle size](https://img.shields.io/bundlephobia/min/dt-toolbox)
10
+
5
11
 
6
12
 
7
13
 
@@ -543,7 +549,7 @@ const storage = dtbox.init ( first ); // first will become a root segment
543
549
  storage.insertSegment ( 'second', second );
544
550
  storage.insertSegment ( 'third', third );
545
551
 
546
- const [ a, b c, firstData, otherData ] = storage.extractList ( ['first', 'second', 'third', 'data', 'secondData' ], { type: 'std' } ));
552
+ const [ a, b c, firstData, otherData ] = storage.extractList ( ['first', 'second', 'third', 'data', 'secondData' ], { as: 'std' } ));
547
553
  // a -> { name: 'first', data: 'first data' }
548
554
  // b -> { name: 'second', data: 'second data' }
549
555
  // c -> { name: 'third', data: 'third data' }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dt-toolbox",
3
3
  "description": "Data manipulation tool",
4
- "version": "7.3.0",
4
+ "version": "7.4.0",
5
5
  "license": "MIT",
6
6
  "author": "Peter Naydenov",
7
7
  "keywords": [
@@ -21,7 +21,7 @@ function flatObject ( dependencies, d ) {
21
21
  , objectAPI = {
22
22
  // I/O Operations
23
23
  insertSegment : insert ( dependencies, flatIO ) // Extends available data with new data segment;
24
- , export : ex ( dependencies, flatIO ) // Returns flat data;
24
+ , export : ex ( dependencies, flatIO ) // Returns a flat data;
25
25
  , copy : copy ( dependencies, flatIO ) // Creates deep copy of original data
26
26
  , model : model ( dependencies, flatIO, flatStore ) // Arrange data according specific data-model. Model should come as a function;
27
27
  , query : query ( dependencies, flatIO, flatStore ) // Request, and evaluate data. Returns a new flat object;
@@ -1,8 +1,9 @@
1
1
  'use strict'
2
2
 
3
-
4
3
  function setupFilter ( flatIO ) {
5
- return ( name, filterFn ) => flatIO.setupFilter ( name, filterFn )
4
+ return function setupFilter ( name, filterFn ) {
5
+ flatIO.setupFilter ( name, filterFn )
6
+ }
6
7
  } // setupFilter func.
7
8
 
8
9
 
package/src/main.js CHANGED
@@ -43,12 +43,16 @@ const { init, load, flating, converting, getWalk } = mainLib;
43
43
 
44
44
 
45
45
 
46
+
47
+
48
+
49
+
46
50
  const dtbox = {
47
- init : init
48
- , load : load
49
- , flat : flating
50
- , convert : converting
51
- , getWalk
51
+ init,
52
+ load,
53
+ flat : flating,
54
+ convert : converting,
55
+ getWalk
52
56
  } // dtbox func.
53
57
 
54
58
 
package/src/mainLib.js CHANGED
@@ -23,6 +23,47 @@ const INIT_DATA_TYPES = [
23
23
 
24
24
 
25
25
 
26
+ /**
27
+ * @typedef {(number|string|boolean)} Primitives
28
+ * @typedef {('std'|'tuples'|'breadcrumbs'|'files'|'midFlat'|'flat'|'dt-model')} DtmodelNames
29
+ * @typedef {(filterName:string,fn:function)=>void} setupFilterFn
30
+ * @typedef {(segmentName:string, segment:DTObject)=>void} insertSegmentFn
31
+ * @typedef {(request:Array<string>,options:{as:DtmodelNames}=) => Array<RequestedModel>} extractListFn;
32
+ * @typedef {(fn:queryFunction, ...args)=>DTObject} QueryFn
33
+ * @typedef {(breadcrumbs:string) => dtLine } IndexFn
34
+ *
35
+ *
36
+ *
37
+ * @typedef {Object} DTObject
38
+ * @property {insertSegmentFn} insertSegment - Extends available data with new data segment;
39
+ * @property {(segmentName:string)=>Dtmodel} export - Returns a dt-model of the data;
40
+ * @property {Function} copy - Creates deep copy of original data segment;
41
+ * @property {Function} model - Arrange data according specific data-model. Model should come as a function;
42
+ * @property {QueryFn} query - Request, and evaluate data. Returns a new flat object;
43
+ * @property {setupFilterFn} setupFilter - Functions should filter content according some criteria. Generated indexes will help for data search in;
44
+ * @property {Function} listSegments - Returns list of segments in flat data;
45
+ * @property {IndexFn} index - Returns dt-line by breadcrumbs;
46
+ * @property {extractListFn} extractList - Extracts list of data segments;
47
+ *
48
+ *
49
+ *
50
+ *
51
+ *
52
+ * @typedef {{0:string,1:(Array<Primitives>|Object<string,Primitives>),2:string,3:string[]}} Dtmodel - dt-model
53
+ * @param Dtmodel[]0 - name of the dt-line;
54
+ * @param Dtmodel[]1 - flat data;
55
+ * @param Dtmodel[]2 - breadcrumbs of the dt-line;
56
+ * @param Dtmodel[]3 - children breadcrumbs(edges);
57
+ *
58
+ *
59
+ *
60
+ * @typedef {Object} Initoptions
61
+ * @description dtbox.init options
62
+ * @property {string} [model='std'] model - data model according library's data models.(Look at the documentation)
63
+ */
64
+
65
+
66
+
26
67
  const mainLib = {
27
68
 
28
69
  dependencies () {
@@ -43,11 +84,19 @@ const mainLib = {
43
84
  }
44
85
  , draft
45
86
  }
46
- } // dependencies func.
87
+ }, // dependencies func.
47
88
 
48
89
 
49
90
 
50
- , init ( inData, options={} ) {
91
+ /**
92
+ * @function init
93
+ * @description Create a dt-object from data source
94
+ * @param {(Array|Object)} inData - data source
95
+ * @param {Object} options - options {}
96
+ * @param {('std'|'tuples'|'breadcrumbs'|'files'|'midFlat'|'flat'|'dt-model')} options.model - model of the data source
97
+ * @returns {DTObject} - dt-object
98
+ */
99
+ init ( inData, options={} ) {
51
100
  let
52
101
  defaultOptions = { model : 'std' }
53
102
  , { model } = Object.assign ( {}, defaultOptions, options )
@@ -61,11 +110,19 @@ const mainLib = {
61
110
  mainLib.load ( inData ) :
62
111
  convert.from ( model ).toFlat ( dependencies, inData );
63
112
  return flatObject ( dependencies, d )
64
- } // init func.
65
-
66
-
67
-
68
- , load ( inData ) {
113
+ }, // init func.
114
+
115
+ /**
116
+ * @function load
117
+ * @description Load data from dt-model
118
+ * @param {{0:string,1:(Array<Primitives>|Object<string,Primitives>),2:string,3:string[]}} inData - dt-model:
119
+ * @param inData[]0 - name of the dt-line;
120
+ * @param inData[]1 - flat data;
121
+ * @param inData[]2 - breadcrumbs of the dt-line;
122
+ * @param inData[]3 - children breadcrumbs(edges);
123
+ * @returns {DTObject} - dt-object
124
+ */
125
+ load ( inData ) {
69
126
  const index = {};
70
127
  inData.forEach ( line => {
71
128
  const [ , ,breadcrumbs ] = line;
@@ -73,11 +130,20 @@ const mainLib = {
73
130
  })
74
131
  const copy = walk ({data: inData });
75
132
  return flatObject ( mainLib.dependencies, [copy, index, inData ] )
76
- } // load func.
133
+ }, // load func.
77
134
 
78
135
 
79
136
 
80
- , flating ( inData, options={} ) {
137
+ /**
138
+ *
139
+ * @function flating
140
+ * @description Create a dt-model from data source
141
+ * @param {(Array|Object)} inData - data source. Object or array.
142
+ * @param {Object} options - options.
143
+ * @param {('std'|'tuples'|'breadcrumbs'|'files'|'midFlat'|'flat'|'dt-model')} options.model - model of the data source
144
+ * @returns {Dtmodel[]} - dt-model
145
+ */
146
+ flating ( inData, options={} ) {
81
147
  let
82
148
  defaultOptions = { model : 'std' }
83
149
  , { model } = Object.assign ( {}, defaultOptions, options )
@@ -85,11 +151,18 @@ const mainLib = {
85
151
  if ( !INIT_DATA_TYPES.includes(model) ) return null
86
152
  let [,,dt] = convert.from ('std').toFlat ( mainLib.dependencies, inData );
87
153
  return dt
88
- } // flating func.
89
-
90
-
91
-
92
- , converting ( inData, options={} ) {
154
+ }, // flating func.
155
+
156
+ /**
157
+ * @function converting
158
+ * @description Convert data from one model to another
159
+ * @param {Array|Object} inData - data source
160
+ * @param {Object} options
161
+ * @param {string} options.model - model of the data source
162
+ * @param {string} options.as - model to be converted to
163
+ * @returns {Array|Object} - converted data
164
+ */
165
+ converting ( inData, options={} ) {
93
166
  let
94
167
  defaultOptions = { model : 'std', as: 'std' }
95
168
  , { model, as } = Object.assign ( {}, defaultOptions, options )
@@ -99,11 +172,16 @@ const mainLib = {
99
172
  let [,,dt] = convert.from ('std').toFlat ( mainLib.dependencies, inData );
100
173
 
101
174
  return convert.to ( as, mainLib.dependencies, dt )
102
- } // flating func.
175
+ }, // flating func.
176
+
103
177
 
104
178
 
105
-
106
- , getWalk : () => walk
179
+ /**
180
+ * @function getWalk
181
+ * @description Extract the 'walk' (@peter.naydenov/walk) dependency from dt-toolbox library
182
+ * @returns {Function} - the 'walk' function
183
+ */
184
+ getWalk : () => walk
107
185
 
108
186
  } // mainLib
109
187