sanctuary-js / sanctuary-def

Run-time type system for JavaScript
MIT License
294 stars 23 forks source link

make sure that sanctuary-def will run without "util" module #301

Closed dotnetCarpenter closed 3 years ago

dotnetCarpenter commented 3 years ago

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.

This will hopefully fix issue #300 but I guess the only way to know for sure is to publish and test it out on scrimba.com.

dotnetCarpenter commented 3 years ago

Closing in favour of:

    wrapped.toString = always0 (typeSignature (typeInfo));

    // Node.js
    if (
      typeof process === 'object' &&
      process != null &&
      process.versions != null &&
      process.versions.node != null
    ) wrapped[Symbol.for('nodejs.util.inspect.custom')] = wrapped.toString;

    // Deno
    if (
      typeof Deno !== 'undefined' &&
      Deno != null &&
      typeof Deno.customInspect === 'symbol'
    ) wrapped[Deno.customInspect] = wrapped.toString;