-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improved sorting for search results
- Loading branch information
1 parent
5cb4d91
commit 21d5bdb
Showing
7 changed files
with
199 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { IconifyJSON } from '@iconify/types'; | ||
import { StorageIconSetThemes } from '../../../types/icon-set/storage'; | ||
|
||
/** | ||
* Themes to copy | ||
*/ | ||
export const themeKeys: (keyof StorageIconSetThemes)[] = ['prefixes', 'suffixes']; | ||
|
||
/** | ||
* Hardcoded list of themes | ||
* | ||
* Should contain only simple items, without '-' | ||
*/ | ||
const hardcodedThemes: Set<string> = new Set([ | ||
'baseline', | ||
'outline', | ||
'round', | ||
'sharp', | ||
'twotone', | ||
'thin', | ||
'light', | ||
'bold', | ||
'fill', | ||
'duotone', | ||
'linear', | ||
'line', | ||
'solid', | ||
'filled', | ||
'outlined', | ||
]); | ||
|
||
/** | ||
* Find icon | ||
*/ | ||
export function findIconSetThemes(iconSet: IconifyJSON): string[] { | ||
const results: Set<string> = new Set(); | ||
|
||
// Add prefixes / suffixes from themes | ||
themeKeys.forEach((key) => { | ||
const items = iconSet[key]; | ||
if (items) { | ||
Object.keys(items).forEach((item) => { | ||
if (item) { | ||
results.add(item); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
// Check all icons and aliases | ||
const names = Object.keys(iconSet.icons).concat(Object.keys(iconSet.aliases || {})); | ||
for (let i = 0; i < names.length; i++) { | ||
const name = names[i]; | ||
const parts = name.split('-'); | ||
if (parts.length > 1) { | ||
const firstChunk = parts.shift() as string; | ||
const lastChunk = parts.pop() as string; | ||
if (hardcodedThemes.has(firstChunk)) { | ||
results.add(firstChunk); | ||
} | ||
if (hardcodedThemes.has(lastChunk)) { | ||
results.add(lastChunk); | ||
} | ||
} | ||
} | ||
|
||
// Return as array, sorted by length | ||
return Array.from(results).sort((a, b) => b.length - a.length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.