Node-Red configuration
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. var hasMap = typeof Map === 'function' && Map.prototype;
  2. var mapSizeDescriptor = Object.getOwnPropertyDescriptor && hasMap ? Object.getOwnPropertyDescriptor(Map.prototype, 'size') : null;
  3. var mapSize = hasMap && mapSizeDescriptor && typeof mapSizeDescriptor.get === 'function' ? mapSizeDescriptor.get : null;
  4. var mapForEach = hasMap && Map.prototype.forEach;
  5. var hasSet = typeof Set === 'function' && Set.prototype;
  6. var setSizeDescriptor = Object.getOwnPropertyDescriptor && hasSet ? Object.getOwnPropertyDescriptor(Set.prototype, 'size') : null;
  7. var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'function' ? setSizeDescriptor.get : null;
  8. var setForEach = hasSet && Set.prototype.forEach;
  9. var hasWeakMap = typeof WeakMap === 'function' && WeakMap.prototype;
  10. var weakMapHas = hasWeakMap ? WeakMap.prototype.has : null;
  11. var hasWeakSet = typeof WeakSet === 'function' && WeakSet.prototype;
  12. var weakSetHas = hasWeakSet ? WeakSet.prototype.has : null;
  13. var hasWeakRef = typeof WeakRef === 'function' && WeakRef.prototype;
  14. var weakRefDeref = hasWeakRef ? WeakRef.prototype.deref : null;
  15. var booleanValueOf = Boolean.prototype.valueOf;
  16. var objectToString = Object.prototype.toString;
  17. var functionToString = Function.prototype.toString;
  18. var $match = String.prototype.match;
  19. var $slice = String.prototype.slice;
  20. var $replace = String.prototype.replace;
  21. var $toUpperCase = String.prototype.toUpperCase;
  22. var $toLowerCase = String.prototype.toLowerCase;
  23. var $test = RegExp.prototype.test;
  24. var $concat = Array.prototype.concat;
  25. var $join = Array.prototype.join;
  26. var $arrSlice = Array.prototype.slice;
  27. var $floor = Math.floor;
  28. var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null;
  29. var gOPS = Object.getOwnPropertySymbols;
  30. var symToString = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? Symbol.prototype.toString : null;
  31. var hasShammedSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'object';
  32. // ie, `has-tostringtag/shams
  33. var toStringTag = typeof Symbol === 'function' && Symbol.toStringTag && (typeof Symbol.toStringTag === hasShammedSymbols ? 'object' : 'symbol')
  34. ? Symbol.toStringTag
  35. : null;
  36. var isEnumerable = Object.prototype.propertyIsEnumerable;
  37. var gPO = (typeof Reflect === 'function' ? Reflect.getPrototypeOf : Object.getPrototypeOf) || (
  38. [].__proto__ === Array.prototype // eslint-disable-line no-proto
  39. ? function (O) {
  40. return O.__proto__; // eslint-disable-line no-proto
  41. }
  42. : null
  43. );
  44. function addNumericSeparator(num, str) {
  45. if (
  46. num === Infinity
  47. || num === -Infinity
  48. || num !== num
  49. || (num && num > -1000 && num < 1000)
  50. || $test.call(/e/, str)
  51. ) {
  52. return str;
  53. }
  54. var sepRegex = /[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;
  55. if (typeof num === 'number') {
  56. var int = num < 0 ? -$floor(-num) : $floor(num); // trunc(num)
  57. if (int !== num) {
  58. var intStr = String(int);
  59. var dec = $slice.call(str, intStr.length + 1);
  60. return $replace.call(intStr, sepRegex, '$&_') + '.' + $replace.call($replace.call(dec, /([0-9]{3})/g, '$&_'), /_$/, '');
  61. }
  62. }
  63. return $replace.call(str, sepRegex, '$&_');
  64. }
  65. var utilInspect = require('./util.inspect');
  66. var inspectCustom = utilInspect.custom;
  67. var inspectSymbol = isSymbol(inspectCustom) ? inspectCustom : null;
  68. module.exports = function inspect_(obj, options, depth, seen) {
  69. var opts = options || {};
  70. if (has(opts, 'quoteStyle') && (opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double')) {
  71. throw new TypeError('option "quoteStyle" must be "single" or "double"');
  72. }
  73. if (
  74. has(opts, 'maxStringLength') && (typeof opts.maxStringLength === 'number'
  75. ? opts.maxStringLength < 0 && opts.maxStringLength !== Infinity
  76. : opts.maxStringLength !== null
  77. )
  78. ) {
  79. throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');
  80. }
  81. var customInspect = has(opts, 'customInspect') ? opts.customInspect : true;
  82. if (typeof customInspect !== 'boolean' && customInspect !== 'symbol') {
  83. throw new TypeError('option "customInspect", if provided, must be `true`, `false`, or `\'symbol\'`');
  84. }
  85. if (
  86. has(opts, 'indent')
  87. && opts.indent !== null
  88. && opts.indent !== '\t'
  89. && !(parseInt(opts.indent, 10) === opts.indent && opts.indent > 0)
  90. ) {
  91. throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');
  92. }
  93. if (has(opts, 'numericSeparator') && typeof opts.numericSeparator !== 'boolean') {
  94. throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');
  95. }
  96. var numericSeparator = opts.numericSeparator;
  97. if (typeof obj === 'undefined') {
  98. return 'undefined';
  99. }
  100. if (obj === null) {
  101. return 'null';
  102. }
  103. if (typeof obj === 'boolean') {
  104. return obj ? 'true' : 'false';
  105. }
  106. if (typeof obj === 'string') {
  107. return inspectString(obj, opts);
  108. }
  109. if (typeof obj === 'number') {
  110. if (obj === 0) {
  111. return Infinity / obj > 0 ? '0' : '-0';
  112. }
  113. var str = String(obj);
  114. return numericSeparator ? addNumericSeparator(obj, str) : str;
  115. }
  116. if (typeof obj === 'bigint') {
  117. var bigIntStr = String(obj) + 'n';
  118. return numericSeparator ? addNumericSeparator(obj, bigIntStr) : bigIntStr;
  119. }
  120. var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;
  121. if (typeof depth === 'undefined') { depth = 0; }
  122. if (depth >= maxDepth && maxDepth > 0 && typeof obj === 'object') {
  123. return isArray(obj) ? '[Array]' : '[Object]';
  124. }
  125. var indent = getIndent(opts, depth);
  126. if (typeof seen === 'undefined') {
  127. seen = [];
  128. } else if (indexOf(seen, obj) >= 0) {
  129. return '[Circular]';
  130. }
  131. function inspect(value, from, noIndent) {
  132. if (from) {
  133. seen = $arrSlice.call(seen);
  134. seen.push(from);
  135. }
  136. if (noIndent) {
  137. var newOpts = {
  138. depth: opts.depth
  139. };
  140. if (has(opts, 'quoteStyle')) {
  141. newOpts.quoteStyle = opts.quoteStyle;
  142. }
  143. return inspect_(value, newOpts, depth + 1, seen);
  144. }
  145. return inspect_(value, opts, depth + 1, seen);
  146. }
  147. if (typeof obj === 'function' && !isRegExp(obj)) { // in older engines, regexes are callable
  148. var name = nameOf(obj);
  149. var keys = arrObjKeys(obj, inspect);
  150. return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + $join.call(keys, ', ') + ' }' : '');
  151. }
  152. if (isSymbol(obj)) {
  153. var symString = hasShammedSymbols ? $replace.call(String(obj), /^(Symbol\(.*\))_[^)]*$/, '$1') : symToString.call(obj);
  154. return typeof obj === 'object' && !hasShammedSymbols ? markBoxed(symString) : symString;
  155. }
  156. if (isElement(obj)) {
  157. var s = '<' + $toLowerCase.call(String(obj.nodeName));
  158. var attrs = obj.attributes || [];
  159. for (var i = 0; i < attrs.length; i++) {
  160. s += ' ' + attrs[i].name + '=' + wrapQuotes(quote(attrs[i].value), 'double', opts);
  161. }
  162. s += '>';
  163. if (obj.childNodes && obj.childNodes.length) { s += '...'; }
  164. s += '</' + $toLowerCase.call(String(obj.nodeName)) + '>';
  165. return s;
  166. }
  167. if (isArray(obj)) {
  168. if (obj.length === 0) { return '[]'; }
  169. var xs = arrObjKeys(obj, inspect);
  170. if (indent && !singleLineValues(xs)) {
  171. return '[' + indentedJoin(xs, indent) + ']';
  172. }
  173. return '[ ' + $join.call(xs, ', ') + ' ]';
  174. }
  175. if (isError(obj)) {
  176. var parts = arrObjKeys(obj, inspect);
  177. if (!('cause' in Error.prototype) && 'cause' in obj && !isEnumerable.call(obj, 'cause')) {
  178. return '{ [' + String(obj) + '] ' + $join.call($concat.call('[cause]: ' + inspect(obj.cause), parts), ', ') + ' }';
  179. }
  180. if (parts.length === 0) { return '[' + String(obj) + ']'; }
  181. return '{ [' + String(obj) + '] ' + $join.call(parts, ', ') + ' }';
  182. }
  183. if (typeof obj === 'object' && customInspect) {
  184. if (inspectSymbol && typeof obj[inspectSymbol] === 'function' && utilInspect) {
  185. return utilInspect(obj, { depth: maxDepth - depth });
  186. } else if (customInspect !== 'symbol' && typeof obj.inspect === 'function') {
  187. return obj.inspect();
  188. }
  189. }
  190. if (isMap(obj)) {
  191. var mapParts = [];
  192. if (mapForEach) {
  193. mapForEach.call(obj, function (value, key) {
  194. mapParts.push(inspect(key, obj, true) + ' => ' + inspect(value, obj));
  195. });
  196. }
  197. return collectionOf('Map', mapSize.call(obj), mapParts, indent);
  198. }
  199. if (isSet(obj)) {
  200. var setParts = [];
  201. if (setForEach) {
  202. setForEach.call(obj, function (value) {
  203. setParts.push(inspect(value, obj));
  204. });
  205. }
  206. return collectionOf('Set', setSize.call(obj), setParts, indent);
  207. }
  208. if (isWeakMap(obj)) {
  209. return weakCollectionOf('WeakMap');
  210. }
  211. if (isWeakSet(obj)) {
  212. return weakCollectionOf('WeakSet');
  213. }
  214. if (isWeakRef(obj)) {
  215. return weakCollectionOf('WeakRef');
  216. }
  217. if (isNumber(obj)) {
  218. return markBoxed(inspect(Number(obj)));
  219. }
  220. if (isBigInt(obj)) {
  221. return markBoxed(inspect(bigIntValueOf.call(obj)));
  222. }
  223. if (isBoolean(obj)) {
  224. return markBoxed(booleanValueOf.call(obj));
  225. }
  226. if (isString(obj)) {
  227. return markBoxed(inspect(String(obj)));
  228. }
  229. // note: in IE 8, sometimes `global !== window` but both are the prototypes of each other
  230. /* eslint-env browser */
  231. if (typeof window !== 'undefined' && obj === window) {
  232. return '{ [object Window] }';
  233. }
  234. if (
  235. (typeof globalThis !== 'undefined' && obj === globalThis)
  236. || (typeof global !== 'undefined' && obj === global)
  237. ) {
  238. return '{ [object globalThis] }';
  239. }
  240. if (!isDate(obj) && !isRegExp(obj)) {
  241. var ys = arrObjKeys(obj, inspect);
  242. var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object;
  243. var protoTag = obj instanceof Object ? '' : 'null prototype';
  244. var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? $slice.call(toStr(obj), 8, -1) : protoTag ? 'Object' : '';
  245. var constructorTag = isPlainObject || typeof obj.constructor !== 'function' ? '' : obj.constructor.name ? obj.constructor.name + ' ' : '';
  246. var tag = constructorTag + (stringTag || protoTag ? '[' + $join.call($concat.call([], stringTag || [], protoTag || []), ': ') + '] ' : '');
  247. if (ys.length === 0) { return tag + '{}'; }
  248. if (indent) {
  249. return tag + '{' + indentedJoin(ys, indent) + '}';
  250. }
  251. return tag + '{ ' + $join.call(ys, ', ') + ' }';
  252. }
  253. return String(obj);
  254. };
  255. function wrapQuotes(s, defaultStyle, opts) {
  256. var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'";
  257. return quoteChar + s + quoteChar;
  258. }
  259. function quote(s) {
  260. return $replace.call(String(s), /"/g, '&quot;');
  261. }
  262. function isArray(obj) { return toStr(obj) === '[object Array]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
  263. function isDate(obj) { return toStr(obj) === '[object Date]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
  264. function isRegExp(obj) { return toStr(obj) === '[object RegExp]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
  265. function isError(obj) { return toStr(obj) === '[object Error]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
  266. function isString(obj) { return toStr(obj) === '[object String]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
  267. function isNumber(obj) { return toStr(obj) === '[object Number]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
  268. function isBoolean(obj) { return toStr(obj) === '[object Boolean]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
  269. // Symbol and BigInt do have Symbol.toStringTag by spec, so that can't be used to eliminate false positives
  270. function isSymbol(obj) {
  271. if (hasShammedSymbols) {
  272. return obj && typeof obj === 'object' && obj instanceof Symbol;
  273. }
  274. if (typeof obj === 'symbol') {
  275. return true;
  276. }
  277. if (!obj || typeof obj !== 'object' || !symToString) {
  278. return false;
  279. }
  280. try {
  281. symToString.call(obj);
  282. return true;
  283. } catch (e) {}
  284. return false;
  285. }
  286. function isBigInt(obj) {
  287. if (!obj || typeof obj !== 'object' || !bigIntValueOf) {
  288. return false;
  289. }
  290. try {
  291. bigIntValueOf.call(obj);
  292. return true;
  293. } catch (e) {}
  294. return false;
  295. }
  296. var hasOwn = Object.prototype.hasOwnProperty || function (key) { return key in this; };
  297. function has(obj, key) {
  298. return hasOwn.call(obj, key);
  299. }
  300. function toStr(obj) {
  301. return objectToString.call(obj);
  302. }
  303. function nameOf(f) {
  304. if (f.name) { return f.name; }
  305. var m = $match.call(functionToString.call(f), /^function\s*([\w$]+)/);
  306. if (m) { return m[1]; }
  307. return null;
  308. }
  309. function indexOf(xs, x) {
  310. if (xs.indexOf) { return xs.indexOf(x); }
  311. for (var i = 0, l = xs.length; i < l; i++) {
  312. if (xs[i] === x) { return i; }
  313. }
  314. return -1;
  315. }
  316. function isMap(x) {
  317. if (!mapSize || !x || typeof x !== 'object') {
  318. return false;
  319. }
  320. try {
  321. mapSize.call(x);
  322. try {
  323. setSize.call(x);
  324. } catch (s) {
  325. return true;
  326. }
  327. return x instanceof Map; // core-js workaround, pre-v2.5.0
  328. } catch (e) {}
  329. return false;
  330. }
  331. function isWeakMap(x) {
  332. if (!weakMapHas || !x || typeof x !== 'object') {
  333. return false;
  334. }
  335. try {
  336. weakMapHas.call(x, weakMapHas);
  337. try {
  338. weakSetHas.call(x, weakSetHas);
  339. } catch (s) {
  340. return true;
  341. }
  342. return x instanceof WeakMap; // core-js workaround, pre-v2.5.0
  343. } catch (e) {}
  344. return false;
  345. }
  346. function isWeakRef(x) {
  347. if (!weakRefDeref || !x || typeof x !== 'object') {
  348. return false;
  349. }
  350. try {
  351. weakRefDeref.call(x);
  352. return true;
  353. } catch (e) {}
  354. return false;
  355. }
  356. function isSet(x) {
  357. if (!setSize || !x || typeof x !== 'object') {
  358. return false;
  359. }
  360. try {
  361. setSize.call(x);
  362. try {
  363. mapSize.call(x);
  364. } catch (m) {
  365. return true;
  366. }
  367. return x instanceof Set; // core-js workaround, pre-v2.5.0
  368. } catch (e) {}
  369. return false;
  370. }
  371. function isWeakSet(x) {
  372. if (!weakSetHas || !x || typeof x !== 'object') {
  373. return false;
  374. }
  375. try {
  376. weakSetHas.call(x, weakSetHas);
  377. try {
  378. weakMapHas.call(x, weakMapHas);
  379. } catch (s) {
  380. return true;
  381. }
  382. return x instanceof WeakSet; // core-js workaround, pre-v2.5.0
  383. } catch (e) {}
  384. return false;
  385. }
  386. function isElement(x) {
  387. if (!x || typeof x !== 'object') { return false; }
  388. if (typeof HTMLElement !== 'undefined' && x instanceof HTMLElement) {
  389. return true;
  390. }
  391. return typeof x.nodeName === 'string' && typeof x.getAttribute === 'function';
  392. }
  393. function inspectString(str, opts) {
  394. if (str.length > opts.maxStringLength) {
  395. var remaining = str.length - opts.maxStringLength;
  396. var trailer = '... ' + remaining + ' more character' + (remaining > 1 ? 's' : '');
  397. return inspectString($slice.call(str, 0, opts.maxStringLength), opts) + trailer;
  398. }
  399. // eslint-disable-next-line no-control-regex
  400. var s = $replace.call($replace.call(str, /(['\\])/g, '\\$1'), /[\x00-\x1f]/g, lowbyte);
  401. return wrapQuotes(s, 'single', opts);
  402. }
  403. function lowbyte(c) {
  404. var n = c.charCodeAt(0);
  405. var x = {
  406. 8: 'b',
  407. 9: 't',
  408. 10: 'n',
  409. 12: 'f',
  410. 13: 'r'
  411. }[n];
  412. if (x) { return '\\' + x; }
  413. return '\\x' + (n < 0x10 ? '0' : '') + $toUpperCase.call(n.toString(16));
  414. }
  415. function markBoxed(str) {
  416. return 'Object(' + str + ')';
  417. }
  418. function weakCollectionOf(type) {
  419. return type + ' { ? }';
  420. }
  421. function collectionOf(type, size, entries, indent) {
  422. var joinedEntries = indent ? indentedJoin(entries, indent) : $join.call(entries, ', ');
  423. return type + ' (' + size + ') {' + joinedEntries + '}';
  424. }
  425. function singleLineValues(xs) {
  426. for (var i = 0; i < xs.length; i++) {
  427. if (indexOf(xs[i], '\n') >= 0) {
  428. return false;
  429. }
  430. }
  431. return true;
  432. }
  433. function getIndent(opts, depth) {
  434. var baseIndent;
  435. if (opts.indent === '\t') {
  436. baseIndent = '\t';
  437. } else if (typeof opts.indent === 'number' && opts.indent > 0) {
  438. baseIndent = $join.call(Array(opts.indent + 1), ' ');
  439. } else {
  440. return null;
  441. }
  442. return {
  443. base: baseIndent,
  444. prev: $join.call(Array(depth + 1), baseIndent)
  445. };
  446. }
  447. function indentedJoin(xs, indent) {
  448. if (xs.length === 0) { return ''; }
  449. var lineJoiner = '\n' + indent.prev + indent.base;
  450. return lineJoiner + $join.call(xs, ',' + lineJoiner) + '\n' + indent.prev;
  451. }
  452. function arrObjKeys(obj, inspect) {
  453. var isArr = isArray(obj);
  454. var xs = [];
  455. if (isArr) {
  456. xs.length = obj.length;
  457. for (var i = 0; i < obj.length; i++) {
  458. xs[i] = has(obj, i) ? inspect(obj[i], obj) : '';
  459. }
  460. }
  461. var syms = typeof gOPS === 'function' ? gOPS(obj) : [];
  462. var symMap;
  463. if (hasShammedSymbols) {
  464. symMap = {};
  465. for (var k = 0; k < syms.length; k++) {
  466. symMap['$' + syms[k]] = syms[k];
  467. }
  468. }
  469. for (var key in obj) { // eslint-disable-line no-restricted-syntax
  470. if (!has(obj, key)) { continue; } // eslint-disable-line no-restricted-syntax, no-continue
  471. if (isArr && String(Number(key)) === key && key < obj.length) { continue; } // eslint-disable-line no-restricted-syntax, no-continue
  472. if (hasShammedSymbols && symMap['$' + key] instanceof Symbol) {
  473. // this is to prevent shammed Symbols, which are stored as strings, from being included in the string key section
  474. continue; // eslint-disable-line no-restricted-syntax, no-continue
  475. } else if ($test.call(/[^\w$]/, key)) {
  476. xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj));
  477. } else {
  478. xs.push(key + ': ' + inspect(obj[key], obj));
  479. }
  480. }
  481. if (typeof gOPS === 'function') {
  482. for (var j = 0; j < syms.length; j++) {
  483. if (isEnumerable.call(obj, syms[j])) {
  484. xs.push('[' + inspect(syms[j]) + ']: ' + inspect(obj[syms[j]], obj));
  485. }
  486. }
  487. }
  488. return xs;
  489. }