0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-06 23:00:55 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/text/font/local/translateFontVariantId.ts
Jordi Sala Morales 2920ac297b
Implement unordered and ordered lists (#88)
* wip

* implement bullet points

* needs more ifs

* refactor

* revert

* refactor

* fix and refactor

* refactor

* refactor

* refactor

* add ordered class

* wip

* wip

* fixes

* package.json

* little refactors

* base list

* fixes

* abstract baselist

* refactors

* refactor

* changeset

* fix eslint issue

* fix

* fixes

* fixes

---------

Co-authored-by: Alex Sánchez <sion333@gmail.com>
2024-05-07 12:18:15 +02:00

30 lines
987 B
TypeScript

import { LocalFont } from './localFont';
export const translateFontVariantId = (
localFont: LocalFont,
fontName: FontName,
fontWeight: number
): string | undefined => {
// check match by style and weight
const italic = fontName.style.toLowerCase().includes('italic');
const variantWithStyleWeight = localFont.variants?.find(
variant =>
variant.weight === fontWeight.toString() && variant.style === (italic ? 'italic' : 'normal')
);
if (variantWithStyleWeight !== undefined) return variantWithStyleWeight.id;
// check match directly by suffix if exists
const variant = localFont.variants?.find(
variant => variant.suffix === fontName.style.toLowerCase().replace(/\s/g, '')
);
if (variant !== undefined) return variant.id;
// check match directly by id
const variantById = localFont.variants?.find(
variant => variant.id === fontName.style.toLowerCase().replace(/\s/g, '')
);
if (variantById !== undefined) return variantById.id;
};