const fm = require('font-manager'); var fonts = fm.getAvailableFontsSync();
const fm = require('font-manager'); var fonts = fm.getAvailableFontsSync(); object_array_sort(fonts, 'family', 'asc', function(fonts_sorted){ console.log(fonts_sorted); //fonts_sortedに整理されたフォントが入る }); function object_array_sort(data,key,order,fn){ //デフォは降順(DESC) var num_a = -1; var num_b = 1; if(order === 'asc'){//指定があれば昇順(ASC) num_a = 1; num_b = -1; } data = data.sort(function(a, b){ var x = a[key]; var y = b[key]; if (x > y) return num_a; if (x < y) return num_b; return 0; }); //重複排除 var arrObj = {}; for (var i = 0; i < data.length; i++) { arrObj[data[i]['family']] = data[i]; } data = []; for (var key in arrObj) { data.push(arrObj[key]); } fn(data); // ソート後の配列を返す }