1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ArgumentError = exports.AnyPredicate = exports.DataViewPredicate = exports.ArrayBufferPredicate = exports.TypedArrayPredicate = exports.WeakSetPredicate = exports.SetPredicate = exports.WeakMapPredicate = exports.MapPredicate = exports.ErrorPredicate = exports.DatePredicate = exports.ObjectPredicate = exports.ArrayPredicate = exports.BooleanPredicate = exports.NumberPredicate = exports.StringPredicate = exports.Predicate = void 0;
|
4 | const callsites_1 = require("callsites");
|
5 | const infer_label_1 = require("./utils/infer-label");
|
6 | const predicate_1 = require("./predicates/predicate");
|
7 | Object.defineProperty(exports, "Predicate", { enumerable: true, get: function () { return predicate_1.Predicate; } });
|
8 | const base_predicate_1 = require("./predicates/base-predicate");
|
9 | const modifiers_1 = require("./modifiers");
|
10 | const predicates_1 = require("./predicates");
|
11 | const test_1 = require("./test");
|
12 | const generate_stack_1 = require("./utils/generate-stack");
|
13 | const ow = (value, labelOrPredicate, predicate) => {
|
14 | const stack = generate_stack_1.generateStackTrace();
|
15 | if (!base_predicate_1.isPredicate(labelOrPredicate) && typeof labelOrPredicate !== 'string') {
|
16 | throw new TypeError(`Expected second argument to be a predicate or a string, got \`${typeof labelOrPredicate}\``);
|
17 | }
|
18 | if (base_predicate_1.isPredicate(labelOrPredicate)) {
|
19 |
|
20 | const stackFrames = callsites_1.default();
|
21 | test_1.default(value, () => infer_label_1.inferLabel(stackFrames), labelOrPredicate, stack);
|
22 | return;
|
23 | }
|
24 | test_1.default(value, labelOrPredicate, predicate, stack);
|
25 | };
|
26 | Object.defineProperties(ow, {
|
27 | isValid: {
|
28 | value: (value, predicate) => {
|
29 | try {
|
30 | ow(value, predicate);
|
31 | return true;
|
32 | }
|
33 | catch (_a) {
|
34 | return false;
|
35 | }
|
36 | }
|
37 | },
|
38 | create: {
|
39 | value: (labelOrPredicate, predicate) => (value, label) => {
|
40 | const stack = generate_stack_1.generateStackTrace();
|
41 | if (base_predicate_1.isPredicate(labelOrPredicate)) {
|
42 | const stackFrames = callsites_1.default();
|
43 | test_1.default(value, label !== null && label !== void 0 ? label : (() => infer_label_1.inferLabel(stackFrames)), labelOrPredicate, stack);
|
44 | return;
|
45 | }
|
46 | test_1.default(value, label !== null && label !== void 0 ? label : (labelOrPredicate), predicate, stack);
|
47 | }
|
48 | }
|
49 | });
|
50 |
|
51 |
|
52 |
|
53 | const _ow = predicates_1.default(modifiers_1.default(ow));
|
54 | exports.default = _ow;
|
55 | var predicates_2 = require("./predicates");
|
56 | Object.defineProperty(exports, "StringPredicate", { enumerable: true, get: function () { return predicates_2.StringPredicate; } });
|
57 | Object.defineProperty(exports, "NumberPredicate", { enumerable: true, get: function () { return predicates_2.NumberPredicate; } });
|
58 | Object.defineProperty(exports, "BooleanPredicate", { enumerable: true, get: function () { return predicates_2.BooleanPredicate; } });
|
59 | Object.defineProperty(exports, "ArrayPredicate", { enumerable: true, get: function () { return predicates_2.ArrayPredicate; } });
|
60 | Object.defineProperty(exports, "ObjectPredicate", { enumerable: true, get: function () { return predicates_2.ObjectPredicate; } });
|
61 | Object.defineProperty(exports, "DatePredicate", { enumerable: true, get: function () { return predicates_2.DatePredicate; } });
|
62 | Object.defineProperty(exports, "ErrorPredicate", { enumerable: true, get: function () { return predicates_2.ErrorPredicate; } });
|
63 | Object.defineProperty(exports, "MapPredicate", { enumerable: true, get: function () { return predicates_2.MapPredicate; } });
|
64 | Object.defineProperty(exports, "WeakMapPredicate", { enumerable: true, get: function () { return predicates_2.WeakMapPredicate; } });
|
65 | Object.defineProperty(exports, "SetPredicate", { enumerable: true, get: function () { return predicates_2.SetPredicate; } });
|
66 | Object.defineProperty(exports, "WeakSetPredicate", { enumerable: true, get: function () { return predicates_2.WeakSetPredicate; } });
|
67 | Object.defineProperty(exports, "TypedArrayPredicate", { enumerable: true, get: function () { return predicates_2.TypedArrayPredicate; } });
|
68 | Object.defineProperty(exports, "ArrayBufferPredicate", { enumerable: true, get: function () { return predicates_2.ArrayBufferPredicate; } });
|
69 | Object.defineProperty(exports, "DataViewPredicate", { enumerable: true, get: function () { return predicates_2.DataViewPredicate; } });
|
70 | Object.defineProperty(exports, "AnyPredicate", { enumerable: true, get: function () { return predicates_2.AnyPredicate; } });
|
71 | var argument_error_1 = require("./argument-error");
|
72 | Object.defineProperty(exports, "ArgumentError", { enumerable: true, get: function () { return argument_error_1.ArgumentError; } });
|