@coolicons/cli 5.0.0-beta.2 → 5.0.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/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @coolicons/cli
2
2
 
3
- Search [coolicons](https://coolicons.cool) and copy them into your project from the terminal: 1220 icons in five styles and three corner radii. No install, no dependencies, no network. The whole set ships inside the package.
3
+ <a href="https://coolicons.cool"><img src="https://raw.githubusercontent.com/krystonschwarze/coolicons/main/.github/assets/banner.png" alt="coolicons: Every icon for your next project. Free, wherever you build." width="100%"></a>
4
+
5
+ Search [coolicons](https://coolicons.cool) and copy them into your project from the terminal: 1,220 icons in five styles and three corner radii. No install, no dependencies, no network. The whole set ships inside the package.
4
6
 
5
7
  ```sh
6
8
  npx @coolicons/cli search delete
package/dist/core.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { readFileSync } from "node:fs";
2
+ import { matchIcons } from "./search.js";
2
3
 
3
4
  export const STYLES = ["line", "duocolor", "duotone", "fill", "bulk"];
4
5
  export const RADII = ["sharp", "regular", "round"];
@@ -54,38 +55,8 @@ export function checkVariant(style = "line", radius = "regular") {
54
55
  return { style, radius };
55
56
  }
56
57
 
57
- function scoreIcon(icon, terms) {
58
- let total = 0;
59
- const tokens = icon.name.split("-");
60
- const groups = icon.category.toLowerCase().split(/[^a-z0-9]+/);
61
- for (const term of terms) {
62
- let best = 0;
63
- const exact = icon.keywords.indexOf(term);
64
- const prefix = icon.keywords.findIndex((word) => word.startsWith(term));
65
- if (icon.name === term) best = 100;
66
- else if (icon.name.startsWith(term)) best = 80;
67
- else if (tokens.includes(term)) best = 70;
68
- else if (tokens.some((token) => token.startsWith(term))) best = 55;
69
- else if ((term.length > 3 || term.includes("-")) && icon.name.includes(term)) best = 40;
70
- else if (exact >= 0) best = 35 - Math.min(exact, 9);
71
- else if (groups.includes(term)) best = 30;
72
- else if (prefix >= 0) best = 25 - Math.min(prefix, 9);
73
- else if (icon.category.toLowerCase().includes(term)) best = 15;
74
- if (!best) return 0;
75
- total += best;
76
- }
77
- return total;
78
- }
79
-
80
58
  export function search(query, limit = 10) {
81
- const terms = String(query).toLowerCase().trim().split(/\s+/).filter(Boolean);
82
- if (!terms.length) return [];
83
- return iconSet()
84
- .icons.map((icon) => ({ icon, rank: scoreIcon(icon, terms) }))
85
- .filter((entry) => entry.rank)
86
- .sort((a, b) => b.rank - a.rank || a.icon.name.length - b.icon.name.length || a.icon.name.localeCompare(b.icon.name))
87
- .slice(0, limit)
88
- .map((entry) => entry.icon);
59
+ return matchIcons(iconSet().icons, query).slice(0, limit);
89
60
  }
90
61
 
91
62
  function distance(a, b) {
package/dist/search.js ADDED
@@ -0,0 +1,44 @@
1
+ export function searchTerms(query) {
2
+ return String(query).toLowerCase().trim().split(/\s+/).filter(Boolean);
3
+ }
4
+
5
+ export function scoreIcon(icon, terms) {
6
+ let total = 0;
7
+ const tokens = icon.name.split("-");
8
+ const groups = icon.category.toLowerCase().split(/[^a-z0-9]+/);
9
+ for (const term of terms) {
10
+ let best = 0;
11
+ const exact = icon.keywords.indexOf(term);
12
+ const prefix = icon.keywords.findIndex((word) => word.startsWith(term));
13
+ if (icon.name === term) best = 100;
14
+ else if (icon.name.startsWith(term)) best = 80;
15
+ else if (tokens.includes(term)) best = 70;
16
+ else if (tokens.some((token) => token.startsWith(term))) best = 55;
17
+ else if (
18
+ (term.length > 3 || term.includes("-")) &&
19
+ icon.name.includes(term)
20
+ )
21
+ best = 40;
22
+ else if (exact >= 0) best = 35 - Math.min(exact, 9);
23
+ else if (groups.includes(term)) best = 30;
24
+ else if (prefix >= 0) best = 25 - Math.min(prefix, 9);
25
+ else if (icon.category.toLowerCase().includes(term)) best = 15;
26
+ if (!best) return 0;
27
+ total += best;
28
+ }
29
+ return total;
30
+ }
31
+
32
+ export function matchIcons(icons, query) {
33
+ const terms = searchTerms(query);
34
+ return icons
35
+ .map((icon) => ({ icon, rank: scoreIcon(icon, terms) }))
36
+ .filter((entry) => entry.rank)
37
+ .sort(
38
+ (a, b) =>
39
+ b.rank - a.rank ||
40
+ a.icon.name.length - b.icon.name.length ||
41
+ a.icon.name.localeCompare(b.icon.name),
42
+ )
43
+ .map((entry) => entry.icon);
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coolicons/cli",
3
- "version": "5.0.0-beta.2",
3
+ "version": "5.0.0",
4
4
  "description": "Search coolicons and copy them into your project from the terminal, without network",
5
5
  "keywords": [
6
6
  "coolicons",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "type": "module",
25
25
  "bin": {
26
- "coolicons": "./dist/cli.js"
26
+ "coolicons": "dist/cli.js"
27
27
  },
28
28
  "files": [
29
29
  "dist"