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 resolvePackage(id, paths) {
|
22 | return require.resolve(id, paths);
|
23 | }
|
24 | exports.resolvePackage = resolvePackage;
|
25 | function loadJSON(path) {
|
26 | debug('loadJSON %s', path);
|
27 |
|
28 |
|
29 |
|
30 | return new Promise((resolve, reject) => {
|
31 | fs.readFile(path, 'utf8', (err, d) => {
|
32 | try {
|
33 | if (err)
|
34 | reject(err);
|
35 | else
|
36 | resolve(JSON.parse(d));
|
37 | }
|
38 | catch (error) {
|
39 | reject(error);
|
40 | }
|
41 | });
|
42 | });
|
43 | }
|
44 | exports.loadJSON = loadJSON;
|
45 | function compact(a) {
|
46 | return a.filter((a) => Boolean(a));
|
47 | }
|
48 | exports.compact = compact;
|
49 | function uniq(arr) {
|
50 | return arr.filter((a, i) => {
|
51 | return !arr.find((b, j) => j > i && b === a);
|
52 | });
|
53 | }
|
54 | exports.uniq = uniq;
|