cmpstr 2.0.2 → 2.0.3

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/README.md CHANGED
@@ -84,7 +84,7 @@ Clears the normalization cache.
84
84
 
85
85
  #### `listAlgo( [ loadedOnly = false ] )`
86
86
 
87
- List all registered similarity algorithms.
87
+ List all registered or loaded similarity algorithms.
88
88
 
89
89
  Parameters:
90
90
 
@@ -145,9 +145,13 @@ Parameters:
145
145
 
146
146
  ### Filters
147
147
 
148
- #### `listFilter()`
148
+ #### `listFilter( [ activeOnly = false ] )`
149
149
 
150
- List all added filters.
150
+ List all added or active filter names.
151
+
152
+ Parameters:
153
+
154
+ `<Boolean> activeOnly` – it true, only names of active filters are returned
151
155
 
152
156
  #### `addFilter( name, callback [, priority = 10 ] )`
153
157
 
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "url" : "https://komed3.de"
8
8
  },
9
9
  "homepage": "https://github.com/komed3/cmpstr#readme",
10
- "version": "2.0.2",
10
+ "version": "2.0.3",
11
11
  "main": "src/index.js",
12
12
  "types": "src/index.d.ts",
13
13
  "license": "MIT",
package/src/CmpStr.d.ts CHANGED
@@ -19,7 +19,7 @@ export declare class CmpStr {
19
19
 
20
20
  getStr () : string;
21
21
 
22
- listAlgo ( loadedOnly?: boolean ) : string[];
22
+ listAlgo ( loadedOnly?: boolean = false ) : string[];
23
23
 
24
24
  isAlgo ( algo: string ) : boolean;
25
25
 
@@ -33,11 +33,11 @@ export declare class CmpStr {
33
33
 
34
34
  rmvAlgo( algo: string ) : boolean;
35
35
 
36
- listFilter () : string[];
36
+ listFilter ( activeOnly?: boolean = false ) : string[];
37
37
 
38
38
  addFilter ( name: string, callback: (
39
39
  str: string
40
- ) => string, priority?: number ) : boolean;
40
+ ) => string, priority?: number = 10 ) : boolean;
41
41
 
42
42
  rmvFilter ( name: string ) : boolean;
43
43
 
package/src/CmpStr.js CHANGED
@@ -233,7 +233,7 @@ module.exports = class CmpStr {
233
233
  */
234
234
 
235
235
  /**
236
- * list all registered similarity algorithms
236
+ * list all registered or loaded similarity algorithms
237
237
  *
238
238
  * @param {Boolean} [loadedOnly=false] it true, only loaded algorithm names are returned
239
239
  * @returns {String[]} array of algorithm names
@@ -437,13 +437,18 @@ module.exports = class CmpStr {
437
437
  */
438
438
 
439
439
  /**
440
- * list all added filters
440
+ * list all added or artice filter names
441
441
  *
442
+ * @param {Boolean} [activeOnly=false] if true, only names of active filters are returned
442
443
  * @returns {String[]} array of filter names
443
444
  */
444
- listFilter () {
445
+ listFilter ( activeOnly = false ) {
445
446
 
446
- return [ ...this.#filter.keys() ];
447
+ return activeOnly
448
+ ? Array.from( this.#filter.entries() )
449
+ .filter( ( [ _, filter ] ) => filter.active )
450
+ .map( ( [ name ] ) => name )
451
+ : [ ...this.#filter.keys() ];
447
452
 
448
453
  };
449
454
 
@@ -2,7 +2,7 @@ import { CmpStr, Config, BatchResult } from './CmpStr';
2
2
 
3
3
  export declare class CmpStrAsync extends CmpStr {
4
4
 
5
- normalizeAsync ( input: string|string[], flags?: string ) : string|string[];
5
+ normalizeAsync ( input: string|string[], flags?: string ) : Promise<string|string[]>;
6
6
 
7
7
  compareAsync ( algo: string, a: string, b: string, config?: Config ) : Promise<number | any>;
8
8
 
@@ -16,4 +16,4 @@ export declare class CmpStrAsync extends CmpStr {
16
16
 
17
17
  similarityMatrixAsync ( algo: string, arr: string[], config?: Config ) : Promise<number[][]>;
18
18
 
19
- }
19
+ }
@@ -41,7 +41,6 @@ module.exports = class CmpStrAsync extends CmpStr {
41
41
 
42
42
  /**
43
43
  * generic async wrapper for methods
44
- * @async
45
44
  *
46
45
  * @private
47
46
  * @param {Function} method method to call
@@ -96,7 +95,6 @@ module.exports = class CmpStrAsync extends CmpStr {
96
95
 
97
96
  /**
98
97
  * compares two string a and b using the passed algorithm
99
- * @async
100
98
  *
101
99
  * @param {String} algo name of the algorithm
102
100
  * @param {String} a string a
@@ -116,7 +114,6 @@ module.exports = class CmpStrAsync extends CmpStr {
116
114
  /**
117
115
  * tests the similarity between the base string and a target string
118
116
  * using the current algorithm
119
- * @async
120
117
  *
121
118
  * @param {String} str target string
122
119
  * @param {Object} [config={}] config (flags, args)
@@ -133,7 +130,6 @@ module.exports = class CmpStrAsync extends CmpStr {
133
130
 
134
131
  /**
135
132
  * tests the similarity of multiple strings against the base string
136
- * @async
137
133
  *
138
134
  * @param {String[]} arr array of strings
139
135
  * @param {Object} [config={}] config (flags, args)
@@ -151,13 +147,12 @@ module.exports = class CmpStrAsync extends CmpStr {
151
147
  /**
152
148
  * finds strings in an array that exceed a similarity threshold
153
149
  * returns the array sorted by highest similarity
154
- * @async
155
150
  *
156
151
  * @param {String[]} arr array of strings
157
152
  * @param {Object} [config={}] config (flags, threshold, args)
158
153
  * @returns {Promise} Promise resolving an array of objects, sorted by highest similarity
159
154
  */
160
- async matchAsync ( arr, config = {} ) {
155
+ matchAsync ( arr, config = {} ) {
161
156
 
162
157
  return this.#asyncWrapper(
163
158
  this.match,
@@ -168,13 +163,12 @@ module.exports = class CmpStrAsync extends CmpStr {
168
163
 
169
164
  /**
170
165
  * finds the closest matching string from an array
171
- * @async
172
166
  *
173
167
  * @param {String[]} arr array of strings
174
168
  * @param {Object} [config={}] config (flags, args)
175
169
  * @returns {Promise} Promise resolving the closest matching string
176
170
  */
177
- async closestAsync ( arr, config = {} ) {
171
+ closestAsync ( arr, config = {} ) {
178
172
 
179
173
  return this.#asyncWrapper(
180
174
  this.closest,
@@ -185,7 +179,6 @@ module.exports = class CmpStrAsync extends CmpStr {
185
179
 
186
180
  /**
187
181
  * generate a similarity matrix for an array of strings
188
- * @async
189
182
  *
190
183
  * @param {String} algo name of the algorithm
191
184
  * @param {String[]} arr array of strings to cross-compare
package/src/index.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * - generate similarity matrices for cross-comparisons
23
23
  *
24
24
  * @author Paul Köhler (komed3)
25
- * @version 2.0.2
25
+ * @version 2.0.3
26
26
  * @license MIT
27
27
  */
28
28