mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* first part of migration * second part of migration * bump up es-toolkit version * bump up `es-toolkit` version and remove `lodash` completely * update screenshot
31 lines
735 B
TypeScript
31 lines
735 B
TypeScript
import { upperFirst } from 'es-toolkit';
|
|
|
|
export function formatName(_name: string) {
|
|
const name = _name
|
|
.replaceAll('_', ' ')
|
|
.replaceAll(/\burl|nft|id\b/gi, (str) => str.toUpperCase());
|
|
|
|
return upperFirst(name.trim());
|
|
}
|
|
|
|
const PINNED_FIELDS = [ 'name', 'description' ];
|
|
|
|
export function sortFields([ nameA ]: [string, unknown], [ nameB ]: [string, unknown]): number {
|
|
const pinnedIndexA = PINNED_FIELDS.indexOf(nameA.toLowerCase());
|
|
const pinnedIndexB = PINNED_FIELDS.indexOf(nameB.toLowerCase());
|
|
|
|
if (pinnedIndexA === -1 && pinnedIndexB === -1) {
|
|
return 0;
|
|
}
|
|
|
|
if (pinnedIndexB === -1) {
|
|
return -1;
|
|
}
|
|
|
|
if (pinnedIndexA === -1) {
|
|
return 1;
|
|
}
|
|
|
|
return pinnedIndexA > pinnedIndexB ? 1 : -1;
|
|
}
|