@findlane/browser 0.16.0 → 0.16.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.
@@ -1,6 +1,8 @@
1
1
  import type { QuerySuggestion, RecommendationsRequest, RecommendationsResponse, SearchBrowserClient, SearchRequest, SearchResponse } from "../index.js";
2
2
  /** Requests the API answers the same way share a key, as at the edge (workers/api/src/edge.ts):
3
- * the query's first eight lowercase words, defaults left out, and list order ignored. */
3
+ * the query's first eight lowercase words, defaults left out, and list order ignored. Words keep an
4
+ * apostrophe or period inside them (don't, 3.5), which the API matches as one word; the edge's exact
5
+ * rule needs lookbehind, which older Safari can't parse, so this keeps a little more apart than it. */
4
6
  export declare function searchKey(request: SearchRequest): string;
5
7
  /** A product's recommendations share a key when only defaults differ: the limit of 8 and empty filters. */
6
8
  export declare function recommendationsKey(objectID: string, request?: RecommendationsRequest): string;
@@ -6,11 +6,14 @@ const searches = store();
6
6
  const recommendations = store();
7
7
  const suggestions = store();
8
8
  /** Requests the API answers the same way share a key, as at the edge (workers/api/src/edge.ts):
9
- * the query's first eight lowercase words, defaults left out, and list order ignored. */
9
+ * the query's first eight lowercase words, defaults left out, and list order ignored. Words keep an
10
+ * apostrophe or period inside them (don't, 3.5), which the API matches as one word; the edge's exact
11
+ * rule needs lookbehind, which older Safari can't parse, so this keeps a little more apart than it. */
10
12
  export function searchKey(request) {
11
13
  const normal = { ...request };
12
14
  if (typeof normal.q === "string" && normal.q.length <= 200)
13
- normal.q = normal.q.toLowerCase().match(/[\p{L}\p{N}]+/gu)?.slice(0, 8).join(" ") ?? "";
15
+ normal.q = (normal.q.toLowerCase().replace(/[’‘]/gu, "'").match(/[\p{L}\p{M}\p{N}_'.:·,;]+/gu) ?? [])
16
+ .map((word) => word.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, "")).filter(Boolean).slice(0, 8).join(" ");
14
17
  const defaults = { q: "", limit: 20, offset: 0, countMode: "page", facetMode: "page" };
15
18
  for (const [key, value] of Object.entries(defaults))
16
19
  if (normal[key] === value)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@findlane/browser",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Findlane browser SDK: fast, typo-tolerant public search from the browser with an index's public ID, plus React hooks and components.",
5
5
  "keywords": ["findlane", "search", "full-text search", "typo tolerance", "instant search", "ecommerce search", "browser", "react", "autocomplete"],
6
6
  "license": "MIT",