Skip to content

Commit

Permalink
fix(preset-web-fonts): sort weights as string using localeCompare (#2845
Browse files Browse the repository at this point in the history
)

Co-authored-by: Chris <hizyyv@gmail.com>
  • Loading branch information
arunanshub and zyyv committed Jul 15, 2023
1 parent ffdeb20 commit 1bfba0d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/preset-web-fonts/src/index.ts
Expand Up @@ -27,15 +27,15 @@ export function normalizedFontMeta(meta: WebFontMeta | string, defaultProvider:
if (typeof meta !== 'string') {
meta.provider = resolveProvider(meta.provider || defaultProvider)
if (meta.weights)
meta.weights = [...new Set(meta.weights.map(Number).sort((a, b) => a - b))]
meta.weights = [...new Set(meta.weights.sort((a, b) => a.toString().localeCompare(b.toString(), 'en', { numeric: true })))]
return meta as ResolvedWebFontMeta
}

const [name, weights = ''] = meta.split(':')

return {
name,
weights: [...new Set(weights.split(/[,;]\s*/).filter(Boolean).map(Number).sort((a, b) => a - b))],
weights: [...new Set(weights.split(/[,;]\s*/).filter(Boolean).sort((a, b) => a.localeCompare(b, 'en', { numeric: true })))],
provider: resolveProvider(defaultProvider),
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/preset-web-fonts/src/providers/bunny.ts
Expand Up @@ -13,7 +13,7 @@ export function createBunnyFontsProvider(
if (!weights?.length)
return `${formattedName}${italic ? ':i' : ''}`

let weightsAsString = weights.sort().map(weight => weight.toString())
let weightsAsString = weights.map(weight => weight.toString())
// 1. if weights have at least one element that has 'i', ignore the `italic` flag.
// 2. if none of the weights have an 'i' and italic is true, append an 'i'
const weightsHaveItalic = weightsAsString.some(weight => weight.endsWith('i'))
Expand Down

0 comments on commit 1bfba0d

Please sign in to comment.