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