1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", { value: true });
|
8 | const S = require("sanctuary");
|
9 | const Future = require("fluture");
|
10 | const fs = require("fs");
|
11 | const which = require("which");
|
12 | const $ = require("sanctuary-def");
|
13 |
|
14 | exports.safeWhich = Future.encase(which.sync);
|
15 | exports.safeRealpath = Future.encase(fs.realpathSync);
|
16 | function safeImport(fileName) {
|
17 | let moduleObj = null;
|
18 | try {
|
19 | moduleObj = require(fileName);
|
20 | }
|
21 | catch (e) {
|
22 | return e.code === 'MODULE_NOT_FOUND' ? Future.of(fileName) : Future.reject(e);
|
23 | }
|
24 | return Future.of(moduleObj);
|
25 | }
|
26 | exports.safeImport = safeImport;
|
27 | exports.safeReaddir = Future.encaseN(fs.readdir);
|
28 |
|
29 |
|
30 | function maybeFnToEither(monadReturningFunction) {
|
31 | return function convertMaybe(val) {
|
32 | const result = monadReturningFunction(val);
|
33 | return S.isJust(result) ? S.Right(result.value) : S.Left(null);
|
34 | };
|
35 | }
|
36 | exports.maybeFnToEither = maybeFnToEither;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | exports.prepend = (a) => (b) => {
|
42 | const argsAreStrings = typeof a === 'string' && typeof b === 'string';
|
43 | return argsAreStrings ? Future.of(a + b) : Future.reject('Both args should be strings');
|
44 | };
|
45 |
|
46 | exports.isObject = S.is($.Object);
|
47 |
|
48 | exports.l = x => {
|
49 | console.log('!!!!!!!', x);
|
50 | return x;
|
51 | };
|
52 |
|
53 | exports.lf = x => {
|
54 | console.log('-------', x);
|
55 | return Future.of(x);
|
56 | };
|
57 |
|
\ | No newline at end of file |