@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.
@@ -56,32 +56,43 @@ export function compare( left, right ) {
56
56
  }
57
57
 
58
58
  /**
59
- * Extracts list of terms from provided scalar or non-scalar value.
59
+ * Extracts list of words from provided scalar or non-scalar value.
60
60
  *
61
- * A term is a consecutive sequence of letters and digits. On setting custom
62
- * option for ignoring case, all letters of collected terms are converted to
63
- * lowercase in resulting map.
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 terms from
66
- * @param {number} minSize minimum number of characters in a string to be considered for extracting terms
67
- * @param {number} minTermSize minimum number of characters in extracted terms
68
- * @param {number} maxTermSize maximum number of characters in extracted terms
69
- * @param {boolean} ignoreCase set true to drop case of extracted terms
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 terms into either term's number of occurrences
72
+ * @returns {Object<string,number>} map of extracted words into either words's number of occurrences
72
73
  */
73
- export function terms( value, minSize = 10, minTermSize = 1, maxTermSize = Infinity, ignoreCase = false, strict = true ) {
74
+ export function spread( value, minSize = 10, minWordSize = 3, maxWordSize = Infinity, ignoreCase = true, strict = true ) {
74
75
  const result = {};
75
76
 
76
- for ( const term of generateTerms( value, minSize, ignoreCase, strict ) ) {
77
- if ( term.length >= minTermSize && term.length <= maxTermSize ) {
78
- result[term] = ( result[term] || 0 ) + 1;
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 *generateTerms( source, minSize, ignoreCase, strict ) {
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* generateTerms( sub, minSize, ignoreCase, strict );
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.1.2-alpha.1",
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.3.3",
28
+ "simple-terms": "^0.4.0",
29
29
  "yaml": "^2.1.0"
30
30
  },
31
31
  "devDependencies": {