Files: 4f27567900a7b5b821bccc74e95bfc96c8233159 / node_modules / readable-stream / errors-browser.js
4197 bytesRaw
1 | ; |
2 | |
3 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } |
4 | |
5 | var codes = {}; |
6 | |
7 | function createErrorType(code, message, Base) { |
8 | if (!Base) { |
9 | Base = Error; |
10 | } |
11 | |
12 | function getMessage(arg1, arg2, arg3) { |
13 | if (typeof message === 'string') { |
14 | return message; |
15 | } else { |
16 | return message(arg1, arg2, arg3); |
17 | } |
18 | } |
19 | |
20 | var NodeError = |
21 | /*#__PURE__*/ |
22 | function (_Base) { |
23 | _inheritsLoose(NodeError, _Base); |
24 | |
25 | function NodeError(arg1, arg2, arg3) { |
26 | return _Base.call(this, getMessage(arg1, arg2, arg3)) || this; |
27 | } |
28 | |
29 | return NodeError; |
30 | }(Base); |
31 | |
32 | NodeError.prototype.name = Base.name; |
33 | NodeError.prototype.code = code; |
34 | codes[code] = NodeError; |
35 | } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js |
36 | |
37 | |
38 | function oneOf(expected, thing) { |
39 | if (Array.isArray(expected)) { |
40 | var len = expected.length; |
41 | expected = expected.map(function (i) { |
42 | return String(i); |
43 | }); |
44 | |
45 | if (len > 2) { |
46 | return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1]; |
47 | } else if (len === 2) { |
48 | return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]); |
49 | } else { |
50 | return "of ".concat(thing, " ").concat(expected[0]); |
51 | } |
52 | } else { |
53 | return "of ".concat(thing, " ").concat(String(expected)); |
54 | } |
55 | } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith |
56 | |
57 | |
58 | function startsWith(str, search, pos) { |
59 | return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search; |
60 | } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith |
61 | |
62 | |
63 | function endsWith(str, search, this_len) { |
64 | if (this_len === undefined || this_len > str.length) { |
65 | this_len = str.length; |
66 | } |
67 | |
68 | return str.substring(this_len - search.length, this_len) === search; |
69 | } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes |
70 | |
71 | |
72 | function includes(str, search, start) { |
73 | if (typeof start !== 'number') { |
74 | start = 0; |
75 | } |
76 | |
77 | if (start + search.length > str.length) { |
78 | return false; |
79 | } else { |
80 | return str.indexOf(search, start) !== -1; |
81 | } |
82 | } |
83 | |
84 | createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) { |
85 | return 'The value "' + value + '" is invalid for option "' + name + '"'; |
86 | }, TypeError); |
87 | createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) { |
88 | // determiner: 'must be' or 'must not be' |
89 | var determiner; |
90 | |
91 | if (typeof expected === 'string' && startsWith(expected, 'not ')) { |
92 | determiner = 'must not be'; |
93 | expected = expected.replace(/^not /, ''); |
94 | } else { |
95 | determiner = 'must be'; |
96 | } |
97 | |
98 | var msg; |
99 | |
100 | if (endsWith(name, ' argument')) { |
101 | // For cases like 'first argument' |
102 | msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type')); |
103 | } else { |
104 | var type = includes(name, '.') ? 'property' : 'argument'; |
105 | msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type')); |
106 | } |
107 | |
108 | msg += ". Received type ".concat(typeof actual); |
109 | return msg; |
110 | }, TypeError); |
111 | createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF'); |
112 | createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) { |
113 | return 'The ' + name + ' method is not implemented'; |
114 | }); |
115 | createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close'); |
116 | createErrorType('ERR_STREAM_DESTROYED', function (name) { |
117 | return 'Cannot call ' + name + ' after a stream was destroyed'; |
118 | }); |
119 | createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times'); |
120 | createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable'); |
121 | createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end'); |
122 | createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError); |
123 | createErrorType('ERR_UNKNOWN_ENCODING', function (arg) { |
124 | return 'Unknown encoding: ' + arg; |
125 | }, TypeError); |
126 | createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event'); |
127 | module.exports.codes = codes; |
128 |
Built with git-ssb-web