@cepharum/concrete-db 0.1.2-alpha.1 → 0.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/concrete-db.d.ts +37 -21
- package/cure.mjs +37 -4
- package/lib/collector.mjs +22 -1
- package/lib/cure.mjs +1 -1
- package/lib/default.shape.yaml +2 -0
- package/lib/generator.mjs +22 -3
- package/lib/helper.mjs +2 -0
- package/lib/shaper.mjs +355 -229
- package/lib/term-functions.mjs +27 -16
- package/package.json +2 -2
package/lib/term-functions.mjs
CHANGED
|
@@ -56,32 +56,43 @@ export function compare( left, right ) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* Extracts list of
|
|
59
|
+
* Extracts list of words from provided scalar or non-scalar value.
|
|
60
60
|
*
|
|
61
|
-
* A
|
|
62
|
-
*
|
|
63
|
-
*
|
|
61
|
+
* A word is a consecutive sequence of letters, digits, underscores and dashes
|
|
62
|
+
* though dashes are rejected in a leading position. On setting custom option
|
|
63
|
+
* for ignoring case, all letters of collected words are converted to lowercase
|
|
64
|
+
* in resulting map.
|
|
64
65
|
*
|
|
65
|
-
* @param {any} value value to extract
|
|
66
|
-
* @param {number} minSize minimum number of characters in a string to be considered for extracting
|
|
67
|
-
* @param {number}
|
|
68
|
-
* @param {number}
|
|
69
|
-
* @param {boolean} ignoreCase set true to drop case of extracted
|
|
66
|
+
* @param {any} value value to extract words from
|
|
67
|
+
* @param {number} minSize minimum number of characters in a string to be considered for extracting words
|
|
68
|
+
* @param {number} minWordSize minimum number of characters in extracted words
|
|
69
|
+
* @param {number} maxWordSize maximum number of characters in extracted words
|
|
70
|
+
* @param {boolean} ignoreCase set true to drop case of extracted words
|
|
70
71
|
* @param {boolean} strict set false to have any non-string value converted to string instead of being ignored
|
|
71
|
-
* @returns {Object<string,number>} map of extracted
|
|
72
|
+
* @returns {Object<string,number>} map of extracted words into either words's number of occurrences
|
|
72
73
|
*/
|
|
73
|
-
export function
|
|
74
|
+
export function spread( value, minSize = 10, minWordSize = 3, maxWordSize = Infinity, ignoreCase = true, strict = true ) {
|
|
74
75
|
const result = {};
|
|
75
76
|
|
|
76
|
-
for ( const
|
|
77
|
-
if (
|
|
78
|
-
result[
|
|
77
|
+
for ( const word of generateWords( value, minSize, ignoreCase, strict ) ) {
|
|
78
|
+
if ( word.length >= minWordSize && word.length <= maxWordSize ) {
|
|
79
|
+
result[word] = ( result[word] || 0 ) + 1;
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
return result;
|
|
83
84
|
}
|
|
84
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Generates error with provided message for failing curing process.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} message description of error
|
|
90
|
+
* @returns {Error} generated error
|
|
91
|
+
*/
|
|
92
|
+
export function fail( message ) {
|
|
93
|
+
return new Error( message );
|
|
94
|
+
}
|
|
95
|
+
|
|
85
96
|
|
|
86
97
|
/**
|
|
87
98
|
* Recursively iterates over provided source converting all scalar data into
|
|
@@ -93,7 +104,7 @@ export function terms( value, minSize = 10, minTermSize = 1, maxTermSize = Infin
|
|
|
93
104
|
* @param {boolean} strict set false to have any non-string value converted to string instead of being ignored
|
|
94
105
|
* @returns {Generator<string|*, void, *>} iterator over flat sequence of terms
|
|
95
106
|
*/
|
|
96
|
-
function *
|
|
107
|
+
function *generateWords( source, minSize, ignoreCase, strict ) {
|
|
97
108
|
let stream;
|
|
98
109
|
|
|
99
110
|
if ( Array.isArray( source ) ) {
|
|
@@ -124,6 +135,6 @@ function *generateTerms( source, minSize, ignoreCase, strict ) {
|
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
for ( const sub of stream ) {
|
|
127
|
-
yield*
|
|
138
|
+
yield* generateWords( sub, minSize, ignoreCase, strict );
|
|
128
139
|
}
|
|
129
140
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cepharum/concrete-db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "a read-only web database generator",
|
|
5
5
|
"main": "lib/collector.mjs",
|
|
6
6
|
"types": "concrete-db.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"lodash.merge": "^4.6.2",
|
|
26
26
|
"minimist": "^1.2.6",
|
|
27
27
|
"promise-essentials": "^0.2.0",
|
|
28
|
-
"simple-terms": "^0.
|
|
28
|
+
"simple-terms": "^0.4.0",
|
|
29
29
|
"yaml": "^2.1.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|