@ohos-ports/get-system-fonts 0.0.0-stage → 2.0.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ ## [2.0.2](https://github.com/princjef/get-system-fonts/compare/v2.0.1...v2.0.2) (2020-06-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **no:** add option to regexp ignoreCase ([#8](https://github.com/princjef/get-system-fonts/issues/8)) ([0b3271f](https://github.com/princjef/get-system-fonts/commit/0b3271f))
7
+
8
+ ## [2.0.1](https://github.com/princjef/get-system-fonts/compare/v2.0.0...v2.0.1) (2019-04-23)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **windows:** include fonts installed to local app data on windows ([#4](https://github.com/princjef/get-system-fonts/issues/4)) ([95183eb](https://github.com/princjef/get-system-fonts/commit/95183eb)), closes [#3](https://github.com/princjef/get-system-fonts/issues/3)
14
+
15
+ # [2.0.0](https://github.com/princjef/get-system-fonts/compare/v1.0.0...v2.0.0) (2018-07-30)
16
+
17
+
18
+ ### Performance Improvements
19
+
20
+ * remove fast-glob dependency to reduce install size ([f033af5](https://github.com/princjef/get-system-fonts/commit/f033af5))
21
+
22
+
23
+ ### BREAKING CHANGES
24
+
25
+ * dropped support for Node 6 and 7
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jeffrey Principe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,44 @@
1
- # Temporary Holding Version
1
+ # get-system-fonts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![Travis CI build status](https://travis-ci.org/princjef/get-system-fonts.svg?branch=master)](https://travis-ci.org/princjef/get-system-fonts)
4
+ [![codecov](https://codecov.io/gh/princjef/get-system-fonts/branch/master/graph/badge.svg)](https://codecov.io/gh/princjef/get-system-fonts)
5
+ [![npm version](https://img.shields.io/npm/v/get-system-fonts.svg)](https://npmjs.org/package/get-system-fonts)
6
+
7
+ List full paths to all of the system fonts present.
8
+
9
+ ```
10
+ npm install get-system-fonts
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```js
16
+ const getSystemFonts = require('get-system-fonts');
17
+
18
+ // In an async function...
19
+ const files = await getSystemFonts(); // ['/Library/Fonts/Georgia.ttf', ...]
20
+ ```
21
+
22
+ ## API
23
+
24
+ ### `getSystemFonts([options]): Promise<string[]>`
25
+
26
+ Lists absolute paths to all system fonts
27
+
28
+ *NOTE: If you're using Typescript, `getSystemFonts()` is available as the
29
+ default export.*
30
+
31
+ **Params**
32
+
33
+ * `options` [*object*] - Options for configuring retrieval
34
+ * `additionalFolders` [*string[]*] - Paths to additional folders to
35
+ recursively scan for font files. Absolute paths are recommended. Default:
36
+ `[]`
37
+ * `extensions` [*string[]*] - List of file extensions to treat as font
38
+ files. Default: `['ttf', 'otf', 'ttc', 'woff', 'woff2']`
39
+
40
+ ## Contributing
41
+
42
+ Want to contribute to the project? Go check out the [Contribution
43
+ Guide](CONTRIBUTING.md) for instructions to set up your development
44
+ environment, open an issue and create a pull request.
@@ -0,0 +1,17 @@
1
+ export interface Options {
2
+ /**
3
+ * Additional folders to search for fonts. Default: []
4
+ */
5
+ additionalFolders?: string[];
6
+ /**
7
+ * File extensions to search for. Default: ['ttf', 'otf', 'ttc', 'woff', 'woff2']
8
+ */
9
+ extensions?: string[];
10
+ }
11
+ /**
12
+ * List absolute paths to all installed system fonts present.
13
+ *
14
+ * @param options Configuration options
15
+ */
16
+ declare function getSystemFonts(options?: Options): Promise<string[]>;
17
+ export default getSystemFonts;
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path = require("path");
4
+ const os = require("os");
5
+ const recursiveWalk_1 = require("./recursiveWalk");
6
+ const directories = {
7
+ win32: () => {
8
+ const globalDir = path.join(process.env.WINDIR || 'C:\\Windows', 'Fonts');
9
+ const appDataDir = 'Microsoft\\Windows\\Fonts';
10
+ let localDir;
11
+ if (process.env.LOCALAPPDATA) {
12
+ localDir = path.join(process.env.LOCALAPPDATA, appDataDir);
13
+ }
14
+ else if (process.env.APPDATA) {
15
+ localDir = path.join(process.env.APPDATA, 'Local', appDataDir);
16
+ }
17
+ else if (process.env.USERPROFILE) {
18
+ localDir = path.join(process.env.USERPROFILE, 'AppData', 'Local', appDataDir);
19
+ }
20
+ if (localDir) {
21
+ return [globalDir, localDir];
22
+ }
23
+ else {
24
+ return [globalDir];
25
+ }
26
+ },
27
+ darwin: () => {
28
+ const home = os.homedir();
29
+ const userFolders = home
30
+ ? [path.join(home, '/Library/Fonts')]
31
+ : [];
32
+ return [
33
+ ...userFolders,
34
+ '/Library/Fonts',
35
+ '/Network/Library/Fonts',
36
+ '/System/Library/Fonts',
37
+ '/System Folder/Fonts'
38
+ ];
39
+ },
40
+ linux: () => {
41
+ const home = os.homedir();
42
+ const userFolders = home
43
+ ? [
44
+ path.join(home, '.fonts'),
45
+ path.join(home, '.local/share/fonts')
46
+ ]
47
+ : [];
48
+ return [
49
+ // TODO: use fontconfig to find the folder locations
50
+ '/usr/share/fonts',
51
+ '/usr/local/share/fonts',
52
+ ...userFolders
53
+ ];
54
+ },
55
+ openharmony: () => {
56
+ const home = os.homedir();
57
+ const userFolders = home
58
+ ? [
59
+ path.join(home, '.fonts'),
60
+ path.join(home, '.local/share/fonts')
61
+ ]
62
+ : [];
63
+ return [
64
+ '/system/fonts',
65
+ '/usr/share/fonts',
66
+ '/usr/local/share/fonts',
67
+ ...userFolders
68
+ ];
69
+ }
70
+ };
71
+ /**
72
+ * List absolute paths to all installed system fonts present.
73
+ *
74
+ * @param options Configuration options
75
+ */
76
+ function getSystemFonts(options) {
77
+ const opts = Object.assign({ extensions: ['ttf', 'otf', 'ttc', 'woff', 'woff2'], additionalFolders: [] }, options);
78
+ const platform = os.platform();
79
+ const getDirs = directories[platform];
80
+ if (!getDirs) {
81
+ throw new Error(`Unsupported platform: ${platform}`);
82
+ }
83
+ const dirs = getDirs();
84
+ return recursiveWalk_1.default([...dirs, ...opts.additionalFolders], opts.extensions);
85
+ }
86
+ module.exports = Object.assign(getSystemFonts, { default: getSystemFonts });
87
+ exports.default = getSystemFonts;
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,6BAA6B;AAC7B,yBAAyB;AAEzB,mDAA4C;AAE5C,MAAM,WAAW,GAAiD;IAC9D,KAAK,EAAE,GAAG,EAAE;QACR,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,aAAa,EAAE,OAAO,CAAC,CAAC;QAE1E,MAAM,UAAU,GAAG,2BAA2B,CAAC;QAE/C,IAAI,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AC,CAAC,EAAE,CAAC;QACT,OAAO;YACH,oDAAoD;YACpD,kBAAkB;YAClB,wBAAwB;YACxB,GAAG,WAAW;SACjB,CAAC;IACN,CAAC;CACJ,CAAC;AAcF;;;;GAIG;AACH,SAAS,cAAc,CAAC,OAAiB;IACrC,MAAM,IAAI,mBACN,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAClD,iBAAiB,EAAE,EAAE,IAClB,OAAO,CACb,CAAC;IAEF,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAE/B,MAAM,OAAO,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,OAAO,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;KACxD;IAED,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IAEvB,OAAO,uBAAa,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,iBAAiB,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AAChF,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;AAC5E,kBAAe,cAAc,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Recursively scans the list of directories for files with one of the provided
3
+ * extensions.
4
+ *
5
+ * @param baseDirs Directories to search for files
6
+ * @param extensions List of valid extensions that files may have
7
+ */
8
+ export default function recursiveWalk(baseDirs: string[], extensions: string[]): Promise<string[]>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const util = require("util");
5
+ const path = require("path");
6
+ const readdirAsync = util.promisify(fs.readdir);
7
+ const statAsync = util.promisify(fs.stat);
8
+ /**
9
+ * Recursively scans the list of directories for files with one of the provided
10
+ * extensions.
11
+ *
12
+ * @param baseDirs Directories to search for files
13
+ * @param extensions List of valid extensions that files may have
14
+ */
15
+ async function recursiveWalk(baseDirs, extensions) {
16
+ // We put the results in a set to ensure there are no duplicates
17
+ const results = new Set();
18
+ await Promise.all(baseDirs.map(async (baseDir) => {
19
+ const files = await recursiveWalkInternal(path.resolve(baseDir), new RegExp(`\\.${extensions.map(ext => `(?:${ext})`).join('|')}$`, 'i'));
20
+ for (const file of files) {
21
+ results.add(file);
22
+ }
23
+ }));
24
+ return [...results];
25
+ }
26
+ exports.default = recursiveWalk;
27
+ /**
28
+ * Recursively walk the filesystem to find files with the proper extensions.
29
+ *
30
+ * @param baseDir The fully resolved starting directory (absolute path)
31
+ * @param extensionRegex Regular expression to verify the file extension
32
+ * @param maxDepth The maximum number of recursive calls to make before stopping
33
+ */
34
+ async function recursiveWalkInternal(baseDir, extensionRegex, maxDepth = 10) {
35
+ if (maxDepth <= 0) {
36
+ return [];
37
+ }
38
+ let entries;
39
+ try {
40
+ entries = await readdirAsync(baseDir);
41
+ }
42
+ catch (_a) {
43
+ return [];
44
+ }
45
+ // We collect the results up in this array as we find them rather than
46
+ // mapping/reducing the data to avoid the cost of creating and concatenating
47
+ // intermediate arrays.
48
+ const results = [];
49
+ await Promise.all(entries.map(async (entry) => {
50
+ const entryPath = path.join(baseDir, entry);
51
+ let stats;
52
+ try {
53
+ stats = await statAsync(entryPath);
54
+ }
55
+ catch (_a) {
56
+ return;
57
+ }
58
+ if (stats.isFile() && extensionRegex.test(entryPath)) {
59
+ results.push(entryPath);
60
+ }
61
+ else if (stats.isDirectory()) {
62
+ results.push(...await recursiveWalkInternal(entryPath, extensionRegex, maxDepth - 1));
63
+ }
64
+ }));
65
+ return results;
66
+ }
67
+ //# sourceMappingURL=recursiveWalk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recursiveWalk.js","sourceRoot":"","sources":["../src/recursiveWalk.ts"],"names":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AO,GAAa,EAAE,CAAC;IAE7B,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAC,KAAK,EAAC,EAAE;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5C,IAAI,KAAe,CAAC;QACpB,IAAI;YACA,KAAK,GAAG,MAAM,SAAS,CAAC,SAAS,CAAC,CAAC;SACtC;QAAC,WAAM;YACJ,OAAO;SACV;QAED,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YAClD,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC3B;aAAM,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE;YAC5B,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,qBAAqB,CACvC,SAAS,EACT,cAAc,EACd,QAAQ,GAAG,CAAC,CACf,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC,CAAC;IAEJ,OAAO,OAAO,CAAC;AACnB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@ohos-ports/get-system-fonts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.2-beta.0",
4
+ "description": "List full paths to all system fonts",
5
+ "homepage": "https://github.com/princjef/get-system-fonts#readme",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/ohos-ports/ohos-ports.git",
9
+ "directory": "ports/get-system-fonts/2.0.2"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
13
+ },
14
+ "engines": {
15
+ "node": ">8.0.0"
16
+ },
17
+ "main": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "keywords": [
20
+ "font",
21
+ "system",
22
+ "ttf",
23
+ "otf",
24
+ "file"
25
+ ],
26
+ "author": "Jeff Principe <princjef@gmail.com>",
27
+ "license": "MIT",
28
+ "dependencies": {},
29
+ "files": [
30
+ "dist",
31
+ "LICENSE.md",
32
+ "README.md",
33
+ "CHANGELOG.md"
34
+ ]
35
+ }