@coolicons/cli 0.0.0 → 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/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,8 +1,16 @@
1
1
  {
2
2
  "name": "@coolicons/cli",
3
- "version": "0.0.0",
4
- "description": "Reserved for coolicons 5, the first real version follows shortly",
3
+ "version": "5.0.0",
4
+ "description": "Search coolicons and copy them into your project from the terminal, without network",
5
+ "keywords": [
6
+ "coolicons",
7
+ "icons",
8
+ "svg",
9
+ "cli",
10
+ "icon-set"
11
+ ],
5
12
  "homepage": "https://coolicons.cool",
13
+ "bugs": "https://github.com/krystonschwarze/coolicons/issues",
6
14
  "repository": {
7
15
  "type": "git",
8
16
  "url": "git+https://github.com/krystonschwarze/coolicons.git",
@@ -12,5 +20,15 @@
12
20
  "author": {
13
21
  "name": "Kryston Schwarze",
14
22
  "url": "https://krystonschwarze.com"
23
+ },
24
+ "type": "module",
25
+ "bin": {
26
+ "coolicons": "dist/cli.js"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "engines": {
32
+ "node": ">=22"
15
33
  }
16
34
  }