@orchidjs/sifter 1.0.3 → 1.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.
Files changed (42) hide show
  1. package/README.md +8 -10
  2. package/dist/cjs/package.json +1 -0
  3. package/dist/cjs/sifter.d.ts +72 -0
  4. package/dist/cjs/sifter.js +275 -1101
  5. package/dist/cjs/sifter.js.map +1 -1
  6. package/dist/cjs/types.d.ts +58 -0
  7. package/dist/cjs/types.js +3 -0
  8. package/dist/cjs/types.js.map +1 -0
  9. package/dist/cjs/utils.d.ts +48 -0
  10. package/dist/cjs/utils.js +104 -0
  11. package/dist/cjs/utils.js.map +1 -0
  12. package/dist/esm/sifter.d.ts +72 -0
  13. package/dist/esm/sifter.js +266 -330
  14. package/dist/esm/sifter.js.map +1 -1
  15. package/dist/esm/types.d.ts +58 -0
  16. package/dist/esm/types.js +2 -0
  17. package/dist/esm/types.js.map +1 -0
  18. package/dist/esm/utils.d.ts +48 -0
  19. package/dist/esm/utils.js +56 -56
  20. package/dist/esm/utils.js.map +1 -1
  21. package/dist/types/sifter.d.ts +5 -4
  22. package/dist/types/types.d.ts +13 -12
  23. package/dist/types/utils.d.ts +2 -2
  24. package/dist/umd/package.json +1 -0
  25. package/dist/umd/sifter.js +808 -1037
  26. package/dist/umd/sifter.js.map +1 -1
  27. package/dist/umd/sifter.min.js +66 -66
  28. package/dist/umd/sifter.min.js.map +1 -1
  29. package/lib/sifter.ts +9 -9
  30. package/lib/types.ts +4 -2
  31. package/lib/utils.ts +4 -2
  32. package/package.json +31 -21
  33. package/dist/esm/lib/sifter.js +0 -368
  34. package/dist/esm/lib/sifter.js.map +0 -1
  35. package/dist/esm/lib/utils.js +0 -95
  36. package/dist/esm/lib/utils.js.map +0 -1
  37. package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/index.js +0 -547
  38. package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/index.js.map +0 -1
  39. package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/regex.js +0 -113
  40. package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/regex.js.map +0 -1
  41. package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/strings.js +0 -29
  42. package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/strings.js.map +0 -1
package/README.md CHANGED
@@ -39,12 +39,12 @@ var result = sifter.search('anna', {
39
39
  });
40
40
  ```
41
41
 
42
- Seaching will provide back meta information and an "items" array that contains objects with the index (or key, if searching a hash) and a score that represents how good of a match the item was. Items that did not match will not be returned.
42
+ Seaching will provide back meta information and an "items" array that contains objects with the index (or key, if searching a hash), the matched item itself, and a score that represents how good of a match the item was. Items that did not match will not be returned.
43
43
 
44
44
  ```js
45
- { score: 0.5757575757575758, id: 0 },
46
- { score: 0.5555555555555555, id: 1 },
47
- { score: 0.5384615384615384, id: 2 }
45
+ { score: 0.5757575757575758, id: 0, item: { title: 'Annapurna I', location: 'Nepal', continent: 'Asia' } },
46
+ { score: 0.5555555555555555, id: 1, item: { title: 'Annapurna II', location: 'Nepal', continent: 'Asia' } },
47
+ { score: 0.5384615384615384, id: 2, item: { title: 'Annapurna III', location: 'Nepal', continent: 'Asia' } }
48
48
  ```
49
49
 
50
50
  Items are sorted by best-match, primarily. If two or more items have the same score (which will be the case when searching with an empty string), it will resort to the fields listed in the "sort" option.
@@ -67,9 +67,9 @@ The full result comes back in the format of:
67
67
  }],
68
68
  total: 3,
69
69
  items: [
70
- { score: 0.5757575757575758, id: 0 },
71
- { score: 0.5555555555555555, id: 1 },
72
- { score: 0.5384615384615384, id: 2 }
70
+ { score: 0.5757575757575758, id: 0, item: { title: 'Annapurna I', ... } },
71
+ { score: 0.5555555555555555, id: 1, item: { title: 'Annapurna II', ... } },
72
+ { score: 0.5384615384615384, id: 2, item: { title: 'Annapurna III', ... } }
73
73
  ]
74
74
  }
75
75
  ```
@@ -120,9 +120,7 @@ fields: [
120
120
 
121
121
  ```js
122
122
  sort: function(a,b){
123
- var item_a = this.items[a.id];
124
- var item_b = this.items[b.id];
125
- return item_a.fielda.localeCompare(item_b.fielda);
123
+ return a.item.fielda.localeCompare(b.item.fielda);
126
124
  },
127
125
  ```
128
126
  </td>
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * sifter.js
3
+ * Copyright (c) 2013–2020 Brian Reavis & contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6
+ * file except in compliance with the License. You may obtain a copy of the License at:
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ * ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ *
14
+ * @author Brian Reavis <brian@thirdroute.com>
15
+ */
16
+ import { scoreValue, getAttr, getAttrNesting, propToArray, iterate, cmp } from './utils.ts';
17
+ import { getPattern } from '@orchidjs/unicode-variants';
18
+ import type * as T from './types.ts';
19
+ declare class Sifter {
20
+ items: any;
21
+ settings: T.Settings;
22
+ /**
23
+ * Textually searches arrays and hashes of objects
24
+ * by property (or multiple properties). Designed
25
+ * specifically for autocomplete.
26
+ *
27
+ */
28
+ constructor(items: any, settings: T.Settings);
29
+ /**
30
+ * Splits a search string into an array of individual
31
+ * regexps to be used to match results.
32
+ *
33
+ */
34
+ tokenize(query: string, respect_word_boundaries?: boolean, weights?: T.Weights): T.Token[];
35
+ /**
36
+ * Returns a function to be used to score individual results.
37
+ *
38
+ * Good matches will have a higher score than poor matches.
39
+ * If an item is not a match, 0 will be returned by the function.
40
+ *
41
+ * @returns {T.ScoreFn}
42
+ */
43
+ getScoreFunction(query: string, options: T.UserOptions): (data: {}) => number;
44
+ /**
45
+ * @returns {T.ScoreFn}
46
+ *
47
+ */
48
+ _getScoreFunction(search: T.PrepareObj): (data: {}) => number;
49
+ /**
50
+ * Returns a function that can be used to compare two
51
+ * results, for sorting purposes. If no sorting should
52
+ * be performed, `null` will be returned.
53
+ *
54
+ * @return function(a,b)
55
+ */
56
+ getSortFunction(query: string, options: T.UserOptions): ((a: T.ResultItem<any>, b: T.ResultItem<any>) => number) | null;
57
+ _getSortFunction(search: T.PrepareObj): ((a: T.ResultItem<any>, b: T.ResultItem<any>) => number) | null;
58
+ /**
59
+ * Parses a search query and returns an object
60
+ * with tokens and fields ready to be populated
61
+ * with results.
62
+ *
63
+ */
64
+ prepareSearch(query: string, optsUser: T.UserOptions): T.PrepareObj;
65
+ /**
66
+ * Searches through all items and returns a sorted array of matches.
67
+ *
68
+ */
69
+ search(query: string, options: T.UserOptions): T.PrepareObj;
70
+ }
71
+ export { Sifter, scoreValue, getAttr, getAttrNesting, propToArray, iterate, cmp, getPattern };
72
+ export type * from './types.ts';