1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 | const fs = require("fs");
|
5 | const debug = require('debug')('@oclif/config');
|
6 | function flatMap(arr, fn) {
|
7 | return arr.reduce((arr, i) => arr.concat(fn(i)), []);
|
8 | }
|
9 | exports.flatMap = flatMap;
|
10 | function mapValues(obj, fn) {
|
11 | return Object.entries(obj)
|
12 | .reduce((o, [k, v]) => {
|
13 | o[k] = fn(v, k);
|
14 | return o;
|
15 | }, {});
|
16 | }
|
17 | exports.mapValues = mapValues;
|
18 | function loadJSONSync(path) {
|
19 | debug('loadJSONSync %s', path);
|
20 |
|
21 |
|
22 |
|
23 | return JSON.parse(fs.readFileSync(path, 'utf8'));
|
24 | }
|
25 | exports.loadJSONSync = loadJSONSync;
|
26 | function exists(path) {
|
27 |
|
28 | return new Promise(resolve => fs.exists(path, resolve));
|
29 | }
|
30 | exports.exists = exists;
|
31 | function loadJSON(path) {
|
32 | debug('loadJSON %s', path);
|
33 |
|
34 |
|
35 |
|
36 | return new Promise((resolve, reject) => {
|
37 | fs.readFile(path, 'utf8', (err, d) => {
|
38 | try {
|
39 | if (err)
|
40 | reject(err);
|
41 | else
|
42 | resolve(JSON.parse(d));
|
43 | }
|
44 | catch (err) {
|
45 | reject(err);
|
46 | }
|
47 | });
|
48 | });
|
49 | }
|
50 | exports.loadJSON = loadJSON;
|
51 | function compact(a) {
|
52 | return a.filter((a) => !!a);
|
53 | }
|
54 | exports.compact = compact;
|
55 | function uniq(arr) {
|
56 | return arr.filter((a, i) => {
|
57 | return !arr.find((b, j) => j > i && b === a);
|
58 | });
|
59 | }
|
60 | exports.uniq = uniq;
|