@glob-ui/utils 0.1.0 → 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.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,13 @@
1
1
  import { ClassValue } from 'clsx';
2
2
 
3
+ /** Lowercase, without accents or diacritics, trimmed, with runs of spaces collapsed. */
4
+ declare function normalizeText(text: string): string;
5
+ /**
6
+ * True when every word of the query appears in the texts (in any order, ignoring case and accents).
7
+ * An empty query matches everything.
8
+ */
9
+ declare function matchesSearch(query: string, ...texts: string[]): boolean;
10
+
3
11
  declare function cn(...inputs: ClassValue[]): string;
4
12
 
5
- export { cn };
13
+ export { cn, matchesSearch, normalizeText };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  import { ClassValue } from 'clsx';
2
2
 
3
+ /** Lowercase, without accents or diacritics, trimmed, with runs of spaces collapsed. */
4
+ declare function normalizeText(text: string): string;
5
+ /**
6
+ * True when every word of the query appears in the texts (in any order, ignoring case and accents).
7
+ * An empty query matches everything.
8
+ */
9
+ declare function matchesSearch(query: string, ...texts: string[]): boolean;
10
+
3
11
  declare function cn(...inputs: ClassValue[]): string;
4
12
 
5
- export { cn };
13
+ export { cn, matchesSearch, normalizeText };
package/dist/index.js CHANGED
@@ -20,11 +20,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- cn: () => cn
23
+ cn: () => cn,
24
+ matchesSearch: () => matchesSearch,
25
+ normalizeText: () => normalizeText
24
26
  });
25
27
  module.exports = __toCommonJS(index_exports);
26
28
  var import_clsx = require("clsx");
27
29
  var import_tailwind_merge = require("tailwind-merge");
30
+
31
+ // src/text.ts
32
+ function normalizeText(text) {
33
+ return text.normalize("NFD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().trim().replace(/\s+/g, " ");
34
+ }
35
+ function matchesSearch(query, ...texts) {
36
+ const words = normalizeText(query).split(" ").filter(Boolean);
37
+ if (words.length === 0) return true;
38
+ const haystack = normalizeText(texts.join(" "));
39
+ return words.every((word) => haystack.includes(word));
40
+ }
41
+
42
+ // src/index.ts
28
43
  var twMerge = (0, import_tailwind_merge.extendTailwindMerge)({
29
44
  extend: {
30
45
  theme: {
@@ -38,6 +53,8 @@ function cn(...inputs) {
38
53
  }
39
54
  // Annotate the CommonJS export names for ESM import in node:
40
55
  0 && (module.exports = {
41
- cn
56
+ cn,
57
+ matchesSearch,
58
+ normalizeText
42
59
  });
43
60
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { clsx, type ClassValue } from \"clsx\"\nimport { extendTailwindMerge } from \"tailwind-merge\"\n\n// tailwind-merge only knows the default radius/shadow scales. Without this, \"rounded-glob-md\"\n// and a consumer's \"rounded-full\" both survive and the token class can win.\nconst twMerge = extendTailwindMerge({\n extend: {\n theme: {\n radius: [\"glob-sm\", \"glob-md\", \"glob-lg\"],\n shadow: [\"glob-sm\", \"glob-md\"],\n },\n },\n})\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsC;AACtC,4BAAoC;AAIpC,IAAM,cAAU,2CAAoB;AAAA,EAClC,QAAQ;AAAA,IACN,OAAO;AAAA,MACL,QAAQ,CAAC,WAAW,WAAW,SAAS;AAAA,MACxC,QAAQ,CAAC,WAAW,SAAS;AAAA,IAC/B;AAAA,EACF;AACF,CAAC;AAEM,SAAS,MAAM,QAAsB;AAC1C,SAAO,YAAQ,kBAAK,MAAM,CAAC;AAC7B;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/text.ts"],"sourcesContent":["import { clsx, type ClassValue } from \"clsx\"\nimport { extendTailwindMerge } from \"tailwind-merge\"\n\n// tailwind-merge only knows the default radius/shadow scales. Without this, \"rounded-glob-md\"\n// and a consumer's \"rounded-full\" both survive and the token class can win.\nconst twMerge = extendTailwindMerge({\n extend: {\n theme: {\n radius: [\"glob-sm\", \"glob-md\", \"glob-lg\"],\n shadow: [\"glob-sm\", \"glob-md\"],\n },\n },\n})\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs))\n}\nexport { normalizeText, matchesSearch } from \"./text\"\n","/** Lowercase, without accents or diacritics, trimmed, with runs of spaces collapsed. */\nexport function normalizeText(text: string) {\n return text\n .normalize(\"NFD\")\n .replace(/\\p{Diacritic}/gu, \"\")\n .toLowerCase()\n .trim()\n .replace(/\\s+/g, \" \")\n}\n\n/**\n * True when every word of the query appears in the texts (in any order, ignoring case and accents).\n * An empty query matches everything.\n */\nexport function matchesSearch(query: string, ...texts: string[]) {\n const words = normalizeText(query).split(\" \").filter(Boolean)\n if (words.length === 0) return true\n const haystack = normalizeText(texts.join(\" \"))\n return words.every((word) => haystack.includes(word))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsC;AACtC,4BAAoC;;;ACA7B,SAAS,cAAc,MAAc;AAC1C,SAAO,KACJ,UAAU,KAAK,EACf,QAAQ,WAAC,kBAAc,IAAE,GAAE,EAAE,EAC7B,YAAY,EACZ,KAAK,EACL,QAAQ,QAAQ,GAAG;AACxB;AAMO,SAAS,cAAc,UAAkB,OAAiB;AAC/D,QAAM,QAAQ,cAAc,KAAK,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO;AAC5D,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,QAAM,WAAW,cAAc,MAAM,KAAK,GAAG,CAAC;AAC9C,SAAO,MAAM,MAAM,CAAC,SAAS,SAAS,SAAS,IAAI,CAAC;AACtD;;;ADdA,IAAM,cAAU,2CAAoB;AAAA,EAClC,QAAQ;AAAA,IACN,OAAO;AAAA,MACL,QAAQ,CAAC,WAAW,WAAW,SAAS;AAAA,MACxC,QAAQ,CAAC,WAAW,SAAS;AAAA,IAC/B;AAAA,EACF;AACF,CAAC;AAEM,SAAS,MAAM,QAAsB;AAC1C,SAAO,YAAQ,kBAAK,MAAM,CAAC;AAC7B;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,6 +1,19 @@
1
1
  // src/index.ts
2
2
  import { clsx } from "clsx";
3
3
  import { extendTailwindMerge } from "tailwind-merge";
4
+
5
+ // src/text.ts
6
+ function normalizeText(text) {
7
+ return text.normalize("NFD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().trim().replace(/\s+/g, " ");
8
+ }
9
+ function matchesSearch(query, ...texts) {
10
+ const words = normalizeText(query).split(" ").filter(Boolean);
11
+ if (words.length === 0) return true;
12
+ const haystack = normalizeText(texts.join(" "));
13
+ return words.every((word) => haystack.includes(word));
14
+ }
15
+
16
+ // src/index.ts
4
17
  var twMerge = extendTailwindMerge({
5
18
  extend: {
6
19
  theme: {
@@ -13,6 +26,8 @@ function cn(...inputs) {
13
26
  return twMerge(clsx(inputs));
14
27
  }
15
28
  export {
16
- cn
29
+ cn,
30
+ matchesSearch,
31
+ normalizeText
17
32
  };
18
33
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { clsx, type ClassValue } from \"clsx\"\nimport { extendTailwindMerge } from \"tailwind-merge\"\n\n// tailwind-merge only knows the default radius/shadow scales. Without this, \"rounded-glob-md\"\n// and a consumer's \"rounded-full\" both survive and the token class can win.\nconst twMerge = extendTailwindMerge({\n extend: {\n theme: {\n radius: [\"glob-sm\", \"glob-md\", \"glob-lg\"],\n shadow: [\"glob-sm\", \"glob-md\"],\n },\n },\n})\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs))\n}\n"],"mappings":";AAAA,SAAS,YAA6B;AACtC,SAAS,2BAA2B;AAIpC,IAAM,UAAU,oBAAoB;AAAA,EAClC,QAAQ;AAAA,IACN,OAAO;AAAA,MACL,QAAQ,CAAC,WAAW,WAAW,SAAS;AAAA,MACxC,QAAQ,CAAC,WAAW,SAAS;AAAA,IAC/B;AAAA,EACF;AACF,CAAC;AAEM,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/text.ts"],"sourcesContent":["import { clsx, type ClassValue } from \"clsx\"\nimport { extendTailwindMerge } from \"tailwind-merge\"\n\n// tailwind-merge only knows the default radius/shadow scales. Without this, \"rounded-glob-md\"\n// and a consumer's \"rounded-full\" both survive and the token class can win.\nconst twMerge = extendTailwindMerge({\n extend: {\n theme: {\n radius: [\"glob-sm\", \"glob-md\", \"glob-lg\"],\n shadow: [\"glob-sm\", \"glob-md\"],\n },\n },\n})\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs))\n}\nexport { normalizeText, matchesSearch } from \"./text\"\n","/** Lowercase, without accents or diacritics, trimmed, with runs of spaces collapsed. */\nexport function normalizeText(text: string) {\n return text\n .normalize(\"NFD\")\n .replace(/\\p{Diacritic}/gu, \"\")\n .toLowerCase()\n .trim()\n .replace(/\\s+/g, \" \")\n}\n\n/**\n * True when every word of the query appears in the texts (in any order, ignoring case and accents).\n * An empty query matches everything.\n */\nexport function matchesSearch(query: string, ...texts: string[]) {\n const words = normalizeText(query).split(\" \").filter(Boolean)\n if (words.length === 0) return true\n const haystack = normalizeText(texts.join(\" \"))\n return words.every((word) => haystack.includes(word))\n}\n"],"mappings":";AAAA,SAAS,YAA6B;AACtC,SAAS,2BAA2B;;;ACA7B,SAAS,cAAc,MAAc;AAC1C,SAAO,KACJ,UAAU,KAAK,EACf,QAAQ,WAAC,kBAAc,IAAE,GAAE,EAAE,EAC7B,YAAY,EACZ,KAAK,EACL,QAAQ,QAAQ,GAAG;AACxB;AAMO,SAAS,cAAc,UAAkB,OAAiB;AAC/D,QAAM,QAAQ,cAAc,KAAK,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO;AAC5D,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,QAAM,WAAW,cAAc,MAAM,KAAK,GAAG,CAAC;AAC9C,SAAO,MAAM,MAAM,CAAC,SAAS,SAAS,SAAS,IAAI,CAAC;AACtD;;;ADdA,IAAM,UAAU,oBAAoB;AAAA,EAClC,QAAQ;AAAA,IACN,OAAO;AAAA,MACL,QAAQ,CAAC,WAAW,WAAW,SAAS;AAAA,MACxC,QAAQ,CAAC,WAAW,SAAS;AAAA,IAC/B;AAAA,EACF;AACF,CAAC;AAEM,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glob-ui/utils",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",