'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.maybeSetModuleExports = void 0;
var tslib_1 = require("tslib");
var types_1 = tslib_1.__importDefault(require("./types"));
function default_1(fork) {
    var types = fork.use(types_1.default);
    var Type = types.Type;
    var builtin = types.builtInTypes;
    var isNumber = builtin.number;
    // An example of constructing a new type with arbitrary constraints from
    // an existing type.
    function geq(than) {
        return Type.from(function (value) { return isNumber.check(value) && value >= than; }, isNumber + " >= " + than);
    }
    ;
    // Default value-returning functions that may optionally be passed as a
    // third argument to Def.prototype.field.
    var defaults = {
        // Functions were used because (among other reasons) that's the most
        // elegant way to allow for the emptyArray one always to give a new
        // array instance.
        "null": function () { return null; },
        "emptyArray": function () { return []; },
        "false": function () { return false; },
        "true": function () { return true; },
        "undefined": function () { },
        "use strict": function () { return "use strict"; }
    };
    var naiveIsPrimitive = Type.or(builtin.string, builtin.number, builtin.boolean, builtin.null, builtin.undefined);
    var isPrimitive = Type.from(function (value) {
        if (value === null)
            return true;
        var type = typeof value;
        if (type === "object" ||
            type === "function") {
            return false;
        }
        return true;
    }, naiveIsPrimitive.toString());
    return {
        geq: geq,
        defaults: defaults,
        isPrimitive: isPrimitive,
    };
}
exports.default = default_1;
;
// This function accepts a getter function that should return an object
// conforming to the NodeModule interface above. Typically, this means calling
// maybeSetModuleExports(() => module) at the very end of any module that has a
// default export, so the default export value can replace module.exports and
// thus CommonJS consumers can continue to rely on require("./that/module")
// returning the default-exported value, rather than always returning an exports
// object with a default property equal to that value. This function should help
// preserve backwards compatibility for CommonJS consumers, as a replacement for
// the ts-add-module-exports package.
function maybeSetModuleExports(moduleGetter) {
    try {
        var nodeModule = moduleGetter();
        var originalExports = nodeModule.exports;
        var defaultExport = originalExports["default"];
    }
    catch (_a) {
        // It's normal/acceptable for this code to throw a ReferenceError due to
        // the moduleGetter function attempting to access a non-existent global
        // `module` variable. That's the reason we use a getter function here:
        // so the calling code doesn't have to do its own typeof module ===
        // "object" checking (because it's always safe to pass `() => module` as
        // an argument, even when `module` is not defined in the calling scope).
        return;
    }
    if (defaultExport &&
        defaultExport !== originalExports &&
        typeof originalExports === "object") {
        // Make all properties found in originalExports properties of the
        // default export, including the default property itself, so that
        // require(nodeModule.id).default === require(nodeModule.id).
        Object.assign(defaultExport, originalExports, { "default": defaultExport });
        // Object.assign only transfers enumerable properties, and
        // __esModule is (and should remain) non-enumerable.
        if (originalExports.__esModule) {
            Object.defineProperty(defaultExport, "__esModule", { value: true });
        }
        // This line allows require(nodeModule.id) === defaultExport, rather
        // than (only) require(nodeModule.id).default === defaultExport.
        nodeModule.exports = defaultExport;
    }
}
exports.maybeSetModuleExports = maybeSetModuleExports;
//# sourceMappingURL=shared.js.map