@capsizecss/metrics
Version:
Font metrics library for system and Google fonts
22 lines (20 loc) • 629 B
JavaScript
//#region src/index.ts
/**
* Converts the font family name to the correct casing for the relevant metrics import.
*
* ---
* Example usage:
*
* ```ts
* import { fontFamilyToCamelCase } from '@capsizecss/metrics';
*
* const familyName = fontFamilyToCamelCase('--apple-system'); // => `appleSystem`
* const metrics = await import(`@capsizecss/metrics/${familyName}`);
* ```
* ---
*/
function fontFamilyToCamelCase(str) {
return str.split(/[\s|-]/).filter(Boolean).map((s, i) => `${s.charAt(0)[i > 0 ? "toUpperCase" : "toLowerCase"]()}${s.slice(1)}`).join("");
}
//#endregion
exports.fontFamilyToCamelCase = fontFamilyToCamelCase;