'use strict';

var font = require('font-ls');

// @ts-ignore
/**
 * 判断字符串是否全部为 ASCII 字符
 * @param str 要检查的字符串
 * @returns 如果字符串全部为 ASCII 字符，则返回 true；否则返回 false
 */
function isAscii(str) {
    // eslint-disable-next-line no-control-regex
    return /^[\x00-\x7F]*$/.test(str);
}
async function getFontsList() {
    // @ts-ignore
    const fonts = await font.getAvailableFonts();
    // @ts-ignore
    return fonts.map((font) => {
        if (isAscii(font.postscriptName)) {
            return {
                postscriptName: font.postscriptName,
                fullName: font.localizedName,
            };
        }
        else {
            return {
                postscriptName: font.enName,
                fullName: font.localizedName,
            };
        }
    });
}

exports.getFontsList = getFontsList;
