-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
41 lines (33 loc) · 857 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* @author oldj
* @blog http://oldj.net
*/
'use strict'
const standardize = require('./libs/standardize')
const platform = process.platform
let getFontsFunc
switch (platform) {
case 'darwin':
getFontsFunc = require('./libs/darwin')
break
case 'win32':
getFontsFunc = require('./libs/win32')
break
case 'linux':
getFontsFunc = require('./libs/linux')
break
default:
throw new Error(`Error: font-list can not run on ${platform}.`)
}
const defaultOptions = {
disableQuoting: false
}
exports.getFonts = async (options) => {
options = Object.assign({}, defaultOptions, options)
let fonts = await getFontsFunc()
fonts = standardize(fonts, options)
fonts.sort((a, b) => {
return a.replace(/^['"]+/, '').toLocaleLowerCase() < b.replace(/^['"]+/, '').toLocaleLowerCase() ? -1 : 1
})
return fonts
}