@cepharum/concrete-db 0.1.1 → 0.2.1
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/LICENSE +1 -1
- package/concrete-db.d.ts +72 -2
- package/cure.mjs +39 -33
- package/lib/collector.mjs +32 -36
- package/lib/cure.mjs +1 -29
- package/lib/{default.shape.yml → default.shape.yaml} +2 -0
- package/lib/defaults.mjs +2 -30
- package/lib/generator.mjs +22 -31
- package/lib/helper.mjs +8 -31
- package/lib/index.mjs +0 -28
- package/lib/meta.cjs +0 -28
- package/lib/options.mjs +3 -0
- package/lib/shaper.mjs +740 -132
- package/lib/term-functions.mjs +86 -28
- package/package.json +16 -12
package/lib/term-functions.mjs
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
|
|
3
|
-
*
|
|
4
|
-
* The MIT License (MIT)
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 cepharum GmbH
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
* @author: cepharum
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
1
|
import { ForeignKey } from "./helper.mjs";
|
|
30
2
|
|
|
31
3
|
/**
|
|
@@ -82,3 +54,89 @@ export function icompare( left, right ) {
|
|
|
82
54
|
export function compare( left, right ) {
|
|
83
55
|
return String( left ).localeCompare( String( right ) );
|
|
84
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Extracts list of words from provided scalar or non-scalar value.
|
|
60
|
+
*
|
|
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.
|
|
65
|
+
*
|
|
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
|
|
71
|
+
* @param {boolean} strict set false to have any non-string value converted to string instead of being ignored
|
|
72
|
+
* @param {string} wordPattern provides source of global unicode regexp matching a word to generate
|
|
73
|
+
* @returns {Object<string,number>} map of extracted words into either words's number of occurrences
|
|
74
|
+
*/
|
|
75
|
+
export function spread( value, minSize = 10, minWordSize = 3, maxWordSize = Infinity, ignoreCase = true, strict = true, wordPattern = undefined ) {
|
|
76
|
+
const result = {};
|
|
77
|
+
|
|
78
|
+
for ( const word of generateWords( value, minSize, ignoreCase, strict, wordPattern ) ) {
|
|
79
|
+
if ( word.length >= minWordSize && word.length <= maxWordSize ) {
|
|
80
|
+
result[word] = ( result[word] || 0 ) + 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Generates error with provided message for failing curing process.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} message description of error
|
|
91
|
+
* @returns {Error} generated error
|
|
92
|
+
*/
|
|
93
|
+
export function fail( message ) {
|
|
94
|
+
return new Error( message );
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Recursively iterates over provided source converting all scalar data into
|
|
100
|
+
* string prior to yielding consecutive sequences of letters and digits.
|
|
101
|
+
*
|
|
102
|
+
* @param {any} source data to extract terms from
|
|
103
|
+
* @param {number} minSize minimum number of characters in a string to be considered for extracting terms
|
|
104
|
+
* @param {boolean} ignoreCase set true to drop case of extracted terms
|
|
105
|
+
* @param {boolean} strict set false to have any non-string value converted to string instead of being ignored
|
|
106
|
+
* @param {string} wordPattern provides source of global unicode regexp matching a word to generate
|
|
107
|
+
* @returns {Generator<string|*, void, *>} iterator over flat sequence of terms
|
|
108
|
+
*/
|
|
109
|
+
function *generateWords( source, minSize, ignoreCase, strict, wordPattern = undefined ) {
|
|
110
|
+
let stream;
|
|
111
|
+
|
|
112
|
+
if ( Array.isArray( source ) ) {
|
|
113
|
+
stream = source;
|
|
114
|
+
} else if ( source instanceof Set || source instanceof Map ) {
|
|
115
|
+
stream = source.values();
|
|
116
|
+
} else if ( source && typeof source === "object" ) {
|
|
117
|
+
stream = Object.values( source );
|
|
118
|
+
} else {
|
|
119
|
+
if ( strict && typeof source !== "string" ) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const string = String( source ).trim();
|
|
124
|
+
|
|
125
|
+
if ( string.length < minSize ) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const ptn = wordPattern ? new RegExp( wordPattern, "gu" ) : /[\p{L}\p{N}_][\p{L}\p{N}_-]*/gu;
|
|
130
|
+
let match;
|
|
131
|
+
|
|
132
|
+
while ( ( match = ptn.exec( string ) ) ) {
|
|
133
|
+
yield ignoreCase ? ( match[1] ?? match[0] ).toLocaleLowerCase() : match[1] ?? match[0];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for ( const sub of stream ) {
|
|
140
|
+
yield* generateWords( sub, minSize, ignoreCase, strict, wordPattern );
|
|
141
|
+
}
|
|
142
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cepharum/concrete-db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "a read-only web database generator",
|
|
5
5
|
"main": "lib/collector.mjs",
|
|
6
6
|
"types": "concrete-db.d.ts",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"cure": "node ./cure.mjs",
|
|
12
12
|
"lint": "eslint lib/**/*.{js,mjs,cjs} test/**/*.{js,mjs,cjs} cure.mjs",
|
|
13
|
-
"
|
|
13
|
+
"lint:fix": "eslint --fix lib/**/*.{js,mjs,cjs} test/**/*.{js,mjs,cjs} cure.mjs",
|
|
14
|
+
"test": "c8 mocha --ui=tdd --recursive test/**/*.spec.*",
|
|
14
15
|
"test:getting-started": "node ./test/curing.shell.mjs",
|
|
15
16
|
"docs:dev": "vuepress dev docs",
|
|
16
17
|
"docs:build": "vuepress build docs"
|
|
@@ -19,23 +20,26 @@
|
|
|
19
20
|
"author": "cepharum GmbH",
|
|
20
21
|
"license": "MIT",
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"ajv": "^
|
|
23
|
+
"ajv": "^8.11.0",
|
|
23
24
|
"file-essentials": "^0.1.2",
|
|
24
25
|
"lodash.merge": "^4.6.2",
|
|
25
|
-
"minimist": "^1.2.
|
|
26
|
+
"minimist": "^1.2.6",
|
|
26
27
|
"promise-essentials": "^0.2.0",
|
|
27
|
-
"simple-terms": "^0.
|
|
28
|
-
"yaml": "^1.
|
|
28
|
+
"simple-terms": "^0.4.0",
|
|
29
|
+
"yaml": "^2.1.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"
|
|
32
|
+
"c8": "^7.11.3",
|
|
33
|
+
"eslint": "^8.16.0",
|
|
32
34
|
"eslint-config-cepharum": "^1.0.12",
|
|
33
|
-
"eslint-plugin-promise": "^
|
|
34
|
-
"mocha": "^
|
|
35
|
-
"nyc": "^15.1.0",
|
|
35
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
36
|
+
"mocha": "^10.0.0",
|
|
36
37
|
"should": "^13.2.3",
|
|
37
|
-
"vuepress": "^1.
|
|
38
|
-
"vuepress-plugin-mermaidjs": "^1.
|
|
38
|
+
"vuepress": "^1.9.7",
|
|
39
|
+
"vuepress-plugin-mermaidjs": "^1.9.1"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=10"
|
|
39
43
|
},
|
|
40
44
|
"files": [
|
|
41
45
|
"lib",
|