UNPKG

915 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3// tslint:disable no-implicit-dependencies
4const fs = require("fs");
5function flatMap(arr, fn) {
6 return arr.reduce((arr, i) => arr.concat(fn(i)), []);
7}
8exports.flatMap = flatMap;
9function mapValues(obj, fn) {
10 return Object.entries(obj)
11 .reduce((o, [k, v]) => {
12 o[k] = fn(v, k);
13 return o;
14 }, {});
15}
16exports.mapValues = mapValues;
17function loadJSONSync(path) {
18 let loadJSON;
19 try {
20 loadJSON = require('load-json-file');
21 }
22 catch (_a) { }
23 if (loadJSON)
24 return loadJSON.sync(path);
25 return JSON.parse(fs.readFileSync(path, 'utf8'));
26}
27exports.loadJSONSync = loadJSONSync;
28function compact(a) {
29 return a.filter((a) => !!a);
30}
31exports.compact = compact;
32function uniq(arr) {
33 return arr.filter((a, i) => arr.findIndex(b => b === a) === i);
34}
35exports.uniq = uniq;