Comparing version 0.2.8 to 0.2.9
import { Font } from 'fontkit'; | ||
export declare class FontDescriptor { | ||
static createFromPath(path: string): FontDescriptor | FontDescriptor[]; | ||
static createFromPath(filepath: string): FontDescriptor | FontDescriptor[]; | ||
readonly path: string; | ||
@@ -12,3 +12,3 @@ readonly family: string; | ||
readonly monospace: boolean; | ||
constructor(font: Font, path: string); | ||
constructor(font: Font, filepath: string); | ||
} |
@@ -8,4 +8,5 @@ "use strict"; | ||
var fontkit_1 = __importDefault(require("fontkit")); | ||
var path_1 = __importDefault(require("path")); | ||
var FontDescriptor = /** @class */ (function () { | ||
function FontDescriptor(font, path) { | ||
function FontDescriptor(font, filepath) { | ||
var _a; | ||
@@ -17,3 +18,4 @@ this.width = 500; | ||
this.monospace = false; | ||
this.path = path; | ||
this.path = filepath; | ||
// font.*Name properties will return Buffer (like Buffer<00 7a 00 ee ...>) occasionally | ||
this.postscriptName = fixIncorrectString(font.postscriptName); | ||
@@ -34,11 +36,12 @@ this.family = fixIncorrectString(font.familyName); | ||
} | ||
FontDescriptor.createFromPath = function (path) { | ||
var font = fontkit_1.default.openSync(path); | ||
FontDescriptor.createFromPath = function (filepath) { | ||
var fixedPath = path_1.default.resolve(filepath); | ||
var font = fontkit_1.default.openSync(fixedPath); | ||
if ('fonts' in font) { | ||
// TrueTypeCollection have multiple fonts in font file | ||
// eslint-disable-next-line | ||
return font.fonts.map(function (f) { return new FontDescriptor(f, path); }); | ||
return font.fonts.map(function (f) { return new FontDescriptor(f, fixedPath); }); | ||
} | ||
else { | ||
return new FontDescriptor(font, path); | ||
return new FontDescriptor(font, fixedPath); | ||
} | ||
@@ -45,0 +48,0 @@ }; |
@@ -46,4 +46,5 @@ "use strict"; | ||
var path_1 = __importDefault(require("path")); | ||
var fs_1 = __importDefault(require("fs")); | ||
exports.getFontList = function (options) { return __awaiter(void 0, void 0, void 0, function () { | ||
var fixedDirs, list, dirRegExp; | ||
var fixedDirs, list, caseInsensitive, dirRegExp; | ||
var _a; | ||
@@ -53,5 +54,15 @@ return __generator(this, function (_b) { | ||
case 0: | ||
fixedDirs = (_a = options === null || options === void 0 ? void 0 : options.customDirectories) === null || _a === void 0 ? void 0 : _a.map(function (dir) { return path_1.default.resolve(dir); }); | ||
if (options && typeof options !== 'object') { | ||
throw new TypeError('options must be `object`'); | ||
} | ||
if ((options === null || options === void 0 ? void 0 : options.customDirectories) && !Array.isArray(options.customDirectories)) { | ||
throw new TypeError('options.customDirectories must be `string[]`'); | ||
} | ||
if ((options === null || options === void 0 ? void 0 : options.onlyCustomDirectories) && | ||
typeof options.onlyCustomDirectories !== 'boolean') { | ||
throw new TypeError('options.onlyCustomDirectories must be `boolean`'); | ||
} | ||
fixedDirs = ((_a = options === null || options === void 0 ? void 0 : options.customDirectories) === null || _a === void 0 ? void 0 : _a.map(function (dir) { return path_1.default.resolve(dir); })) || []; | ||
return [4 /*yield*/, get_system_fonts_1.default({ | ||
additionalFolders: fixedDirs || [], | ||
additionalFolders: fixedDirs, | ||
extensions: ['ttf', 'otf', 'ttc', 'woff', 'woff2', 'dfont'], | ||
@@ -63,6 +74,9 @@ })]; | ||
.reduce(function (acc, val) { return acc.concat(val); }, []); | ||
if (!fixedDirs || fixedDirs.length === 0 || !(options === null || options === void 0 ? void 0 : options.onlyCustomDirectories)) { | ||
if (fixedDirs.length === 0 || !(options === null || options === void 0 ? void 0 : options.onlyCustomDirectories)) { | ||
return [2 /*return*/, list]; | ||
} | ||
dirRegExp = new RegExp("^" + (fixedDirs === null || fixedDirs === void 0 ? void 0 : fixedDirs.map(function (dir) { return "(?:" + dir.replace(/\\/g, '\\\\') + ")"; }).join('|')), 'i'); | ||
caseInsensitive = fs_1.default.existsSync(process.argv0) && | ||
fs_1.default.existsSync(process.argv0.toLowerCase()) && | ||
fs_1.default.existsSync(process.argv0.toUpperCase()); | ||
dirRegExp = new RegExp("^" + (fixedDirs === null || fixedDirs === void 0 ? void 0 : fixedDirs.map(function (dir) { return "(?:" + dir.replace(/\\/g, '\\\\') + ")"; }).join('|')), caseInsensitive ? 'i' : ''); | ||
return [2 /*return*/, list.filter(function (fontDescriptor) { return dirRegExp.exec(fontDescriptor.path); })]; | ||
@@ -69,0 +83,0 @@ } |
{ | ||
"name": "fontscan", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "Get font list in specified directory(default system fonts).", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -14,2 +14,3 @@ # fontscan | ||
|accuracy|Not good|**Good**| | ||
|speed|Slow|**Fast**| | ||
@@ -83,10 +84,13 @@ [more info...](https://github.com/ssssota/fontscan-vs-font-manager) | ||
- `path: string;` | ||
- `family: string;` | ||
- `postscriptName: string;` | ||
- `width: number;` | ||
- `weight: number;` | ||
- `style: string;` | ||
- `italic: boolean;` | ||
- `monospace: boolean;` | ||
- `path: string` | ||
- `family: string` | ||
- `postscriptName: string` | ||
- `width: number` | ||
- detail [microsoft document](https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswidthclass) | ||
- `weight: number` | ||
- detail [microsoft document](https://docs.microsoft.com/en-us/typography/opentype/spec/os2#usweightclass) | ||
- `style: string` | ||
- e.g. `Regular`, `Bold`, `Italic`, `Bold italic` | ||
- `italic: boolean` | ||
- `monospace: boolean` | ||
@@ -100,2 +104,8 @@ ## Contribution | ||
5. Run test suite with the `npm test` command and confirm that it passes | ||
6. Create new Pull Request | ||
6. Create new Pull Request | ||
**Please tell me if my English is wrong** | ||
## LICENSE | ||
[MIT](LICENSE) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
16761
158
109
1