@mtes-mct/monitor-ui 6.2.1 → 6.3.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.
@@ -0,0 +1,72 @@
1
+ import Fuse from 'fuse.js';
2
+ export type CustomSearchOptions = Partial<{
3
+ /** Cache search index to avoid Must be unique in the entire application. */
4
+ cacheKey: string | undefined;
5
+ /**
6
+ * Indicates whether comparisons should be case sensitive.
7
+ *
8
+ * @default false
9
+ * @see https://fusejs.io/api/options.html#iscasesensitive
10
+ */
11
+ isCaseSensitive: boolean;
12
+ /** Indicates whether comparisons should be diacritic (= accent) sensitive. */
13
+ isDiacriticSensitive: boolean;
14
+ /**
15
+ * Use strict keywords matching, disabling fuzziness.
16
+ *
17
+ * @default false
18
+ * @description
19
+ * Looking for "emoi" in ["mÉMOIre", "mÉMOrIsable"] will return only the first one if `isStrict` is `true`,
20
+ * instead of returning both by default (`false`).
21
+ */
22
+ isStrict: boolean;
23
+ /**
24
+ * At what point does the match algorithm give up.
25
+ *
26
+ * @default 0.6
27
+ * @description
28
+ * A threshold of `0.0` requires a perfect match (of both letters and location),
29
+ * a threshold of `1.0` would match anything.
30
+ *
31
+ * @see https://fusejs.io/api/options.html#threshold
32
+ */
33
+ threshold: number;
34
+ }>;
35
+ export type CustomSearchKey<T> = string | Fuse.FuseOptionKeyObject<T>;
36
+ export declare class CustomSearch<T extends Record<string, any> = Record<string, any>> {
37
+ #private;
38
+ constructor(collection: T[], keys: Array<CustomSearchKey<T>>, { cacheKey, isCaseSensitive, isDiacriticSensitive, isStrict, threshold }?: CustomSearchOptions);
39
+ /**
40
+ * Searches the entire collection, and returns a list of items matching this query.
41
+ *
42
+ * @param query The keywords to look for
43
+ * @param limit Denotes the max number of returned search results
44
+ * @returns A list of matching items
45
+ */
46
+ find(query: string, limit?: number): T[];
47
+ /**
48
+ * Replace all the diacritics with unaccented letters in a collection, targetting the provided keys.
49
+ *
50
+ * @param collection An array of objects
51
+ * @param keys List of item prop path to clean, either a using strings
52
+ * or [Fuse.js weighted objects](https://fusejs.io/api/options.html#keys)
53
+ * @returns The same collection with its specified keys normalized without diacritics
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const collection = [
58
+ * { name: 'aérosol', description: 'Un aérosol.', author: { name: 'Camille Hervé' } },
59
+ * { name: 'martèlement', description: 'Un martèlement.', author: { name: 'Athénée Perreault' } }
60
+ * ]
61
+ *
62
+ * const normalizedCollection = CustomSearch.cleanCollectionDiacritics(collection, ['name', 'author.name'])
63
+ * console.log(normalizedCollection[0])
64
+ * // => `{ "name": "aerosol", "description": "Un aérosol.", author: { name: 'Camille Herve' } }`
65
+ *
66
+ * const normalizedCollection = CustomSearch.cleanCollectionDiacritics(collection, [{ name: 'name', weight: 1 }])
67
+ * console.log(normalizedCollection[0])
68
+ * // => `{ "name": "aerosol", "description": "Un aérosol.", author: { name: 'Camille Hervé' }`
69
+ * ```
70
+ */
71
+ static cleanCollectionDiacritics<T extends Record<string, any> = Record<string, any>>(collection: T[], keys: Array<CustomSearchKey<T>>): T[];
72
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mtes-mct/monitor-ui",
3
3
  "description": "Common React UI components and styles for Monitorfish and Monitorenv.",
4
- "version": "6.2.1",
4
+ "version": "6.3.0",
5
5
  "license": "AGPL-3.0",
6
6
  "engines": {
7
7
  "node": ">=18"