source: trip-planner-front/node_modules/readable-stream/errors-browser.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.1 KB
Line 
1'use strict';
2
3function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
4
5var codes = {};
6
7function 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
38function 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
58function 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
63function 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
72function 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
84createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
85 return 'The value "' + value + '" is invalid for option "' + name + '"';
86}, TypeError);
87createErrorType('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);
111createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
112createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
113 return 'The ' + name + ' method is not implemented';
114});
115createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
116createErrorType('ERR_STREAM_DESTROYED', function (name) {
117 return 'Cannot call ' + name + ' after a stream was destroyed';
118});
119createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
120createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
121createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
122createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
123createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
124 return 'Unknown encoding: ' + arg;
125}, TypeError);
126createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
127module.exports.codes = codes;
Note: See TracBrowser for help on using the repository browser.