Skip to content

Commit

Permalink
make sure that sanctuary-def will run without "util" module
Browse files Browse the repository at this point in the history
Fix so sanctuary-def can be used in CommonJS enviroments that does
not have the `util` module, such as scrimba.com.

Here is an example with sanctuary-def 0.22.0:
https://scrimba.com/scrim/cQGBN6cM

The def test "returns a function with "inspect" and "@@show" methods"
fails with the default `util` object but I guess you already know
that.
  • Loading branch information
dotnetCarpenter committed Jun 15, 2021
1 parent 5dba5e3 commit 8dd9356
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,19 @@

var util = {inspect: {}};

function alt(a, f) {
try {
return f ();
} catch (e) {
/* istanbul ignore next */
return a;
}
}

/* istanbul ignore else */
if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = f (require ('util'),
module.exports = f (
alt (util, function() { return require ('util'); }),
require ('sanctuary-either'),
require ('sanctuary-show'),
require ('sanctuary-type-classes'),
Expand Down

0 comments on commit 8dd9356

Please sign in to comment.