├── LICENSE ├── README.md ├── frontend.html ├── index.html ├── index1.html ├── subweb ├── sub-web-modify-one.zip └── sub-web-one.zip ├── worker-old.js └── worker.js /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 bulianglin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # psub 2 | 利用CF Worker搭建的反代订阅转换工具,通过随机化服务器地址和节点账号密码,解决用户转换订阅的隐私问题 3 | 4 | ### 演示网站 5 | https://psub.888005.xyz 6 | 7 | ### 视频教程 8 | https://youtu.be/X7CC5jrgazo 9 | 10 | 环境变量名:`BACKEND` 11 | 12 | KV或R2变量名:`SUB_BUCKET` 13 | 14 | ### 支持反代转换的协议 15 | - shadowsocks 16 | - shadowsocksR 17 | - vmess 18 | - trojan 19 | - vless(取决于后端) 20 | - hysteria(取决于后端) 21 | - hysteria2(取决于后端) 22 | 23 | ### 打赏 24 | 请我喝矿泉水:[全专线中专机场AFF链接](http://b.880805.xyz/) 25 | 26 | 请我喝桶装水:[搬瓦工美国CN2 GIA线路AFF链接](https://bwg.880805.xyz/) 27 | -------------------------------------------------------------------------------- /subweb/sub-web-modify-one.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aylz10/psub/3f1db2201ade6e847041f53bc6fcd460e0a87d56/subweb/sub-web-modify-one.zip -------------------------------------------------------------------------------- /subweb/sub-web-one.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aylz10/psub/3f1db2201ade6e847041f53bc6fcd460e0a87d56/subweb/sub-web-one.zip -------------------------------------------------------------------------------- /worker-old.js: -------------------------------------------------------------------------------- 1 | var __getOwnPropNames = Object.getOwnPropertyNames; 2 | var __esm = (fn, res) => function __init() { 3 | return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; 4 | }; 5 | var __commonJS = (cb, mod) => function __require() { 6 | return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; 7 | }; 8 | 9 | // wrangler-modules-watch:wrangler:modules-watch 10 | var init_wrangler_modules_watch = __esm({ 11 | "wrangler-modules-watch:wrangler:modules-watch"() { 12 | init_modules_watch_stub(); 13 | } 14 | }); 15 | 16 | // C:/Users/WIN/AppData/Roaming/npm/node_modules/wrangler/templates/modules-watch-stub.js 17 | var init_modules_watch_stub = __esm({ 18 | "C:/Users/WIN/AppData/Roaming/npm/node_modules/wrangler/templates/modules-watch-stub.js"() { 19 | init_wrangler_modules_watch(); 20 | } 21 | }); 22 | 23 | // node_modules/js-yaml/lib/common.js 24 | var require_common = __commonJS({ 25 | "node_modules/js-yaml/lib/common.js"(exports, module) { 26 | "use strict"; 27 | init_modules_watch_stub(); 28 | function isNothing(subject) { 29 | return typeof subject === "undefined" || subject === null; 30 | } 31 | function isObject(subject) { 32 | return typeof subject === "object" && subject !== null; 33 | } 34 | function toArray(sequence) { 35 | if (Array.isArray(sequence)) 36 | return sequence; 37 | else if (isNothing(sequence)) 38 | return []; 39 | return [sequence]; 40 | } 41 | function extend(target, source) { 42 | var index, length, key, sourceKeys; 43 | if (source) { 44 | sourceKeys = Object.keys(source); 45 | for (index = 0, length = sourceKeys.length; index < length; index += 1) { 46 | key = sourceKeys[index]; 47 | target[key] = source[key]; 48 | } 49 | } 50 | return target; 51 | } 52 | function repeat(string, count) { 53 | var result = "", cycle; 54 | for (cycle = 0; cycle < count; cycle += 1) { 55 | result += string; 56 | } 57 | return result; 58 | } 59 | function isNegativeZero(number) { 60 | return number === 0 && Number.NEGATIVE_INFINITY === 1 / number; 61 | } 62 | module.exports.isNothing = isNothing; 63 | module.exports.isObject = isObject; 64 | module.exports.toArray = toArray; 65 | module.exports.repeat = repeat; 66 | module.exports.isNegativeZero = isNegativeZero; 67 | module.exports.extend = extend; 68 | } 69 | }); 70 | 71 | // node_modules/js-yaml/lib/exception.js 72 | var require_exception = __commonJS({ 73 | "node_modules/js-yaml/lib/exception.js"(exports, module) { 74 | "use strict"; 75 | init_modules_watch_stub(); 76 | function formatError(exception, compact) { 77 | var where = "", message = exception.reason || "(unknown reason)"; 78 | if (!exception.mark) 79 | return message; 80 | if (exception.mark.name) { 81 | where += 'in "' + exception.mark.name + '" '; 82 | } 83 | where += "(" + (exception.mark.line + 1) + ":" + (exception.mark.column + 1) + ")"; 84 | if (!compact && exception.mark.snippet) { 85 | where += "\n\n" + exception.mark.snippet; 86 | } 87 | return message + " " + where; 88 | } 89 | function YAMLException(reason, mark) { 90 | Error.call(this); 91 | this.name = "YAMLException"; 92 | this.reason = reason; 93 | this.mark = mark; 94 | this.message = formatError(this, false); 95 | if (Error.captureStackTrace) { 96 | Error.captureStackTrace(this, this.constructor); 97 | } else { 98 | this.stack = new Error().stack || ""; 99 | } 100 | } 101 | YAMLException.prototype = Object.create(Error.prototype); 102 | YAMLException.prototype.constructor = YAMLException; 103 | YAMLException.prototype.toString = function toString(compact) { 104 | return this.name + ": " + formatError(this, compact); 105 | }; 106 | module.exports = YAMLException; 107 | } 108 | }); 109 | 110 | // node_modules/js-yaml/lib/snippet.js 111 | var require_snippet = __commonJS({ 112 | "node_modules/js-yaml/lib/snippet.js"(exports, module) { 113 | "use strict"; 114 | init_modules_watch_stub(); 115 | var common = require_common(); 116 | function getLine(buffer, lineStart, lineEnd, position, maxLineLength) { 117 | var head = ""; 118 | var tail = ""; 119 | var maxHalfLength = Math.floor(maxLineLength / 2) - 1; 120 | if (position - lineStart > maxHalfLength) { 121 | head = " ... "; 122 | lineStart = position - maxHalfLength + head.length; 123 | } 124 | if (lineEnd - position > maxHalfLength) { 125 | tail = " ..."; 126 | lineEnd = position + maxHalfLength - tail.length; 127 | } 128 | return { 129 | str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail, 130 | pos: position - lineStart + head.length 131 | // relative position 132 | }; 133 | } 134 | function padStart(string, max) { 135 | return common.repeat(" ", max - string.length) + string; 136 | } 137 | function makeSnippet(mark, options) { 138 | options = Object.create(options || null); 139 | if (!mark.buffer) 140 | return null; 141 | if (!options.maxLength) 142 | options.maxLength = 79; 143 | if (typeof options.indent !== "number") 144 | options.indent = 1; 145 | if (typeof options.linesBefore !== "number") 146 | options.linesBefore = 3; 147 | if (typeof options.linesAfter !== "number") 148 | options.linesAfter = 2; 149 | var re = /\r?\n|\r|\0/g; 150 | var lineStarts = [0]; 151 | var lineEnds = []; 152 | var match; 153 | var foundLineNo = -1; 154 | while (match = re.exec(mark.buffer)) { 155 | lineEnds.push(match.index); 156 | lineStarts.push(match.index + match[0].length); 157 | if (mark.position <= match.index && foundLineNo < 0) { 158 | foundLineNo = lineStarts.length - 2; 159 | } 160 | } 161 | if (foundLineNo < 0) 162 | foundLineNo = lineStarts.length - 1; 163 | var result = "", i, line; 164 | var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length; 165 | var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3); 166 | for (i = 1; i <= options.linesBefore; i++) { 167 | if (foundLineNo - i < 0) 168 | break; 169 | line = getLine( 170 | mark.buffer, 171 | lineStarts[foundLineNo - i], 172 | lineEnds[foundLineNo - i], 173 | mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), 174 | maxLineLength 175 | ); 176 | result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result; 177 | } 178 | line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength); 179 | result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n"; 180 | result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n"; 181 | for (i = 1; i <= options.linesAfter; i++) { 182 | if (foundLineNo + i >= lineEnds.length) 183 | break; 184 | line = getLine( 185 | mark.buffer, 186 | lineStarts[foundLineNo + i], 187 | lineEnds[foundLineNo + i], 188 | mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), 189 | maxLineLength 190 | ); 191 | result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n"; 192 | } 193 | return result.replace(/\n$/, ""); 194 | } 195 | module.exports = makeSnippet; 196 | } 197 | }); 198 | 199 | // node_modules/js-yaml/lib/type.js 200 | var require_type = __commonJS({ 201 | "node_modules/js-yaml/lib/type.js"(exports, module) { 202 | "use strict"; 203 | init_modules_watch_stub(); 204 | var YAMLException = require_exception(); 205 | var TYPE_CONSTRUCTOR_OPTIONS = [ 206 | "kind", 207 | "multi", 208 | "resolve", 209 | "construct", 210 | "instanceOf", 211 | "predicate", 212 | "represent", 213 | "representName", 214 | "defaultStyle", 215 | "styleAliases" 216 | ]; 217 | var YAML_NODE_KINDS = [ 218 | "scalar", 219 | "sequence", 220 | "mapping" 221 | ]; 222 | function compileStyleAliases(map) { 223 | var result = {}; 224 | if (map !== null) { 225 | Object.keys(map).forEach(function (style) { 226 | map[style].forEach(function (alias) { 227 | result[String(alias)] = style; 228 | }); 229 | }); 230 | } 231 | return result; 232 | } 233 | function Type(tag, options) { 234 | options = options || {}; 235 | Object.keys(options).forEach(function (name) { 236 | if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) { 237 | throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.'); 238 | } 239 | }); 240 | this.options = options; 241 | this.tag = tag; 242 | this.kind = options["kind"] || null; 243 | this.resolve = options["resolve"] || function () { 244 | return true; 245 | }; 246 | this.construct = options["construct"] || function (data) { 247 | return data; 248 | }; 249 | this.instanceOf = options["instanceOf"] || null; 250 | this.predicate = options["predicate"] || null; 251 | this.represent = options["represent"] || null; 252 | this.representName = options["representName"] || null; 253 | this.defaultStyle = options["defaultStyle"] || null; 254 | this.multi = options["multi"] || false; 255 | this.styleAliases = compileStyleAliases(options["styleAliases"] || null); 256 | if (YAML_NODE_KINDS.indexOf(this.kind) === -1) { 257 | throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.'); 258 | } 259 | } 260 | module.exports = Type; 261 | } 262 | }); 263 | 264 | // node_modules/js-yaml/lib/schema.js 265 | var require_schema = __commonJS({ 266 | "node_modules/js-yaml/lib/schema.js"(exports, module) { 267 | "use strict"; 268 | init_modules_watch_stub(); 269 | var YAMLException = require_exception(); 270 | var Type = require_type(); 271 | function compileList(schema, name) { 272 | var result = []; 273 | schema[name].forEach(function (currentType) { 274 | var newIndex = result.length; 275 | result.forEach(function (previousType, previousIndex) { 276 | if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) { 277 | newIndex = previousIndex; 278 | } 279 | }); 280 | result[newIndex] = currentType; 281 | }); 282 | return result; 283 | } 284 | function compileMap() { 285 | var result = { 286 | scalar: {}, 287 | sequence: {}, 288 | mapping: {}, 289 | fallback: {}, 290 | multi: { 291 | scalar: [], 292 | sequence: [], 293 | mapping: [], 294 | fallback: [] 295 | } 296 | }, index, length; 297 | function collectType(type) { 298 | if (type.multi) { 299 | result.multi[type.kind].push(type); 300 | result.multi["fallback"].push(type); 301 | } else { 302 | result[type.kind][type.tag] = result["fallback"][type.tag] = type; 303 | } 304 | } 305 | for (index = 0, length = arguments.length; index < length; index += 1) { 306 | arguments[index].forEach(collectType); 307 | } 308 | return result; 309 | } 310 | function Schema(definition) { 311 | return this.extend(definition); 312 | } 313 | Schema.prototype.extend = function extend(definition) { 314 | var implicit = []; 315 | var explicit = []; 316 | if (definition instanceof Type) { 317 | explicit.push(definition); 318 | } else if (Array.isArray(definition)) { 319 | explicit = explicit.concat(definition); 320 | } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) { 321 | if (definition.implicit) 322 | implicit = implicit.concat(definition.implicit); 323 | if (definition.explicit) 324 | explicit = explicit.concat(definition.explicit); 325 | } else { 326 | throw new YAMLException("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })"); 327 | } 328 | implicit.forEach(function (type) { 329 | if (!(type instanceof Type)) { 330 | throw new YAMLException("Specified list of YAML types (or a single Type object) contains a non-Type object."); 331 | } 332 | if (type.loadKind && type.loadKind !== "scalar") { 333 | throw new YAMLException("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported."); 334 | } 335 | if (type.multi) { 336 | throw new YAMLException("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit."); 337 | } 338 | }); 339 | explicit.forEach(function (type) { 340 | if (!(type instanceof Type)) { 341 | throw new YAMLException("Specified list of YAML types (or a single Type object) contains a non-Type object."); 342 | } 343 | }); 344 | var result = Object.create(Schema.prototype); 345 | result.implicit = (this.implicit || []).concat(implicit); 346 | result.explicit = (this.explicit || []).concat(explicit); 347 | result.compiledImplicit = compileList(result, "implicit"); 348 | result.compiledExplicit = compileList(result, "explicit"); 349 | result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit); 350 | return result; 351 | }; 352 | module.exports = Schema; 353 | } 354 | }); 355 | 356 | // node_modules/js-yaml/lib/type/str.js 357 | var require_str = __commonJS({ 358 | "node_modules/js-yaml/lib/type/str.js"(exports, module) { 359 | "use strict"; 360 | init_modules_watch_stub(); 361 | var Type = require_type(); 362 | module.exports = new Type("tag:yaml.org,2002:str", { 363 | kind: "scalar", 364 | construct: function (data) { 365 | return data !== null ? data : ""; 366 | } 367 | }); 368 | } 369 | }); 370 | 371 | // node_modules/js-yaml/lib/type/seq.js 372 | var require_seq = __commonJS({ 373 | "node_modules/js-yaml/lib/type/seq.js"(exports, module) { 374 | "use strict"; 375 | init_modules_watch_stub(); 376 | var Type = require_type(); 377 | module.exports = new Type("tag:yaml.org,2002:seq", { 378 | kind: "sequence", 379 | construct: function (data) { 380 | return data !== null ? data : []; 381 | } 382 | }); 383 | } 384 | }); 385 | 386 | // node_modules/js-yaml/lib/type/map.js 387 | var require_map = __commonJS({ 388 | "node_modules/js-yaml/lib/type/map.js"(exports, module) { 389 | "use strict"; 390 | init_modules_watch_stub(); 391 | var Type = require_type(); 392 | module.exports = new Type("tag:yaml.org,2002:map", { 393 | kind: "mapping", 394 | construct: function (data) { 395 | return data !== null ? data : {}; 396 | } 397 | }); 398 | } 399 | }); 400 | 401 | // node_modules/js-yaml/lib/schema/failsafe.js 402 | var require_failsafe = __commonJS({ 403 | "node_modules/js-yaml/lib/schema/failsafe.js"(exports, module) { 404 | "use strict"; 405 | init_modules_watch_stub(); 406 | var Schema = require_schema(); 407 | module.exports = new Schema({ 408 | explicit: [ 409 | require_str(), 410 | require_seq(), 411 | require_map() 412 | ] 413 | }); 414 | } 415 | }); 416 | 417 | // node_modules/js-yaml/lib/type/null.js 418 | var require_null = __commonJS({ 419 | "node_modules/js-yaml/lib/type/null.js"(exports, module) { 420 | "use strict"; 421 | init_modules_watch_stub(); 422 | var Type = require_type(); 423 | function resolveYamlNull(data) { 424 | if (data === null) 425 | return true; 426 | var max = data.length; 427 | return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL"); 428 | } 429 | function constructYamlNull() { 430 | return null; 431 | } 432 | function isNull(object) { 433 | return object === null; 434 | } 435 | module.exports = new Type("tag:yaml.org,2002:null", { 436 | kind: "scalar", 437 | resolve: resolveYamlNull, 438 | construct: constructYamlNull, 439 | predicate: isNull, 440 | represent: { 441 | canonical: function () { 442 | return "~"; 443 | }, 444 | lowercase: function () { 445 | return "null"; 446 | }, 447 | uppercase: function () { 448 | return "NULL"; 449 | }, 450 | camelcase: function () { 451 | return "Null"; 452 | }, 453 | empty: function () { 454 | return ""; 455 | } 456 | }, 457 | defaultStyle: "lowercase" 458 | }); 459 | } 460 | }); 461 | 462 | // node_modules/js-yaml/lib/type/bool.js 463 | var require_bool = __commonJS({ 464 | "node_modules/js-yaml/lib/type/bool.js"(exports, module) { 465 | "use strict"; 466 | init_modules_watch_stub(); 467 | var Type = require_type(); 468 | function resolveYamlBoolean(data) { 469 | if (data === null) 470 | return false; 471 | var max = data.length; 472 | return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE"); 473 | } 474 | function constructYamlBoolean(data) { 475 | return data === "true" || data === "True" || data === "TRUE"; 476 | } 477 | function isBoolean(object) { 478 | return Object.prototype.toString.call(object) === "[object Boolean]"; 479 | } 480 | module.exports = new Type("tag:yaml.org,2002:bool", { 481 | kind: "scalar", 482 | resolve: resolveYamlBoolean, 483 | construct: constructYamlBoolean, 484 | predicate: isBoolean, 485 | represent: { 486 | lowercase: function (object) { 487 | return object ? "true" : "false"; 488 | }, 489 | uppercase: function (object) { 490 | return object ? "TRUE" : "FALSE"; 491 | }, 492 | camelcase: function (object) { 493 | return object ? "True" : "False"; 494 | } 495 | }, 496 | defaultStyle: "lowercase" 497 | }); 498 | } 499 | }); 500 | 501 | // node_modules/js-yaml/lib/type/int.js 502 | var require_int = __commonJS({ 503 | "node_modules/js-yaml/lib/type/int.js"(exports, module) { 504 | "use strict"; 505 | init_modules_watch_stub(); 506 | var common = require_common(); 507 | var Type = require_type(); 508 | function isHexCode(c) { 509 | return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102; 510 | } 511 | function isOctCode(c) { 512 | return 48 <= c && c <= 55; 513 | } 514 | function isDecCode(c) { 515 | return 48 <= c && c <= 57; 516 | } 517 | function resolveYamlInteger(data) { 518 | if (data === null) 519 | return false; 520 | var max = data.length, index = 0, hasDigits = false, ch; 521 | if (!max) 522 | return false; 523 | ch = data[index]; 524 | if (ch === "-" || ch === "+") { 525 | ch = data[++index]; 526 | } 527 | if (ch === "0") { 528 | if (index + 1 === max) 529 | return true; 530 | ch = data[++index]; 531 | if (ch === "b") { 532 | index++; 533 | for (; index < max; index++) { 534 | ch = data[index]; 535 | if (ch === "_") 536 | continue; 537 | if (ch !== "0" && ch !== "1") 538 | return false; 539 | hasDigits = true; 540 | } 541 | return hasDigits && ch !== "_"; 542 | } 543 | if (ch === "x") { 544 | index++; 545 | for (; index < max; index++) { 546 | ch = data[index]; 547 | if (ch === "_") 548 | continue; 549 | if (!isHexCode(data.charCodeAt(index))) 550 | return false; 551 | hasDigits = true; 552 | } 553 | return hasDigits && ch !== "_"; 554 | } 555 | if (ch === "o") { 556 | index++; 557 | for (; index < max; index++) { 558 | ch = data[index]; 559 | if (ch === "_") 560 | continue; 561 | if (!isOctCode(data.charCodeAt(index))) 562 | return false; 563 | hasDigits = true; 564 | } 565 | return hasDigits && ch !== "_"; 566 | } 567 | } 568 | if (ch === "_") 569 | return false; 570 | for (; index < max; index++) { 571 | ch = data[index]; 572 | if (ch === "_") 573 | continue; 574 | if (!isDecCode(data.charCodeAt(index))) { 575 | return false; 576 | } 577 | hasDigits = true; 578 | } 579 | if (!hasDigits || ch === "_") 580 | return false; 581 | return true; 582 | } 583 | function constructYamlInteger(data) { 584 | var value = data, sign = 1, ch; 585 | if (value.indexOf("_") !== -1) { 586 | value = value.replace(/_/g, ""); 587 | } 588 | ch = value[0]; 589 | if (ch === "-" || ch === "+") { 590 | if (ch === "-") 591 | sign = -1; 592 | value = value.slice(1); 593 | ch = value[0]; 594 | } 595 | if (value === "0") 596 | return 0; 597 | if (ch === "0") { 598 | if (value[1] === "b") 599 | return sign * parseInt(value.slice(2), 2); 600 | if (value[1] === "x") 601 | return sign * parseInt(value.slice(2), 16); 602 | if (value[1] === "o") 603 | return sign * parseInt(value.slice(2), 8); 604 | } 605 | return sign * parseInt(value, 10); 606 | } 607 | function isInteger(object) { 608 | return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object)); 609 | } 610 | module.exports = new Type("tag:yaml.org,2002:int", { 611 | kind: "scalar", 612 | resolve: resolveYamlInteger, 613 | construct: constructYamlInteger, 614 | predicate: isInteger, 615 | represent: { 616 | binary: function (obj) { 617 | return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1); 618 | }, 619 | octal: function (obj) { 620 | return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1); 621 | }, 622 | decimal: function (obj) { 623 | return obj.toString(10); 624 | }, 625 | /* eslint-disable max-len */ 626 | hexadecimal: function (obj) { 627 | return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1); 628 | } 629 | }, 630 | defaultStyle: "decimal", 631 | styleAliases: { 632 | binary: [2, "bin"], 633 | octal: [8, "oct"], 634 | decimal: [10, "dec"], 635 | hexadecimal: [16, "hex"] 636 | } 637 | }); 638 | } 639 | }); 640 | 641 | // node_modules/js-yaml/lib/type/float.js 642 | var require_float = __commonJS({ 643 | "node_modules/js-yaml/lib/type/float.js"(exports, module) { 644 | "use strict"; 645 | init_modules_watch_stub(); 646 | var common = require_common(); 647 | var Type = require_type(); 648 | var YAML_FLOAT_PATTERN = new RegExp( 649 | // 2.5e4, 2.5 and integers 650 | "^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$" 651 | ); 652 | function resolveYamlFloat(data) { 653 | if (data === null) 654 | return false; 655 | if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_` 656 | // Probably should update regexp & check speed 657 | data[data.length - 1] === "_") { 658 | return false; 659 | } 660 | return true; 661 | } 662 | function constructYamlFloat(data) { 663 | var value, sign; 664 | value = data.replace(/_/g, "").toLowerCase(); 665 | sign = value[0] === "-" ? -1 : 1; 666 | if ("+-".indexOf(value[0]) >= 0) { 667 | value = value.slice(1); 668 | } 669 | if (value === ".inf") { 670 | return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; 671 | } else if (value === ".nan") { 672 | return NaN; 673 | } 674 | return sign * parseFloat(value, 10); 675 | } 676 | var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/; 677 | function representYamlFloat(object, style) { 678 | var res; 679 | if (isNaN(object)) { 680 | switch (style) { 681 | case "lowercase": 682 | return ".nan"; 683 | case "uppercase": 684 | return ".NAN"; 685 | case "camelcase": 686 | return ".NaN"; 687 | } 688 | } else if (Number.POSITIVE_INFINITY === object) { 689 | switch (style) { 690 | case "lowercase": 691 | return ".inf"; 692 | case "uppercase": 693 | return ".INF"; 694 | case "camelcase": 695 | return ".Inf"; 696 | } 697 | } else if (Number.NEGATIVE_INFINITY === object) { 698 | switch (style) { 699 | case "lowercase": 700 | return "-.inf"; 701 | case "uppercase": 702 | return "-.INF"; 703 | case "camelcase": 704 | return "-.Inf"; 705 | } 706 | } else if (common.isNegativeZero(object)) { 707 | return "-0.0"; 708 | } 709 | res = object.toString(10); 710 | return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res; 711 | } 712 | function isFloat(object) { 713 | return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object)); 714 | } 715 | module.exports = new Type("tag:yaml.org,2002:float", { 716 | kind: "scalar", 717 | resolve: resolveYamlFloat, 718 | construct: constructYamlFloat, 719 | predicate: isFloat, 720 | represent: representYamlFloat, 721 | defaultStyle: "lowercase" 722 | }); 723 | } 724 | }); 725 | 726 | // node_modules/js-yaml/lib/schema/json.js 727 | var require_json = __commonJS({ 728 | "node_modules/js-yaml/lib/schema/json.js"(exports, module) { 729 | "use strict"; 730 | init_modules_watch_stub(); 731 | module.exports = require_failsafe().extend({ 732 | implicit: [ 733 | require_null(), 734 | require_bool(), 735 | require_int(), 736 | require_float() 737 | ] 738 | }); 739 | } 740 | }); 741 | 742 | // node_modules/js-yaml/lib/schema/core.js 743 | var require_core = __commonJS({ 744 | "node_modules/js-yaml/lib/schema/core.js"(exports, module) { 745 | "use strict"; 746 | init_modules_watch_stub(); 747 | module.exports = require_json(); 748 | } 749 | }); 750 | 751 | // node_modules/js-yaml/lib/type/timestamp.js 752 | var require_timestamp = __commonJS({ 753 | "node_modules/js-yaml/lib/type/timestamp.js"(exports, module) { 754 | "use strict"; 755 | init_modules_watch_stub(); 756 | var Type = require_type(); 757 | var YAML_DATE_REGEXP = new RegExp( 758 | "^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$" 759 | ); 760 | var YAML_TIMESTAMP_REGEXP = new RegExp( 761 | "^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$" 762 | ); 763 | function resolveYamlTimestamp(data) { 764 | if (data === null) 765 | return false; 766 | if (YAML_DATE_REGEXP.exec(data) !== null) 767 | return true; 768 | if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) 769 | return true; 770 | return false; 771 | } 772 | function constructYamlTimestamp(data) { 773 | var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date; 774 | match = YAML_DATE_REGEXP.exec(data); 775 | if (match === null) 776 | match = YAML_TIMESTAMP_REGEXP.exec(data); 777 | if (match === null) 778 | throw new Error("Date resolve error"); 779 | year = +match[1]; 780 | month = +match[2] - 1; 781 | day = +match[3]; 782 | if (!match[4]) { 783 | return new Date(Date.UTC(year, month, day)); 784 | } 785 | hour = +match[4]; 786 | minute = +match[5]; 787 | second = +match[6]; 788 | if (match[7]) { 789 | fraction = match[7].slice(0, 3); 790 | while (fraction.length < 3) { 791 | fraction += "0"; 792 | } 793 | fraction = +fraction; 794 | } 795 | if (match[9]) { 796 | tz_hour = +match[10]; 797 | tz_minute = +(match[11] || 0); 798 | delta = (tz_hour * 60 + tz_minute) * 6e4; 799 | if (match[9] === "-") 800 | delta = -delta; 801 | } 802 | date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction)); 803 | if (delta) 804 | date.setTime(date.getTime() - delta); 805 | return date; 806 | } 807 | function representYamlTimestamp(object) { 808 | return object.toISOString(); 809 | } 810 | module.exports = new Type("tag:yaml.org,2002:timestamp", { 811 | kind: "scalar", 812 | resolve: resolveYamlTimestamp, 813 | construct: constructYamlTimestamp, 814 | instanceOf: Date, 815 | represent: representYamlTimestamp 816 | }); 817 | } 818 | }); 819 | 820 | // node_modules/js-yaml/lib/type/merge.js 821 | var require_merge = __commonJS({ 822 | "node_modules/js-yaml/lib/type/merge.js"(exports, module) { 823 | "use strict"; 824 | init_modules_watch_stub(); 825 | var Type = require_type(); 826 | function resolveYamlMerge(data) { 827 | return data === "<<" || data === null; 828 | } 829 | module.exports = new Type("tag:yaml.org,2002:merge", { 830 | kind: "scalar", 831 | resolve: resolveYamlMerge 832 | }); 833 | } 834 | }); 835 | 836 | // node_modules/js-yaml/lib/type/binary.js 837 | var require_binary = __commonJS({ 838 | "node_modules/js-yaml/lib/type/binary.js"(exports, module) { 839 | "use strict"; 840 | init_modules_watch_stub(); 841 | var Type = require_type(); 842 | var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r"; 843 | function resolveYamlBinary(data) { 844 | if (data === null) 845 | return false; 846 | var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP; 847 | for (idx = 0; idx < max; idx++) { 848 | code = map.indexOf(data.charAt(idx)); 849 | if (code > 64) 850 | continue; 851 | if (code < 0) 852 | return false; 853 | bitlen += 6; 854 | } 855 | return bitlen % 8 === 0; 856 | } 857 | function constructYamlBinary(data) { 858 | var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map = BASE64_MAP, bits = 0, result = []; 859 | for (idx = 0; idx < max; idx++) { 860 | if (idx % 4 === 0 && idx) { 861 | result.push(bits >> 16 & 255); 862 | result.push(bits >> 8 & 255); 863 | result.push(bits & 255); 864 | } 865 | bits = bits << 6 | map.indexOf(input.charAt(idx)); 866 | } 867 | tailbits = max % 4 * 6; 868 | if (tailbits === 0) { 869 | result.push(bits >> 16 & 255); 870 | result.push(bits >> 8 & 255); 871 | result.push(bits & 255); 872 | } else if (tailbits === 18) { 873 | result.push(bits >> 10 & 255); 874 | result.push(bits >> 2 & 255); 875 | } else if (tailbits === 12) { 876 | result.push(bits >> 4 & 255); 877 | } 878 | return new Uint8Array(result); 879 | } 880 | function representYamlBinary(object) { 881 | var result = "", bits = 0, idx, tail, max = object.length, map = BASE64_MAP; 882 | for (idx = 0; idx < max; idx++) { 883 | if (idx % 3 === 0 && idx) { 884 | result += map[bits >> 18 & 63]; 885 | result += map[bits >> 12 & 63]; 886 | result += map[bits >> 6 & 63]; 887 | result += map[bits & 63]; 888 | } 889 | bits = (bits << 8) + object[idx]; 890 | } 891 | tail = max % 3; 892 | if (tail === 0) { 893 | result += map[bits >> 18 & 63]; 894 | result += map[bits >> 12 & 63]; 895 | result += map[bits >> 6 & 63]; 896 | result += map[bits & 63]; 897 | } else if (tail === 2) { 898 | result += map[bits >> 10 & 63]; 899 | result += map[bits >> 4 & 63]; 900 | result += map[bits << 2 & 63]; 901 | result += map[64]; 902 | } else if (tail === 1) { 903 | result += map[bits >> 2 & 63]; 904 | result += map[bits << 4 & 63]; 905 | result += map[64]; 906 | result += map[64]; 907 | } 908 | return result; 909 | } 910 | function isBinary(obj) { 911 | return Object.prototype.toString.call(obj) === "[object Uint8Array]"; 912 | } 913 | module.exports = new Type("tag:yaml.org,2002:binary", { 914 | kind: "scalar", 915 | resolve: resolveYamlBinary, 916 | construct: constructYamlBinary, 917 | predicate: isBinary, 918 | represent: representYamlBinary 919 | }); 920 | } 921 | }); 922 | 923 | // node_modules/js-yaml/lib/type/omap.js 924 | var require_omap = __commonJS({ 925 | "node_modules/js-yaml/lib/type/omap.js"(exports, module) { 926 | "use strict"; 927 | init_modules_watch_stub(); 928 | var Type = require_type(); 929 | var _hasOwnProperty = Object.prototype.hasOwnProperty; 930 | var _toString = Object.prototype.toString; 931 | function resolveYamlOmap(data) { 932 | if (data === null) 933 | return true; 934 | var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data; 935 | for (index = 0, length = object.length; index < length; index += 1) { 936 | pair = object[index]; 937 | pairHasKey = false; 938 | if (_toString.call(pair) !== "[object Object]") 939 | return false; 940 | for (pairKey in pair) { 941 | if (_hasOwnProperty.call(pair, pairKey)) { 942 | if (!pairHasKey) 943 | pairHasKey = true; 944 | else 945 | return false; 946 | } 947 | } 948 | if (!pairHasKey) 949 | return false; 950 | if (objectKeys.indexOf(pairKey) === -1) 951 | objectKeys.push(pairKey); 952 | else 953 | return false; 954 | } 955 | return true; 956 | } 957 | function constructYamlOmap(data) { 958 | return data !== null ? data : []; 959 | } 960 | module.exports = new Type("tag:yaml.org,2002:omap", { 961 | kind: "sequence", 962 | resolve: resolveYamlOmap, 963 | construct: constructYamlOmap 964 | }); 965 | } 966 | }); 967 | 968 | // node_modules/js-yaml/lib/type/pairs.js 969 | var require_pairs = __commonJS({ 970 | "node_modules/js-yaml/lib/type/pairs.js"(exports, module) { 971 | "use strict"; 972 | init_modules_watch_stub(); 973 | var Type = require_type(); 974 | var _toString = Object.prototype.toString; 975 | function resolveYamlPairs(data) { 976 | if (data === null) 977 | return true; 978 | var index, length, pair, keys, result, object = data; 979 | result = new Array(object.length); 980 | for (index = 0, length = object.length; index < length; index += 1) { 981 | pair = object[index]; 982 | if (_toString.call(pair) !== "[object Object]") 983 | return false; 984 | keys = Object.keys(pair); 985 | if (keys.length !== 1) 986 | return false; 987 | result[index] = [keys[0], pair[keys[0]]]; 988 | } 989 | return true; 990 | } 991 | function constructYamlPairs(data) { 992 | if (data === null) 993 | return []; 994 | var index, length, pair, keys, result, object = data; 995 | result = new Array(object.length); 996 | for (index = 0, length = object.length; index < length; index += 1) { 997 | pair = object[index]; 998 | keys = Object.keys(pair); 999 | result[index] = [keys[0], pair[keys[0]]]; 1000 | } 1001 | return result; 1002 | } 1003 | module.exports = new Type("tag:yaml.org,2002:pairs", { 1004 | kind: "sequence", 1005 | resolve: resolveYamlPairs, 1006 | construct: constructYamlPairs 1007 | }); 1008 | } 1009 | }); 1010 | 1011 | // node_modules/js-yaml/lib/type/set.js 1012 | var require_set = __commonJS({ 1013 | "node_modules/js-yaml/lib/type/set.js"(exports, module) { 1014 | "use strict"; 1015 | init_modules_watch_stub(); 1016 | var Type = require_type(); 1017 | var _hasOwnProperty = Object.prototype.hasOwnProperty; 1018 | function resolveYamlSet(data) { 1019 | if (data === null) 1020 | return true; 1021 | var key, object = data; 1022 | for (key in object) { 1023 | if (_hasOwnProperty.call(object, key)) { 1024 | if (object[key] !== null) 1025 | return false; 1026 | } 1027 | } 1028 | return true; 1029 | } 1030 | function constructYamlSet(data) { 1031 | return data !== null ? data : {}; 1032 | } 1033 | module.exports = new Type("tag:yaml.org,2002:set", { 1034 | kind: "mapping", 1035 | resolve: resolveYamlSet, 1036 | construct: constructYamlSet 1037 | }); 1038 | } 1039 | }); 1040 | 1041 | // node_modules/js-yaml/lib/schema/default.js 1042 | var require_default = __commonJS({ 1043 | "node_modules/js-yaml/lib/schema/default.js"(exports, module) { 1044 | "use strict"; 1045 | init_modules_watch_stub(); 1046 | module.exports = require_core().extend({ 1047 | implicit: [ 1048 | require_timestamp(), 1049 | require_merge() 1050 | ], 1051 | explicit: [ 1052 | require_binary(), 1053 | require_omap(), 1054 | require_pairs(), 1055 | require_set() 1056 | ] 1057 | }); 1058 | } 1059 | }); 1060 | 1061 | // node_modules/js-yaml/lib/loader.js 1062 | var require_loader = __commonJS({ 1063 | "node_modules/js-yaml/lib/loader.js"(exports, module) { 1064 | "use strict"; 1065 | init_modules_watch_stub(); 1066 | var common = require_common(); 1067 | var YAMLException = require_exception(); 1068 | var makeSnippet = require_snippet(); 1069 | var DEFAULT_SCHEMA = require_default(); 1070 | var _hasOwnProperty = Object.prototype.hasOwnProperty; 1071 | var CONTEXT_FLOW_IN = 1; 1072 | var CONTEXT_FLOW_OUT = 2; 1073 | var CONTEXT_BLOCK_IN = 3; 1074 | var CONTEXT_BLOCK_OUT = 4; 1075 | var CHOMPING_CLIP = 1; 1076 | var CHOMPING_STRIP = 2; 1077 | var CHOMPING_KEEP = 3; 1078 | var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/; 1079 | var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/; 1080 | var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/; 1081 | var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i; 1082 | var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i; 1083 | function _class(obj) { 1084 | return Object.prototype.toString.call(obj); 1085 | } 1086 | function is_EOL(c) { 1087 | return c === 10 || c === 13; 1088 | } 1089 | function is_WHITE_SPACE(c) { 1090 | return c === 9 || c === 32; 1091 | } 1092 | function is_WS_OR_EOL(c) { 1093 | return c === 9 || c === 32 || c === 10 || c === 13; 1094 | } 1095 | function is_FLOW_INDICATOR(c) { 1096 | return c === 44 || c === 91 || c === 93 || c === 123 || c === 125; 1097 | } 1098 | function fromHexCode(c) { 1099 | var lc; 1100 | if (48 <= c && c <= 57) { 1101 | return c - 48; 1102 | } 1103 | lc = c | 32; 1104 | if (97 <= lc && lc <= 102) { 1105 | return lc - 97 + 10; 1106 | } 1107 | return -1; 1108 | } 1109 | function escapedHexLen(c) { 1110 | if (c === 120) { 1111 | return 2; 1112 | } 1113 | if (c === 117) { 1114 | return 4; 1115 | } 1116 | if (c === 85) { 1117 | return 8; 1118 | } 1119 | return 0; 1120 | } 1121 | function fromDecimalCode(c) { 1122 | if (48 <= c && c <= 57) { 1123 | return c - 48; 1124 | } 1125 | return -1; 1126 | } 1127 | function simpleEscapeSequence(c) { 1128 | return c === 48 ? "\0" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? " " : c === 9 ? " " : c === 110 ? "\n" : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "\x85" : c === 95 ? "\xA0" : c === 76 ? "\u2028" : c === 80 ? "\u2029" : ""; 1129 | } 1130 | function charFromCodepoint(c) { 1131 | if (c <= 65535) { 1132 | return String.fromCharCode(c); 1133 | } 1134 | return String.fromCharCode( 1135 | (c - 65536 >> 10) + 55296, 1136 | (c - 65536 & 1023) + 56320 1137 | ); 1138 | } 1139 | var simpleEscapeCheck = new Array(256); 1140 | var simpleEscapeMap = new Array(256); 1141 | for (i = 0; i < 256; i++) { 1142 | simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0; 1143 | simpleEscapeMap[i] = simpleEscapeSequence(i); 1144 | } 1145 | var i; 1146 | function State(input, options) { 1147 | this.input = input; 1148 | this.filename = options["filename"] || null; 1149 | this.schema = options["schema"] || DEFAULT_SCHEMA; 1150 | this.onWarning = options["onWarning"] || null; 1151 | this.legacy = options["legacy"] || false; 1152 | this.json = options["json"] || false; 1153 | this.listener = options["listener"] || null; 1154 | this.implicitTypes = this.schema.compiledImplicit; 1155 | this.typeMap = this.schema.compiledTypeMap; 1156 | this.length = input.length; 1157 | this.position = 0; 1158 | this.line = 0; 1159 | this.lineStart = 0; 1160 | this.lineIndent = 0; 1161 | this.firstTabInLine = -1; 1162 | this.documents = []; 1163 | } 1164 | function generateError(state, message) { 1165 | var mark = { 1166 | name: state.filename, 1167 | buffer: state.input.slice(0, -1), 1168 | // omit trailing \0 1169 | position: state.position, 1170 | line: state.line, 1171 | column: state.position - state.lineStart 1172 | }; 1173 | mark.snippet = makeSnippet(mark); 1174 | return new YAMLException(message, mark); 1175 | } 1176 | function throwError(state, message) { 1177 | throw generateError(state, message); 1178 | } 1179 | function throwWarning(state, message) { 1180 | if (state.onWarning) { 1181 | state.onWarning.call(null, generateError(state, message)); 1182 | } 1183 | } 1184 | var directiveHandlers = { 1185 | YAML: function handleYamlDirective(state, name, args) { 1186 | var match, major, minor; 1187 | if (state.version !== null) { 1188 | throwError(state, "duplication of %YAML directive"); 1189 | } 1190 | if (args.length !== 1) { 1191 | throwError(state, "YAML directive accepts exactly one argument"); 1192 | } 1193 | match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]); 1194 | if (match === null) { 1195 | throwError(state, "ill-formed argument of the YAML directive"); 1196 | } 1197 | major = parseInt(match[1], 10); 1198 | minor = parseInt(match[2], 10); 1199 | if (major !== 1) { 1200 | throwError(state, "unacceptable YAML version of the document"); 1201 | } 1202 | state.version = args[0]; 1203 | state.checkLineBreaks = minor < 2; 1204 | if (minor !== 1 && minor !== 2) { 1205 | throwWarning(state, "unsupported YAML version of the document"); 1206 | } 1207 | }, 1208 | TAG: function handleTagDirective(state, name, args) { 1209 | var handle, prefix; 1210 | if (args.length !== 2) { 1211 | throwError(state, "TAG directive accepts exactly two arguments"); 1212 | } 1213 | handle = args[0]; 1214 | prefix = args[1]; 1215 | if (!PATTERN_TAG_HANDLE.test(handle)) { 1216 | throwError(state, "ill-formed tag handle (first argument) of the TAG directive"); 1217 | } 1218 | if (_hasOwnProperty.call(state.tagMap, handle)) { 1219 | throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle'); 1220 | } 1221 | if (!PATTERN_TAG_URI.test(prefix)) { 1222 | throwError(state, "ill-formed tag prefix (second argument) of the TAG directive"); 1223 | } 1224 | try { 1225 | prefix = decodeURIComponent(prefix); 1226 | } catch (err) { 1227 | throwError(state, "tag prefix is malformed: " + prefix); 1228 | } 1229 | state.tagMap[handle] = prefix; 1230 | } 1231 | }; 1232 | function captureSegment(state, start, end, checkJson) { 1233 | var _position, _length, _character, _result; 1234 | if (start < end) { 1235 | _result = state.input.slice(start, end); 1236 | if (checkJson) { 1237 | for (_position = 0, _length = _result.length; _position < _length; _position += 1) { 1238 | _character = _result.charCodeAt(_position); 1239 | if (!(_character === 9 || 32 <= _character && _character <= 1114111)) { 1240 | throwError(state, "expected valid JSON character"); 1241 | } 1242 | } 1243 | } else if (PATTERN_NON_PRINTABLE.test(_result)) { 1244 | throwError(state, "the stream contains non-printable characters"); 1245 | } 1246 | state.result += _result; 1247 | } 1248 | } 1249 | function mergeMappings(state, destination, source, overridableKeys) { 1250 | var sourceKeys, key, index, quantity; 1251 | if (!common.isObject(source)) { 1252 | throwError(state, "cannot merge mappings; the provided source object is unacceptable"); 1253 | } 1254 | sourceKeys = Object.keys(source); 1255 | for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) { 1256 | key = sourceKeys[index]; 1257 | if (!_hasOwnProperty.call(destination, key)) { 1258 | destination[key] = source[key]; 1259 | overridableKeys[key] = true; 1260 | } 1261 | } 1262 | } 1263 | function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) { 1264 | var index, quantity; 1265 | if (Array.isArray(keyNode)) { 1266 | keyNode = Array.prototype.slice.call(keyNode); 1267 | for (index = 0, quantity = keyNode.length; index < quantity; index += 1) { 1268 | if (Array.isArray(keyNode[index])) { 1269 | throwError(state, "nested arrays are not supported inside keys"); 1270 | } 1271 | if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") { 1272 | keyNode[index] = "[object Object]"; 1273 | } 1274 | } 1275 | } 1276 | if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") { 1277 | keyNode = "[object Object]"; 1278 | } 1279 | keyNode = String(keyNode); 1280 | if (_result === null) { 1281 | _result = {}; 1282 | } 1283 | if (keyTag === "tag:yaml.org,2002:merge") { 1284 | if (Array.isArray(valueNode)) { 1285 | for (index = 0, quantity = valueNode.length; index < quantity; index += 1) { 1286 | mergeMappings(state, _result, valueNode[index], overridableKeys); 1287 | } 1288 | } else { 1289 | mergeMappings(state, _result, valueNode, overridableKeys); 1290 | } 1291 | } else { 1292 | if (!state.json && !_hasOwnProperty.call(overridableKeys, keyNode) && _hasOwnProperty.call(_result, keyNode)) { 1293 | state.line = startLine || state.line; 1294 | state.lineStart = startLineStart || state.lineStart; 1295 | state.position = startPos || state.position; 1296 | throwError(state, "duplicated mapping key"); 1297 | } 1298 | if (keyNode === "__proto__") { 1299 | Object.defineProperty(_result, keyNode, { 1300 | configurable: true, 1301 | enumerable: true, 1302 | writable: true, 1303 | value: valueNode 1304 | }); 1305 | } else { 1306 | _result[keyNode] = valueNode; 1307 | } 1308 | delete overridableKeys[keyNode]; 1309 | } 1310 | return _result; 1311 | } 1312 | function readLineBreak(state) { 1313 | var ch; 1314 | ch = state.input.charCodeAt(state.position); 1315 | if (ch === 10) { 1316 | state.position++; 1317 | } else if (ch === 13) { 1318 | state.position++; 1319 | if (state.input.charCodeAt(state.position) === 10) { 1320 | state.position++; 1321 | } 1322 | } else { 1323 | throwError(state, "a line break is expected"); 1324 | } 1325 | state.line += 1; 1326 | state.lineStart = state.position; 1327 | state.firstTabInLine = -1; 1328 | } 1329 | function skipSeparationSpace(state, allowComments, checkIndent) { 1330 | var lineBreaks = 0, ch = state.input.charCodeAt(state.position); 1331 | while (ch !== 0) { 1332 | while (is_WHITE_SPACE(ch)) { 1333 | if (ch === 9 && state.firstTabInLine === -1) { 1334 | state.firstTabInLine = state.position; 1335 | } 1336 | ch = state.input.charCodeAt(++state.position); 1337 | } 1338 | if (allowComments && ch === 35) { 1339 | do { 1340 | ch = state.input.charCodeAt(++state.position); 1341 | } while (ch !== 10 && ch !== 13 && ch !== 0); 1342 | } 1343 | if (is_EOL(ch)) { 1344 | readLineBreak(state); 1345 | ch = state.input.charCodeAt(state.position); 1346 | lineBreaks++; 1347 | state.lineIndent = 0; 1348 | while (ch === 32) { 1349 | state.lineIndent++; 1350 | ch = state.input.charCodeAt(++state.position); 1351 | } 1352 | } else { 1353 | break; 1354 | } 1355 | } 1356 | if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) { 1357 | throwWarning(state, "deficient indentation"); 1358 | } 1359 | return lineBreaks; 1360 | } 1361 | function testDocumentSeparator(state) { 1362 | var _position = state.position, ch; 1363 | ch = state.input.charCodeAt(_position); 1364 | if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) { 1365 | _position += 3; 1366 | ch = state.input.charCodeAt(_position); 1367 | if (ch === 0 || is_WS_OR_EOL(ch)) { 1368 | return true; 1369 | } 1370 | } 1371 | return false; 1372 | } 1373 | function writeFoldedLines(state, count) { 1374 | if (count === 1) { 1375 | state.result += " "; 1376 | } else if (count > 1) { 1377 | state.result += common.repeat("\n", count - 1); 1378 | } 1379 | } 1380 | function readPlainScalar(state, nodeIndent, withinFlowCollection) { 1381 | var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch; 1382 | ch = state.input.charCodeAt(state.position); 1383 | if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) { 1384 | return false; 1385 | } 1386 | if (ch === 63 || ch === 45) { 1387 | following = state.input.charCodeAt(state.position + 1); 1388 | if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) { 1389 | return false; 1390 | } 1391 | } 1392 | state.kind = "scalar"; 1393 | state.result = ""; 1394 | captureStart = captureEnd = state.position; 1395 | hasPendingContent = false; 1396 | while (ch !== 0) { 1397 | if (ch === 58) { 1398 | following = state.input.charCodeAt(state.position + 1); 1399 | if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) { 1400 | break; 1401 | } 1402 | } else if (ch === 35) { 1403 | preceding = state.input.charCodeAt(state.position - 1); 1404 | if (is_WS_OR_EOL(preceding)) { 1405 | break; 1406 | } 1407 | } else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) { 1408 | break; 1409 | } else if (is_EOL(ch)) { 1410 | _line = state.line; 1411 | _lineStart = state.lineStart; 1412 | _lineIndent = state.lineIndent; 1413 | skipSeparationSpace(state, false, -1); 1414 | if (state.lineIndent >= nodeIndent) { 1415 | hasPendingContent = true; 1416 | ch = state.input.charCodeAt(state.position); 1417 | continue; 1418 | } else { 1419 | state.position = captureEnd; 1420 | state.line = _line; 1421 | state.lineStart = _lineStart; 1422 | state.lineIndent = _lineIndent; 1423 | break; 1424 | } 1425 | } 1426 | if (hasPendingContent) { 1427 | captureSegment(state, captureStart, captureEnd, false); 1428 | writeFoldedLines(state, state.line - _line); 1429 | captureStart = captureEnd = state.position; 1430 | hasPendingContent = false; 1431 | } 1432 | if (!is_WHITE_SPACE(ch)) { 1433 | captureEnd = state.position + 1; 1434 | } 1435 | ch = state.input.charCodeAt(++state.position); 1436 | } 1437 | captureSegment(state, captureStart, captureEnd, false); 1438 | if (state.result) { 1439 | return true; 1440 | } 1441 | state.kind = _kind; 1442 | state.result = _result; 1443 | return false; 1444 | } 1445 | function readSingleQuotedScalar(state, nodeIndent) { 1446 | var ch, captureStart, captureEnd; 1447 | ch = state.input.charCodeAt(state.position); 1448 | if (ch !== 39) { 1449 | return false; 1450 | } 1451 | state.kind = "scalar"; 1452 | state.result = ""; 1453 | state.position++; 1454 | captureStart = captureEnd = state.position; 1455 | while ((ch = state.input.charCodeAt(state.position)) !== 0) { 1456 | if (ch === 39) { 1457 | captureSegment(state, captureStart, state.position, true); 1458 | ch = state.input.charCodeAt(++state.position); 1459 | if (ch === 39) { 1460 | captureStart = state.position; 1461 | state.position++; 1462 | captureEnd = state.position; 1463 | } else { 1464 | return true; 1465 | } 1466 | } else if (is_EOL(ch)) { 1467 | captureSegment(state, captureStart, captureEnd, true); 1468 | writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent)); 1469 | captureStart = captureEnd = state.position; 1470 | } else if (state.position === state.lineStart && testDocumentSeparator(state)) { 1471 | throwError(state, "unexpected end of the document within a single quoted scalar"); 1472 | } else { 1473 | state.position++; 1474 | captureEnd = state.position; 1475 | } 1476 | } 1477 | throwError(state, "unexpected end of the stream within a single quoted scalar"); 1478 | } 1479 | function readDoubleQuotedScalar(state, nodeIndent) { 1480 | var captureStart, captureEnd, hexLength, hexResult, tmp, ch; 1481 | ch = state.input.charCodeAt(state.position); 1482 | if (ch !== 34) { 1483 | return false; 1484 | } 1485 | state.kind = "scalar"; 1486 | state.result = ""; 1487 | state.position++; 1488 | captureStart = captureEnd = state.position; 1489 | while ((ch = state.input.charCodeAt(state.position)) !== 0) { 1490 | if (ch === 34) { 1491 | captureSegment(state, captureStart, state.position, true); 1492 | state.position++; 1493 | return true; 1494 | } else if (ch === 92) { 1495 | captureSegment(state, captureStart, state.position, true); 1496 | ch = state.input.charCodeAt(++state.position); 1497 | if (is_EOL(ch)) { 1498 | skipSeparationSpace(state, false, nodeIndent); 1499 | } else if (ch < 256 && simpleEscapeCheck[ch]) { 1500 | state.result += simpleEscapeMap[ch]; 1501 | state.position++; 1502 | } else if ((tmp = escapedHexLen(ch)) > 0) { 1503 | hexLength = tmp; 1504 | hexResult = 0; 1505 | for (; hexLength > 0; hexLength--) { 1506 | ch = state.input.charCodeAt(++state.position); 1507 | if ((tmp = fromHexCode(ch)) >= 0) { 1508 | hexResult = (hexResult << 4) + tmp; 1509 | } else { 1510 | throwError(state, "expected hexadecimal character"); 1511 | } 1512 | } 1513 | state.result += charFromCodepoint(hexResult); 1514 | state.position++; 1515 | } else { 1516 | throwError(state, "unknown escape sequence"); 1517 | } 1518 | captureStart = captureEnd = state.position; 1519 | } else if (is_EOL(ch)) { 1520 | captureSegment(state, captureStart, captureEnd, true); 1521 | writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent)); 1522 | captureStart = captureEnd = state.position; 1523 | } else if (state.position === state.lineStart && testDocumentSeparator(state)) { 1524 | throwError(state, "unexpected end of the document within a double quoted scalar"); 1525 | } else { 1526 | state.position++; 1527 | captureEnd = state.position; 1528 | } 1529 | } 1530 | throwError(state, "unexpected end of the stream within a double quoted scalar"); 1531 | } 1532 | function readFlowCollection(state, nodeIndent) { 1533 | var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = /* @__PURE__ */ Object.create(null), keyNode, keyTag, valueNode, ch; 1534 | ch = state.input.charCodeAt(state.position); 1535 | if (ch === 91) { 1536 | terminator = 93; 1537 | isMapping = false; 1538 | _result = []; 1539 | } else if (ch === 123) { 1540 | terminator = 125; 1541 | isMapping = true; 1542 | _result = {}; 1543 | } else { 1544 | return false; 1545 | } 1546 | if (state.anchor !== null) { 1547 | state.anchorMap[state.anchor] = _result; 1548 | } 1549 | ch = state.input.charCodeAt(++state.position); 1550 | while (ch !== 0) { 1551 | skipSeparationSpace(state, true, nodeIndent); 1552 | ch = state.input.charCodeAt(state.position); 1553 | if (ch === terminator) { 1554 | state.position++; 1555 | state.tag = _tag; 1556 | state.anchor = _anchor; 1557 | state.kind = isMapping ? "mapping" : "sequence"; 1558 | state.result = _result; 1559 | return true; 1560 | } else if (!readNext) { 1561 | throwError(state, "missed comma between flow collection entries"); 1562 | } else if (ch === 44) { 1563 | throwError(state, "expected the node content, but found ','"); 1564 | } 1565 | keyTag = keyNode = valueNode = null; 1566 | isPair = isExplicitPair = false; 1567 | if (ch === 63) { 1568 | following = state.input.charCodeAt(state.position + 1); 1569 | if (is_WS_OR_EOL(following)) { 1570 | isPair = isExplicitPair = true; 1571 | state.position++; 1572 | skipSeparationSpace(state, true, nodeIndent); 1573 | } 1574 | } 1575 | _line = state.line; 1576 | _lineStart = state.lineStart; 1577 | _pos = state.position; 1578 | composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true); 1579 | keyTag = state.tag; 1580 | keyNode = state.result; 1581 | skipSeparationSpace(state, true, nodeIndent); 1582 | ch = state.input.charCodeAt(state.position); 1583 | if ((isExplicitPair || state.line === _line) && ch === 58) { 1584 | isPair = true; 1585 | ch = state.input.charCodeAt(++state.position); 1586 | skipSeparationSpace(state, true, nodeIndent); 1587 | composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true); 1588 | valueNode = state.result; 1589 | } 1590 | if (isMapping) { 1591 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos); 1592 | } else if (isPair) { 1593 | _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos)); 1594 | } else { 1595 | _result.push(keyNode); 1596 | } 1597 | skipSeparationSpace(state, true, nodeIndent); 1598 | ch = state.input.charCodeAt(state.position); 1599 | if (ch === 44) { 1600 | readNext = true; 1601 | ch = state.input.charCodeAt(++state.position); 1602 | } else { 1603 | readNext = false; 1604 | } 1605 | } 1606 | throwError(state, "unexpected end of the stream within a flow collection"); 1607 | } 1608 | function readBlockScalar(state, nodeIndent) { 1609 | var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch; 1610 | ch = state.input.charCodeAt(state.position); 1611 | if (ch === 124) { 1612 | folding = false; 1613 | } else if (ch === 62) { 1614 | folding = true; 1615 | } else { 1616 | return false; 1617 | } 1618 | state.kind = "scalar"; 1619 | state.result = ""; 1620 | while (ch !== 0) { 1621 | ch = state.input.charCodeAt(++state.position); 1622 | if (ch === 43 || ch === 45) { 1623 | if (CHOMPING_CLIP === chomping) { 1624 | chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP; 1625 | } else { 1626 | throwError(state, "repeat of a chomping mode identifier"); 1627 | } 1628 | } else if ((tmp = fromDecimalCode(ch)) >= 0) { 1629 | if (tmp === 0) { 1630 | throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one"); 1631 | } else if (!detectedIndent) { 1632 | textIndent = nodeIndent + tmp - 1; 1633 | detectedIndent = true; 1634 | } else { 1635 | throwError(state, "repeat of an indentation width identifier"); 1636 | } 1637 | } else { 1638 | break; 1639 | } 1640 | } 1641 | if (is_WHITE_SPACE(ch)) { 1642 | do { 1643 | ch = state.input.charCodeAt(++state.position); 1644 | } while (is_WHITE_SPACE(ch)); 1645 | if (ch === 35) { 1646 | do { 1647 | ch = state.input.charCodeAt(++state.position); 1648 | } while (!is_EOL(ch) && ch !== 0); 1649 | } 1650 | } 1651 | while (ch !== 0) { 1652 | readLineBreak(state); 1653 | state.lineIndent = 0; 1654 | ch = state.input.charCodeAt(state.position); 1655 | while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) { 1656 | state.lineIndent++; 1657 | ch = state.input.charCodeAt(++state.position); 1658 | } 1659 | if (!detectedIndent && state.lineIndent > textIndent) { 1660 | textIndent = state.lineIndent; 1661 | } 1662 | if (is_EOL(ch)) { 1663 | emptyLines++; 1664 | continue; 1665 | } 1666 | if (state.lineIndent < textIndent) { 1667 | if (chomping === CHOMPING_KEEP) { 1668 | state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines); 1669 | } else if (chomping === CHOMPING_CLIP) { 1670 | if (didReadContent) { 1671 | state.result += "\n"; 1672 | } 1673 | } 1674 | break; 1675 | } 1676 | if (folding) { 1677 | if (is_WHITE_SPACE(ch)) { 1678 | atMoreIndented = true; 1679 | state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines); 1680 | } else if (atMoreIndented) { 1681 | atMoreIndented = false; 1682 | state.result += common.repeat("\n", emptyLines + 1); 1683 | } else if (emptyLines === 0) { 1684 | if (didReadContent) { 1685 | state.result += " "; 1686 | } 1687 | } else { 1688 | state.result += common.repeat("\n", emptyLines); 1689 | } 1690 | } else { 1691 | state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines); 1692 | } 1693 | didReadContent = true; 1694 | detectedIndent = true; 1695 | emptyLines = 0; 1696 | captureStart = state.position; 1697 | while (!is_EOL(ch) && ch !== 0) { 1698 | ch = state.input.charCodeAt(++state.position); 1699 | } 1700 | captureSegment(state, captureStart, state.position, false); 1701 | } 1702 | return true; 1703 | } 1704 | function readBlockSequence(state, nodeIndent) { 1705 | var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch; 1706 | if (state.firstTabInLine !== -1) 1707 | return false; 1708 | if (state.anchor !== null) { 1709 | state.anchorMap[state.anchor] = _result; 1710 | } 1711 | ch = state.input.charCodeAt(state.position); 1712 | while (ch !== 0) { 1713 | if (state.firstTabInLine !== -1) { 1714 | state.position = state.firstTabInLine; 1715 | throwError(state, "tab characters must not be used in indentation"); 1716 | } 1717 | if (ch !== 45) { 1718 | break; 1719 | } 1720 | following = state.input.charCodeAt(state.position + 1); 1721 | if (!is_WS_OR_EOL(following)) { 1722 | break; 1723 | } 1724 | detected = true; 1725 | state.position++; 1726 | if (skipSeparationSpace(state, true, -1)) { 1727 | if (state.lineIndent <= nodeIndent) { 1728 | _result.push(null); 1729 | ch = state.input.charCodeAt(state.position); 1730 | continue; 1731 | } 1732 | } 1733 | _line = state.line; 1734 | composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true); 1735 | _result.push(state.result); 1736 | skipSeparationSpace(state, true, -1); 1737 | ch = state.input.charCodeAt(state.position); 1738 | if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) { 1739 | throwError(state, "bad indentation of a sequence entry"); 1740 | } else if (state.lineIndent < nodeIndent) { 1741 | break; 1742 | } 1743 | } 1744 | if (detected) { 1745 | state.tag = _tag; 1746 | state.anchor = _anchor; 1747 | state.kind = "sequence"; 1748 | state.result = _result; 1749 | return true; 1750 | } 1751 | return false; 1752 | } 1753 | function readBlockMapping(state, nodeIndent, flowIndent) { 1754 | var following, allowCompact, _line, _keyLine, _keyLineStart, _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = /* @__PURE__ */ Object.create(null), keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch; 1755 | if (state.firstTabInLine !== -1) 1756 | return false; 1757 | if (state.anchor !== null) { 1758 | state.anchorMap[state.anchor] = _result; 1759 | } 1760 | ch = state.input.charCodeAt(state.position); 1761 | while (ch !== 0) { 1762 | if (!atExplicitKey && state.firstTabInLine !== -1) { 1763 | state.position = state.firstTabInLine; 1764 | throwError(state, "tab characters must not be used in indentation"); 1765 | } 1766 | following = state.input.charCodeAt(state.position + 1); 1767 | _line = state.line; 1768 | if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) { 1769 | if (ch === 63) { 1770 | if (atExplicitKey) { 1771 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); 1772 | keyTag = keyNode = valueNode = null; 1773 | } 1774 | detected = true; 1775 | atExplicitKey = true; 1776 | allowCompact = true; 1777 | } else if (atExplicitKey) { 1778 | atExplicitKey = false; 1779 | allowCompact = true; 1780 | } else { 1781 | throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"); 1782 | } 1783 | state.position += 1; 1784 | ch = following; 1785 | } else { 1786 | _keyLine = state.line; 1787 | _keyLineStart = state.lineStart; 1788 | _keyPos = state.position; 1789 | if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) { 1790 | break; 1791 | } 1792 | if (state.line === _line) { 1793 | ch = state.input.charCodeAt(state.position); 1794 | while (is_WHITE_SPACE(ch)) { 1795 | ch = state.input.charCodeAt(++state.position); 1796 | } 1797 | if (ch === 58) { 1798 | ch = state.input.charCodeAt(++state.position); 1799 | if (!is_WS_OR_EOL(ch)) { 1800 | throwError(state, "a whitespace character is expected after the key-value separator within a block mapping"); 1801 | } 1802 | if (atExplicitKey) { 1803 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); 1804 | keyTag = keyNode = valueNode = null; 1805 | } 1806 | detected = true; 1807 | atExplicitKey = false; 1808 | allowCompact = false; 1809 | keyTag = state.tag; 1810 | keyNode = state.result; 1811 | } else if (detected) { 1812 | throwError(state, "can not read an implicit mapping pair; a colon is missed"); 1813 | } else { 1814 | state.tag = _tag; 1815 | state.anchor = _anchor; 1816 | return true; 1817 | } 1818 | } else if (detected) { 1819 | throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key"); 1820 | } else { 1821 | state.tag = _tag; 1822 | state.anchor = _anchor; 1823 | return true; 1824 | } 1825 | } 1826 | if (state.line === _line || state.lineIndent > nodeIndent) { 1827 | if (atExplicitKey) { 1828 | _keyLine = state.line; 1829 | _keyLineStart = state.lineStart; 1830 | _keyPos = state.position; 1831 | } 1832 | if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) { 1833 | if (atExplicitKey) { 1834 | keyNode = state.result; 1835 | } else { 1836 | valueNode = state.result; 1837 | } 1838 | } 1839 | if (!atExplicitKey) { 1840 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos); 1841 | keyTag = keyNode = valueNode = null; 1842 | } 1843 | skipSeparationSpace(state, true, -1); 1844 | ch = state.input.charCodeAt(state.position); 1845 | } 1846 | if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) { 1847 | throwError(state, "bad indentation of a mapping entry"); 1848 | } else if (state.lineIndent < nodeIndent) { 1849 | break; 1850 | } 1851 | } 1852 | if (atExplicitKey) { 1853 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); 1854 | } 1855 | if (detected) { 1856 | state.tag = _tag; 1857 | state.anchor = _anchor; 1858 | state.kind = "mapping"; 1859 | state.result = _result; 1860 | } 1861 | return detected; 1862 | } 1863 | function readTagProperty(state) { 1864 | var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch; 1865 | ch = state.input.charCodeAt(state.position); 1866 | if (ch !== 33) 1867 | return false; 1868 | if (state.tag !== null) { 1869 | throwError(state, "duplication of a tag property"); 1870 | } 1871 | ch = state.input.charCodeAt(++state.position); 1872 | if (ch === 60) { 1873 | isVerbatim = true; 1874 | ch = state.input.charCodeAt(++state.position); 1875 | } else if (ch === 33) { 1876 | isNamed = true; 1877 | tagHandle = "!!"; 1878 | ch = state.input.charCodeAt(++state.position); 1879 | } else { 1880 | tagHandle = "!"; 1881 | } 1882 | _position = state.position; 1883 | if (isVerbatim) { 1884 | do { 1885 | ch = state.input.charCodeAt(++state.position); 1886 | } while (ch !== 0 && ch !== 62); 1887 | if (state.position < state.length) { 1888 | tagName = state.input.slice(_position, state.position); 1889 | ch = state.input.charCodeAt(++state.position); 1890 | } else { 1891 | throwError(state, "unexpected end of the stream within a verbatim tag"); 1892 | } 1893 | } else { 1894 | while (ch !== 0 && !is_WS_OR_EOL(ch)) { 1895 | if (ch === 33) { 1896 | if (!isNamed) { 1897 | tagHandle = state.input.slice(_position - 1, state.position + 1); 1898 | if (!PATTERN_TAG_HANDLE.test(tagHandle)) { 1899 | throwError(state, "named tag handle cannot contain such characters"); 1900 | } 1901 | isNamed = true; 1902 | _position = state.position + 1; 1903 | } else { 1904 | throwError(state, "tag suffix cannot contain exclamation marks"); 1905 | } 1906 | } 1907 | ch = state.input.charCodeAt(++state.position); 1908 | } 1909 | tagName = state.input.slice(_position, state.position); 1910 | if (PATTERN_FLOW_INDICATORS.test(tagName)) { 1911 | throwError(state, "tag suffix cannot contain flow indicator characters"); 1912 | } 1913 | } 1914 | if (tagName && !PATTERN_TAG_URI.test(tagName)) { 1915 | throwError(state, "tag name cannot contain such characters: " + tagName); 1916 | } 1917 | try { 1918 | tagName = decodeURIComponent(tagName); 1919 | } catch (err) { 1920 | throwError(state, "tag name is malformed: " + tagName); 1921 | } 1922 | if (isVerbatim) { 1923 | state.tag = tagName; 1924 | } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) { 1925 | state.tag = state.tagMap[tagHandle] + tagName; 1926 | } else if (tagHandle === "!") { 1927 | state.tag = "!" + tagName; 1928 | } else if (tagHandle === "!!") { 1929 | state.tag = "tag:yaml.org,2002:" + tagName; 1930 | } else { 1931 | throwError(state, 'undeclared tag handle "' + tagHandle + '"'); 1932 | } 1933 | return true; 1934 | } 1935 | function readAnchorProperty(state) { 1936 | var _position, ch; 1937 | ch = state.input.charCodeAt(state.position); 1938 | if (ch !== 38) 1939 | return false; 1940 | if (state.anchor !== null) { 1941 | throwError(state, "duplication of an anchor property"); 1942 | } 1943 | ch = state.input.charCodeAt(++state.position); 1944 | _position = state.position; 1945 | while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) { 1946 | ch = state.input.charCodeAt(++state.position); 1947 | } 1948 | if (state.position === _position) { 1949 | throwError(state, "name of an anchor node must contain at least one character"); 1950 | } 1951 | state.anchor = state.input.slice(_position, state.position); 1952 | return true; 1953 | } 1954 | function readAlias(state) { 1955 | var _position, alias, ch; 1956 | ch = state.input.charCodeAt(state.position); 1957 | if (ch !== 42) 1958 | return false; 1959 | ch = state.input.charCodeAt(++state.position); 1960 | _position = state.position; 1961 | while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) { 1962 | ch = state.input.charCodeAt(++state.position); 1963 | } 1964 | if (state.position === _position) { 1965 | throwError(state, "name of an alias node must contain at least one character"); 1966 | } 1967 | alias = state.input.slice(_position, state.position); 1968 | if (!_hasOwnProperty.call(state.anchorMap, alias)) { 1969 | throwError(state, 'unidentified alias "' + alias + '"'); 1970 | } 1971 | state.result = state.anchorMap[alias]; 1972 | skipSeparationSpace(state, true, -1); 1973 | return true; 1974 | } 1975 | function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) { 1976 | var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type, flowIndent, blockIndent; 1977 | if (state.listener !== null) { 1978 | state.listener("open", state); 1979 | } 1980 | state.tag = null; 1981 | state.anchor = null; 1982 | state.kind = null; 1983 | state.result = null; 1984 | allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext; 1985 | if (allowToSeek) { 1986 | if (skipSeparationSpace(state, true, -1)) { 1987 | atNewLine = true; 1988 | if (state.lineIndent > parentIndent) { 1989 | indentStatus = 1; 1990 | } else if (state.lineIndent === parentIndent) { 1991 | indentStatus = 0; 1992 | } else if (state.lineIndent < parentIndent) { 1993 | indentStatus = -1; 1994 | } 1995 | } 1996 | } 1997 | if (indentStatus === 1) { 1998 | while (readTagProperty(state) || readAnchorProperty(state)) { 1999 | if (skipSeparationSpace(state, true, -1)) { 2000 | atNewLine = true; 2001 | allowBlockCollections = allowBlockStyles; 2002 | if (state.lineIndent > parentIndent) { 2003 | indentStatus = 1; 2004 | } else if (state.lineIndent === parentIndent) { 2005 | indentStatus = 0; 2006 | } else if (state.lineIndent < parentIndent) { 2007 | indentStatus = -1; 2008 | } 2009 | } else { 2010 | allowBlockCollections = false; 2011 | } 2012 | } 2013 | } 2014 | if (allowBlockCollections) { 2015 | allowBlockCollections = atNewLine || allowCompact; 2016 | } 2017 | if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) { 2018 | if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) { 2019 | flowIndent = parentIndent; 2020 | } else { 2021 | flowIndent = parentIndent + 1; 2022 | } 2023 | blockIndent = state.position - state.lineStart; 2024 | if (indentStatus === 1) { 2025 | if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) { 2026 | hasContent = true; 2027 | } else { 2028 | if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) { 2029 | hasContent = true; 2030 | } else if (readAlias(state)) { 2031 | hasContent = true; 2032 | if (state.tag !== null || state.anchor !== null) { 2033 | throwError(state, "alias node should not have any properties"); 2034 | } 2035 | } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) { 2036 | hasContent = true; 2037 | if (state.tag === null) { 2038 | state.tag = "?"; 2039 | } 2040 | } 2041 | if (state.anchor !== null) { 2042 | state.anchorMap[state.anchor] = state.result; 2043 | } 2044 | } 2045 | } else if (indentStatus === 0) { 2046 | hasContent = allowBlockCollections && readBlockSequence(state, blockIndent); 2047 | } 2048 | } 2049 | if (state.tag === null) { 2050 | if (state.anchor !== null) { 2051 | state.anchorMap[state.anchor] = state.result; 2052 | } 2053 | } else if (state.tag === "?") { 2054 | if (state.result !== null && state.kind !== "scalar") { 2055 | throwError(state, 'unacceptable node kind for ! tag; it should be "scalar", not "' + state.kind + '"'); 2056 | } 2057 | for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) { 2058 | type = state.implicitTypes[typeIndex]; 2059 | if (type.resolve(state.result)) { 2060 | state.result = type.construct(state.result); 2061 | state.tag = type.tag; 2062 | if (state.anchor !== null) { 2063 | state.anchorMap[state.anchor] = state.result; 2064 | } 2065 | break; 2066 | } 2067 | } 2068 | } else if (state.tag !== "!") { 2069 | if (_hasOwnProperty.call(state.typeMap[state.kind || "fallback"], state.tag)) { 2070 | type = state.typeMap[state.kind || "fallback"][state.tag]; 2071 | } else { 2072 | type = null; 2073 | typeList = state.typeMap.multi[state.kind || "fallback"]; 2074 | for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) { 2075 | if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) { 2076 | type = typeList[typeIndex]; 2077 | break; 2078 | } 2079 | } 2080 | } 2081 | if (!type) { 2082 | throwError(state, "unknown tag !<" + state.tag + ">"); 2083 | } 2084 | if (state.result !== null && type.kind !== state.kind) { 2085 | throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"'); 2086 | } 2087 | if (!type.resolve(state.result, state.tag)) { 2088 | throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag"); 2089 | } else { 2090 | state.result = type.construct(state.result, state.tag); 2091 | if (state.anchor !== null) { 2092 | state.anchorMap[state.anchor] = state.result; 2093 | } 2094 | } 2095 | } 2096 | if (state.listener !== null) { 2097 | state.listener("close", state); 2098 | } 2099 | return state.tag !== null || state.anchor !== null || hasContent; 2100 | } 2101 | function readDocument(state) { 2102 | var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch; 2103 | state.version = null; 2104 | state.checkLineBreaks = state.legacy; 2105 | state.tagMap = /* @__PURE__ */ Object.create(null); 2106 | state.anchorMap = /* @__PURE__ */ Object.create(null); 2107 | while ((ch = state.input.charCodeAt(state.position)) !== 0) { 2108 | skipSeparationSpace(state, true, -1); 2109 | ch = state.input.charCodeAt(state.position); 2110 | if (state.lineIndent > 0 || ch !== 37) { 2111 | break; 2112 | } 2113 | hasDirectives = true; 2114 | ch = state.input.charCodeAt(++state.position); 2115 | _position = state.position; 2116 | while (ch !== 0 && !is_WS_OR_EOL(ch)) { 2117 | ch = state.input.charCodeAt(++state.position); 2118 | } 2119 | directiveName = state.input.slice(_position, state.position); 2120 | directiveArgs = []; 2121 | if (directiveName.length < 1) { 2122 | throwError(state, "directive name must not be less than one character in length"); 2123 | } 2124 | while (ch !== 0) { 2125 | while (is_WHITE_SPACE(ch)) { 2126 | ch = state.input.charCodeAt(++state.position); 2127 | } 2128 | if (ch === 35) { 2129 | do { 2130 | ch = state.input.charCodeAt(++state.position); 2131 | } while (ch !== 0 && !is_EOL(ch)); 2132 | break; 2133 | } 2134 | if (is_EOL(ch)) 2135 | break; 2136 | _position = state.position; 2137 | while (ch !== 0 && !is_WS_OR_EOL(ch)) { 2138 | ch = state.input.charCodeAt(++state.position); 2139 | } 2140 | directiveArgs.push(state.input.slice(_position, state.position)); 2141 | } 2142 | if (ch !== 0) 2143 | readLineBreak(state); 2144 | if (_hasOwnProperty.call(directiveHandlers, directiveName)) { 2145 | directiveHandlers[directiveName](state, directiveName, directiveArgs); 2146 | } else { 2147 | throwWarning(state, 'unknown document directive "' + directiveName + '"'); 2148 | } 2149 | } 2150 | skipSeparationSpace(state, true, -1); 2151 | if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) { 2152 | state.position += 3; 2153 | skipSeparationSpace(state, true, -1); 2154 | } else if (hasDirectives) { 2155 | throwError(state, "directives end mark is expected"); 2156 | } 2157 | composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true); 2158 | skipSeparationSpace(state, true, -1); 2159 | if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) { 2160 | throwWarning(state, "non-ASCII line breaks are interpreted as content"); 2161 | } 2162 | state.documents.push(state.result); 2163 | if (state.position === state.lineStart && testDocumentSeparator(state)) { 2164 | if (state.input.charCodeAt(state.position) === 46) { 2165 | state.position += 3; 2166 | skipSeparationSpace(state, true, -1); 2167 | } 2168 | return; 2169 | } 2170 | if (state.position < state.length - 1) { 2171 | throwError(state, "end of the stream or a document separator is expected"); 2172 | } else { 2173 | return; 2174 | } 2175 | } 2176 | function loadDocuments(input, options) { 2177 | input = String(input); 2178 | options = options || {}; 2179 | if (input.length !== 0) { 2180 | if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) { 2181 | input += "\n"; 2182 | } 2183 | if (input.charCodeAt(0) === 65279) { 2184 | input = input.slice(1); 2185 | } 2186 | } 2187 | var state = new State(input, options); 2188 | var nullpos = input.indexOf("\0"); 2189 | if (nullpos !== -1) { 2190 | state.position = nullpos; 2191 | throwError(state, "null byte is not allowed in input"); 2192 | } 2193 | state.input += "\0"; 2194 | while (state.input.charCodeAt(state.position) === 32) { 2195 | state.lineIndent += 1; 2196 | state.position += 1; 2197 | } 2198 | while (state.position < state.length - 1) { 2199 | readDocument(state); 2200 | } 2201 | return state.documents; 2202 | } 2203 | function loadAll(input, iterator, options) { 2204 | if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") { 2205 | options = iterator; 2206 | iterator = null; 2207 | } 2208 | var documents = loadDocuments(input, options); 2209 | if (typeof iterator !== "function") { 2210 | return documents; 2211 | } 2212 | for (var index = 0, length = documents.length; index < length; index += 1) { 2213 | iterator(documents[index]); 2214 | } 2215 | } 2216 | function load(input, options) { 2217 | var documents = loadDocuments(input, options); 2218 | if (documents.length === 0) { 2219 | return void 0; 2220 | } else if (documents.length === 1) { 2221 | return documents[0]; 2222 | } 2223 | throw new YAMLException("expected a single document in the stream, but found more"); 2224 | } 2225 | module.exports.loadAll = loadAll; 2226 | module.exports.load = load; 2227 | } 2228 | }); 2229 | 2230 | // node_modules/js-yaml/lib/dumper.js 2231 | var require_dumper = __commonJS({ 2232 | "node_modules/js-yaml/lib/dumper.js"(exports, module) { 2233 | "use strict"; 2234 | init_modules_watch_stub(); 2235 | var common = require_common(); 2236 | var YAMLException = require_exception(); 2237 | var DEFAULT_SCHEMA = require_default(); 2238 | var _toString = Object.prototype.toString; 2239 | var _hasOwnProperty = Object.prototype.hasOwnProperty; 2240 | var CHAR_BOM = 65279; 2241 | var CHAR_TAB = 9; 2242 | var CHAR_LINE_FEED = 10; 2243 | var CHAR_CARRIAGE_RETURN = 13; 2244 | var CHAR_SPACE = 32; 2245 | var CHAR_EXCLAMATION = 33; 2246 | var CHAR_DOUBLE_QUOTE = 34; 2247 | var CHAR_SHARP = 35; 2248 | var CHAR_PERCENT = 37; 2249 | var CHAR_AMPERSAND = 38; 2250 | var CHAR_SINGLE_QUOTE = 39; 2251 | var CHAR_ASTERISK = 42; 2252 | var CHAR_COMMA = 44; 2253 | var CHAR_MINUS = 45; 2254 | var CHAR_COLON = 58; 2255 | var CHAR_EQUALS = 61; 2256 | var CHAR_GREATER_THAN = 62; 2257 | var CHAR_QUESTION = 63; 2258 | var CHAR_COMMERCIAL_AT = 64; 2259 | var CHAR_LEFT_SQUARE_BRACKET = 91; 2260 | var CHAR_RIGHT_SQUARE_BRACKET = 93; 2261 | var CHAR_GRAVE_ACCENT = 96; 2262 | var CHAR_LEFT_CURLY_BRACKET = 123; 2263 | var CHAR_VERTICAL_LINE = 124; 2264 | var CHAR_RIGHT_CURLY_BRACKET = 125; 2265 | var ESCAPE_SEQUENCES = {}; 2266 | ESCAPE_SEQUENCES[0] = "\\0"; 2267 | ESCAPE_SEQUENCES[7] = "\\a"; 2268 | ESCAPE_SEQUENCES[8] = "\\b"; 2269 | ESCAPE_SEQUENCES[9] = "\\t"; 2270 | ESCAPE_SEQUENCES[10] = "\\n"; 2271 | ESCAPE_SEQUENCES[11] = "\\v"; 2272 | ESCAPE_SEQUENCES[12] = "\\f"; 2273 | ESCAPE_SEQUENCES[13] = "\\r"; 2274 | ESCAPE_SEQUENCES[27] = "\\e"; 2275 | ESCAPE_SEQUENCES[34] = '\\"'; 2276 | ESCAPE_SEQUENCES[92] = "\\\\"; 2277 | ESCAPE_SEQUENCES[133] = "\\N"; 2278 | ESCAPE_SEQUENCES[160] = "\\_"; 2279 | ESCAPE_SEQUENCES[8232] = "\\L"; 2280 | ESCAPE_SEQUENCES[8233] = "\\P"; 2281 | var DEPRECATED_BOOLEANS_SYNTAX = [ 2282 | "y", 2283 | "Y", 2284 | "yes", 2285 | "Yes", 2286 | "YES", 2287 | "on", 2288 | "On", 2289 | "ON", 2290 | "n", 2291 | "N", 2292 | "no", 2293 | "No", 2294 | "NO", 2295 | "off", 2296 | "Off", 2297 | "OFF" 2298 | ]; 2299 | var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/; 2300 | function compileStyleMap(schema, map) { 2301 | var result, keys, index, length, tag, style, type; 2302 | if (map === null) 2303 | return {}; 2304 | result = {}; 2305 | keys = Object.keys(map); 2306 | for (index = 0, length = keys.length; index < length; index += 1) { 2307 | tag = keys[index]; 2308 | style = String(map[tag]); 2309 | if (tag.slice(0, 2) === "!!") { 2310 | tag = "tag:yaml.org,2002:" + tag.slice(2); 2311 | } 2312 | type = schema.compiledTypeMap["fallback"][tag]; 2313 | if (type && _hasOwnProperty.call(type.styleAliases, style)) { 2314 | style = type.styleAliases[style]; 2315 | } 2316 | result[tag] = style; 2317 | } 2318 | return result; 2319 | } 2320 | function encodeHex(character) { 2321 | var string, handle, length; 2322 | string = character.toString(16).toUpperCase(); 2323 | if (character <= 255) { 2324 | handle = "x"; 2325 | length = 2; 2326 | } else if (character <= 65535) { 2327 | handle = "u"; 2328 | length = 4; 2329 | } else if (character <= 4294967295) { 2330 | handle = "U"; 2331 | length = 8; 2332 | } else { 2333 | throw new YAMLException("code point within a string may not be greater than 0xFFFFFFFF"); 2334 | } 2335 | return "\\" + handle + common.repeat("0", length - string.length) + string; 2336 | } 2337 | var QUOTING_TYPE_SINGLE = 1; 2338 | var QUOTING_TYPE_DOUBLE = 2; 2339 | function State(options) { 2340 | this.schema = options["schema"] || DEFAULT_SCHEMA; 2341 | this.indent = Math.max(1, options["indent"] || 2); 2342 | this.noArrayIndent = options["noArrayIndent"] || false; 2343 | this.skipInvalid = options["skipInvalid"] || false; 2344 | this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"]; 2345 | this.styleMap = compileStyleMap(this.schema, options["styles"] || null); 2346 | this.sortKeys = options["sortKeys"] || false; 2347 | this.lineWidth = options["lineWidth"] || 80; 2348 | this.noRefs = options["noRefs"] || false; 2349 | this.noCompatMode = options["noCompatMode"] || false; 2350 | this.condenseFlow = options["condenseFlow"] || false; 2351 | this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE; 2352 | this.forceQuotes = options["forceQuotes"] || false; 2353 | this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null; 2354 | this.implicitTypes = this.schema.compiledImplicit; 2355 | this.explicitTypes = this.schema.compiledExplicit; 2356 | this.tag = null; 2357 | this.result = ""; 2358 | this.duplicates = []; 2359 | this.usedDuplicates = null; 2360 | } 2361 | function indentString(string, spaces) { 2362 | var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length; 2363 | while (position < length) { 2364 | next = string.indexOf("\n", position); 2365 | if (next === -1) { 2366 | line = string.slice(position); 2367 | position = length; 2368 | } else { 2369 | line = string.slice(position, next + 1); 2370 | position = next + 1; 2371 | } 2372 | if (line.length && line !== "\n") 2373 | result += ind; 2374 | result += line; 2375 | } 2376 | return result; 2377 | } 2378 | function generateNextLine(state, level) { 2379 | return "\n" + common.repeat(" ", state.indent * level); 2380 | } 2381 | function testImplicitResolving(state, str) { 2382 | var index, length, type; 2383 | for (index = 0, length = state.implicitTypes.length; index < length; index += 1) { 2384 | type = state.implicitTypes[index]; 2385 | if (type.resolve(str)) { 2386 | return true; 2387 | } 2388 | } 2389 | return false; 2390 | } 2391 | function isWhitespace(c) { 2392 | return c === CHAR_SPACE || c === CHAR_TAB; 2393 | } 2394 | function isPrintable(c) { 2395 | return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111; 2396 | } 2397 | function isNsCharOrWhitespace(c) { 2398 | return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED; 2399 | } 2400 | function isPlainSafe(c, prev, inblock) { 2401 | var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c); 2402 | var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c); 2403 | return ( 2404 | // ns-plain-safe 2405 | (inblock ? ( 2406 | // c = flow-in 2407 | cIsNsCharOrWhitespace 2408 | ) : cIsNsCharOrWhitespace && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && c !== CHAR_SHARP && !(prev === CHAR_COLON && !cIsNsChar) || isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP || prev === CHAR_COLON && cIsNsChar 2409 | ); 2410 | } 2411 | function isPlainSafeFirst(c) { 2412 | return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT; 2413 | } 2414 | function isPlainSafeLast(c) { 2415 | return !isWhitespace(c) && c !== CHAR_COLON; 2416 | } 2417 | function codePointAt(string, pos) { 2418 | var first = string.charCodeAt(pos), second; 2419 | if (first >= 55296 && first <= 56319 && pos + 1 < string.length) { 2420 | second = string.charCodeAt(pos + 1); 2421 | if (second >= 56320 && second <= 57343) { 2422 | return (first - 55296) * 1024 + second - 56320 + 65536; 2423 | } 2424 | } 2425 | return first; 2426 | } 2427 | function needIndentIndicator(string) { 2428 | var leadingSpaceRe = /^\n* /; 2429 | return leadingSpaceRe.test(string); 2430 | } 2431 | var STYLE_PLAIN = 1; 2432 | var STYLE_SINGLE = 2; 2433 | var STYLE_LITERAL = 3; 2434 | var STYLE_FOLDED = 4; 2435 | var STYLE_DOUBLE = 5; 2436 | function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) { 2437 | var i; 2438 | var char = 0; 2439 | var prevChar = null; 2440 | var hasLineBreak = false; 2441 | var hasFoldableLine = false; 2442 | var shouldTrackWidth = lineWidth !== -1; 2443 | var previousLineBreak = -1; 2444 | var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1)); 2445 | if (singleLineOnly || forceQuotes) { 2446 | for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) { 2447 | char = codePointAt(string, i); 2448 | if (!isPrintable(char)) { 2449 | return STYLE_DOUBLE; 2450 | } 2451 | plain = plain && isPlainSafe(char, prevChar, inblock); 2452 | prevChar = char; 2453 | } 2454 | } else { 2455 | for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) { 2456 | char = codePointAt(string, i); 2457 | if (char === CHAR_LINE_FEED) { 2458 | hasLineBreak = true; 2459 | if (shouldTrackWidth) { 2460 | hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented. 2461 | i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " "; 2462 | previousLineBreak = i; 2463 | } 2464 | } else if (!isPrintable(char)) { 2465 | return STYLE_DOUBLE; 2466 | } 2467 | plain = plain && isPlainSafe(char, prevChar, inblock); 2468 | prevChar = char; 2469 | } 2470 | hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " "); 2471 | } 2472 | if (!hasLineBreak && !hasFoldableLine) { 2473 | if (plain && !forceQuotes && !testAmbiguousType(string)) { 2474 | return STYLE_PLAIN; 2475 | } 2476 | return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE; 2477 | } 2478 | if (indentPerLevel > 9 && needIndentIndicator(string)) { 2479 | return STYLE_DOUBLE; 2480 | } 2481 | if (!forceQuotes) { 2482 | return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL; 2483 | } 2484 | return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE; 2485 | } 2486 | function writeScalar(state, string, level, iskey, inblock) { 2487 | state.dump = function () { 2488 | if (string.length === 0) { 2489 | return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''"; 2490 | } 2491 | if (!state.noCompatMode) { 2492 | if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) { 2493 | return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'"; 2494 | } 2495 | } 2496 | var indent = state.indent * Math.max(1, level); 2497 | var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent); 2498 | var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel; 2499 | function testAmbiguity(string2) { 2500 | return testImplicitResolving(state, string2); 2501 | } 2502 | switch (chooseScalarStyle( 2503 | string, 2504 | singleLineOnly, 2505 | state.indent, 2506 | lineWidth, 2507 | testAmbiguity, 2508 | state.quotingType, 2509 | state.forceQuotes && !iskey, 2510 | inblock 2511 | )) { 2512 | case STYLE_PLAIN: 2513 | return string; 2514 | case STYLE_SINGLE: 2515 | return "'" + string.replace(/'/g, "''") + "'"; 2516 | case STYLE_LITERAL: 2517 | return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent)); 2518 | case STYLE_FOLDED: 2519 | return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent)); 2520 | case STYLE_DOUBLE: 2521 | return '"' + escapeString(string, lineWidth) + '"'; 2522 | default: 2523 | throw new YAMLException("impossible error: invalid scalar style"); 2524 | } 2525 | }(); 2526 | } 2527 | function blockHeader(string, indentPerLevel) { 2528 | var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : ""; 2529 | var clip = string[string.length - 1] === "\n"; 2530 | var keep = clip && (string[string.length - 2] === "\n" || string === "\n"); 2531 | var chomp = keep ? "+" : clip ? "" : "-"; 2532 | return indentIndicator + chomp + "\n"; 2533 | } 2534 | function dropEndingNewline(string) { 2535 | return string[string.length - 1] === "\n" ? string.slice(0, -1) : string; 2536 | } 2537 | function foldString(string, width) { 2538 | var lineRe = /(\n+)([^\n]*)/g; 2539 | var result = function () { 2540 | var nextLF = string.indexOf("\n"); 2541 | nextLF = nextLF !== -1 ? nextLF : string.length; 2542 | lineRe.lastIndex = nextLF; 2543 | return foldLine(string.slice(0, nextLF), width); 2544 | }(); 2545 | var prevMoreIndented = string[0] === "\n" || string[0] === " "; 2546 | var moreIndented; 2547 | var match; 2548 | while (match = lineRe.exec(string)) { 2549 | var prefix = match[1], line = match[2]; 2550 | moreIndented = line[0] === " "; 2551 | result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width); 2552 | prevMoreIndented = moreIndented; 2553 | } 2554 | return result; 2555 | } 2556 | function foldLine(line, width) { 2557 | if (line === "" || line[0] === " ") 2558 | return line; 2559 | var breakRe = / [^ ]/g; 2560 | var match; 2561 | var start = 0, end, curr = 0, next = 0; 2562 | var result = ""; 2563 | while (match = breakRe.exec(line)) { 2564 | next = match.index; 2565 | if (next - start > width) { 2566 | end = curr > start ? curr : next; 2567 | result += "\n" + line.slice(start, end); 2568 | start = end + 1; 2569 | } 2570 | curr = next; 2571 | } 2572 | result += "\n"; 2573 | if (line.length - start > width && curr > start) { 2574 | result += line.slice(start, curr) + "\n" + line.slice(curr + 1); 2575 | } else { 2576 | result += line.slice(start); 2577 | } 2578 | return result.slice(1); 2579 | } 2580 | function escapeString(string) { 2581 | var result = ""; 2582 | var char = 0; 2583 | var escapeSeq; 2584 | for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) { 2585 | char = codePointAt(string, i); 2586 | escapeSeq = ESCAPE_SEQUENCES[char]; 2587 | if (!escapeSeq && isPrintable(char)) { 2588 | result += string[i]; 2589 | if (char >= 65536) 2590 | result += string[i + 1]; 2591 | } else { 2592 | result += escapeSeq || encodeHex(char); 2593 | } 2594 | } 2595 | return result; 2596 | } 2597 | function writeFlowSequence(state, level, object) { 2598 | var _result = "", _tag = state.tag, index, length, value; 2599 | for (index = 0, length = object.length; index < length; index += 1) { 2600 | value = object[index]; 2601 | if (state.replacer) { 2602 | value = state.replacer.call(object, String(index), value); 2603 | } 2604 | if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) { 2605 | if (_result !== "") 2606 | _result += "," + (!state.condenseFlow ? " " : ""); 2607 | _result += state.dump; 2608 | } 2609 | } 2610 | state.tag = _tag; 2611 | state.dump = "[" + _result + "]"; 2612 | } 2613 | function writeBlockSequence(state, level, object, compact) { 2614 | var _result = "", _tag = state.tag, index, length, value; 2615 | for (index = 0, length = object.length; index < length; index += 1) { 2616 | value = object[index]; 2617 | if (state.replacer) { 2618 | value = state.replacer.call(object, String(index), value); 2619 | } 2620 | if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) { 2621 | if (!compact || _result !== "") { 2622 | _result += generateNextLine(state, level); 2623 | } 2624 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) { 2625 | _result += "-"; 2626 | } else { 2627 | _result += "- "; 2628 | } 2629 | _result += state.dump; 2630 | } 2631 | } 2632 | state.tag = _tag; 2633 | state.dump = _result || "[]"; 2634 | } 2635 | function writeFlowMapping(state, level, object) { 2636 | var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer; 2637 | for (index = 0, length = objectKeyList.length; index < length; index += 1) { 2638 | pairBuffer = ""; 2639 | if (_result !== "") 2640 | pairBuffer += ", "; 2641 | if (state.condenseFlow) 2642 | pairBuffer += '"'; 2643 | objectKey = objectKeyList[index]; 2644 | objectValue = object[objectKey]; 2645 | if (state.replacer) { 2646 | objectValue = state.replacer.call(object, objectKey, objectValue); 2647 | } 2648 | if (!writeNode(state, level, objectKey, false, false)) { 2649 | continue; 2650 | } 2651 | if (state.dump.length > 1024) 2652 | pairBuffer += "? "; 2653 | pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " "); 2654 | if (!writeNode(state, level, objectValue, false, false)) { 2655 | continue; 2656 | } 2657 | pairBuffer += state.dump; 2658 | _result += pairBuffer; 2659 | } 2660 | state.tag = _tag; 2661 | state.dump = "{" + _result + "}"; 2662 | } 2663 | function writeBlockMapping(state, level, object, compact) { 2664 | var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer; 2665 | if (state.sortKeys === true) { 2666 | objectKeyList.sort(); 2667 | } else if (typeof state.sortKeys === "function") { 2668 | objectKeyList.sort(state.sortKeys); 2669 | } else if (state.sortKeys) { 2670 | throw new YAMLException("sortKeys must be a boolean or a function"); 2671 | } 2672 | for (index = 0, length = objectKeyList.length; index < length; index += 1) { 2673 | pairBuffer = ""; 2674 | if (!compact || _result !== "") { 2675 | pairBuffer += generateNextLine(state, level); 2676 | } 2677 | objectKey = objectKeyList[index]; 2678 | objectValue = object[objectKey]; 2679 | if (state.replacer) { 2680 | objectValue = state.replacer.call(object, objectKey, objectValue); 2681 | } 2682 | if (!writeNode(state, level + 1, objectKey, true, true, true)) { 2683 | continue; 2684 | } 2685 | explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024; 2686 | if (explicitPair) { 2687 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) { 2688 | pairBuffer += "?"; 2689 | } else { 2690 | pairBuffer += "? "; 2691 | } 2692 | } 2693 | pairBuffer += state.dump; 2694 | if (explicitPair) { 2695 | pairBuffer += generateNextLine(state, level); 2696 | } 2697 | if (!writeNode(state, level + 1, objectValue, true, explicitPair)) { 2698 | continue; 2699 | } 2700 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) { 2701 | pairBuffer += ":"; 2702 | } else { 2703 | pairBuffer += ": "; 2704 | } 2705 | pairBuffer += state.dump; 2706 | _result += pairBuffer; 2707 | } 2708 | state.tag = _tag; 2709 | state.dump = _result || "{}"; 2710 | } 2711 | function detectType(state, object, explicit) { 2712 | var _result, typeList, index, length, type, style; 2713 | typeList = explicit ? state.explicitTypes : state.implicitTypes; 2714 | for (index = 0, length = typeList.length; index < length; index += 1) { 2715 | type = typeList[index]; 2716 | if ((type.instanceOf || type.predicate) && (!type.instanceOf || typeof object === "object" && object instanceof type.instanceOf) && (!type.predicate || type.predicate(object))) { 2717 | if (explicit) { 2718 | if (type.multi && type.representName) { 2719 | state.tag = type.representName(object); 2720 | } else { 2721 | state.tag = type.tag; 2722 | } 2723 | } else { 2724 | state.tag = "?"; 2725 | } 2726 | if (type.represent) { 2727 | style = state.styleMap[type.tag] || type.defaultStyle; 2728 | if (_toString.call(type.represent) === "[object Function]") { 2729 | _result = type.represent(object, style); 2730 | } else if (_hasOwnProperty.call(type.represent, style)) { 2731 | _result = type.represent[style](object, style); 2732 | } else { 2733 | throw new YAMLException("!<" + type.tag + '> tag resolver accepts not "' + style + '" style'); 2734 | } 2735 | state.dump = _result; 2736 | } 2737 | return true; 2738 | } 2739 | } 2740 | return false; 2741 | } 2742 | function writeNode(state, level, object, block, compact, iskey, isblockseq) { 2743 | state.tag = null; 2744 | state.dump = object; 2745 | if (!detectType(state, object, false)) { 2746 | detectType(state, object, true); 2747 | } 2748 | var type = _toString.call(state.dump); 2749 | var inblock = block; 2750 | var tagStr; 2751 | if (block) { 2752 | block = state.flowLevel < 0 || state.flowLevel > level; 2753 | } 2754 | var objectOrArray = type === "[object Object]" || type === "[object Array]", duplicateIndex, duplicate; 2755 | if (objectOrArray) { 2756 | duplicateIndex = state.duplicates.indexOf(object); 2757 | duplicate = duplicateIndex !== -1; 2758 | } 2759 | if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) { 2760 | compact = false; 2761 | } 2762 | if (duplicate && state.usedDuplicates[duplicateIndex]) { 2763 | state.dump = "*ref_" + duplicateIndex; 2764 | } else { 2765 | if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) { 2766 | state.usedDuplicates[duplicateIndex] = true; 2767 | } 2768 | if (type === "[object Object]") { 2769 | if (block && Object.keys(state.dump).length !== 0) { 2770 | writeBlockMapping(state, level, state.dump, compact); 2771 | if (duplicate) { 2772 | state.dump = "&ref_" + duplicateIndex + state.dump; 2773 | } 2774 | } else { 2775 | writeFlowMapping(state, level, state.dump); 2776 | if (duplicate) { 2777 | state.dump = "&ref_" + duplicateIndex + " " + state.dump; 2778 | } 2779 | } 2780 | } else if (type === "[object Array]") { 2781 | if (block && state.dump.length !== 0) { 2782 | if (state.noArrayIndent && !isblockseq && level > 0) { 2783 | writeBlockSequence(state, level - 1, state.dump, compact); 2784 | } else { 2785 | writeBlockSequence(state, level, state.dump, compact); 2786 | } 2787 | if (duplicate) { 2788 | state.dump = "&ref_" + duplicateIndex + state.dump; 2789 | } 2790 | } else { 2791 | writeFlowSequence(state, level, state.dump); 2792 | if (duplicate) { 2793 | state.dump = "&ref_" + duplicateIndex + " " + state.dump; 2794 | } 2795 | } 2796 | } else if (type === "[object String]") { 2797 | if (state.tag !== "?") { 2798 | writeScalar(state, state.dump, level, iskey, inblock); 2799 | } 2800 | } else if (type === "[object Undefined]") { 2801 | return false; 2802 | } else { 2803 | if (state.skipInvalid) 2804 | return false; 2805 | throw new YAMLException("unacceptable kind of an object to dump " + type); 2806 | } 2807 | if (state.tag !== null && state.tag !== "?") { 2808 | tagStr = encodeURI( 2809 | state.tag[0] === "!" ? state.tag.slice(1) : state.tag 2810 | ).replace(/!/g, "%21"); 2811 | if (state.tag[0] === "!") { 2812 | tagStr = "!" + tagStr; 2813 | } else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") { 2814 | tagStr = "!!" + tagStr.slice(18); 2815 | } else { 2816 | tagStr = "!<" + tagStr + ">"; 2817 | } 2818 | state.dump = tagStr + " " + state.dump; 2819 | } 2820 | } 2821 | return true; 2822 | } 2823 | function getDuplicateReferences(object, state) { 2824 | var objects = [], duplicatesIndexes = [], index, length; 2825 | inspectNode(object, objects, duplicatesIndexes); 2826 | for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) { 2827 | state.duplicates.push(objects[duplicatesIndexes[index]]); 2828 | } 2829 | state.usedDuplicates = new Array(length); 2830 | } 2831 | function inspectNode(object, objects, duplicatesIndexes) { 2832 | var objectKeyList, index, length; 2833 | if (object !== null && typeof object === "object") { 2834 | index = objects.indexOf(object); 2835 | if (index !== -1) { 2836 | if (duplicatesIndexes.indexOf(index) === -1) { 2837 | duplicatesIndexes.push(index); 2838 | } 2839 | } else { 2840 | objects.push(object); 2841 | if (Array.isArray(object)) { 2842 | for (index = 0, length = object.length; index < length; index += 1) { 2843 | inspectNode(object[index], objects, duplicatesIndexes); 2844 | } 2845 | } else { 2846 | objectKeyList = Object.keys(object); 2847 | for (index = 0, length = objectKeyList.length; index < length; index += 1) { 2848 | inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes); 2849 | } 2850 | } 2851 | } 2852 | } 2853 | } 2854 | function dump(input, options) { 2855 | options = options || {}; 2856 | var state = new State(options); 2857 | if (!state.noRefs) 2858 | getDuplicateReferences(input, state); 2859 | var value = input; 2860 | if (state.replacer) { 2861 | value = state.replacer.call({ "": value }, "", value); 2862 | } 2863 | if (writeNode(state, 0, value, true, true)) 2864 | return state.dump + "\n"; 2865 | return ""; 2866 | } 2867 | module.exports.dump = dump; 2868 | } 2869 | }); 2870 | 2871 | // node_modules/js-yaml/index.js 2872 | var require_js_yaml = __commonJS({ 2873 | "node_modules/js-yaml/index.js"(exports, module) { 2874 | "use strict"; 2875 | init_modules_watch_stub(); 2876 | var loader = require_loader(); 2877 | var dumper = require_dumper(); 2878 | function renamed(from, to) { 2879 | return function () { 2880 | throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default."); 2881 | }; 2882 | } 2883 | module.exports.Type = require_type(); 2884 | module.exports.Schema = require_schema(); 2885 | module.exports.FAILSAFE_SCHEMA = require_failsafe(); 2886 | module.exports.JSON_SCHEMA = require_json(); 2887 | module.exports.CORE_SCHEMA = require_core(); 2888 | module.exports.DEFAULT_SCHEMA = require_default(); 2889 | module.exports.load = loader.load; 2890 | module.exports.loadAll = loader.loadAll; 2891 | module.exports.dump = dumper.dump; 2892 | module.exports.YAMLException = require_exception(); 2893 | module.exports.types = { 2894 | binary: require_binary(), 2895 | float: require_float(), 2896 | map: require_map(), 2897 | null: require_null(), 2898 | pairs: require_pairs(), 2899 | set: require_set(), 2900 | timestamp: require_timestamp(), 2901 | bool: require_bool(), 2902 | int: require_int(), 2903 | merge: require_merge(), 2904 | omap: require_omap(), 2905 | seq: require_seq(), 2906 | str: require_str() 2907 | }; 2908 | module.exports.safeLoad = renamed("safeLoad", "load"); 2909 | module.exports.safeLoadAll = renamed("safeLoadAll", "loadAll"); 2910 | module.exports.safeDump = renamed("safeDump", "dump"); 2911 | } 2912 | }); 2913 | 2914 | // src/index.js 2915 | init_modules_watch_stub(); 2916 | var yaml = require_js_yaml(); 2917 | var src_default = { 2918 | async fetch(request, env) { 2919 | const url = new URL(request.url); 2920 | const host = url.origin; 2921 | const frontendUrl = 'https://raw.githubusercontent.com/aylz10/psub/main/index1.html'; 2922 | const SUB_BUCKET = env.SUB_BUCKET; 2923 | let backend = env.BACKEND.replace(/(https?:\/\/[^/]+).*$/, "$1"); 2924 | const subDir = "subscription"; 2925 | const pathSegments = url.pathname.split("/").filter((segment) => segment.length > 0); 2926 | if (pathSegments.length === 0) { 2927 | const response = await fetch(frontendUrl); 2928 | if (response.status !== 200) { 2929 | return new Response('Failed to fetch frontend', { status: response.status }); 2930 | } 2931 | const originalHtml = await response.text(); 2932 | const modifiedHtml = originalHtml.replace(/https:\/\/bulianglin2023\.dev/, host); 2933 | return new Response(modifiedHtml, { 2934 | status: 200, 2935 | headers: { 2936 | 'Content-Type': 'text/html', 2937 | }, 2938 | }); 2939 | } else if (pathSegments[0] === subDir) { 2940 | const key = pathSegments[pathSegments.length - 1]; 2941 | const object = await SUB_BUCKET.get(key); 2942 | const object_headers = await SUB_BUCKET.get(key + "_headers"); 2943 | if (object === null) 2944 | return new Response("Not Found", { status: 404 }); 2945 | if ("R2Bucket" === SUB_BUCKET.constructor.name) { 2946 | const headers = object_headers ? new Headers(await object_headers.json()) : new Headers({ "Content-Type": "text/plain;charset=UTF-8" }); 2947 | return new Response(object.body, { headers }); 2948 | } else { 2949 | const headers = object_headers ? new Headers(JSON.parse(object_headers)) : new Headers({ "Content-Type": "text/plain;charset=UTF-8" }); 2950 | return new Response(object, { headers }); 2951 | } 2952 | } 2953 | 2954 | const urlParam = url.searchParams.get("url"); 2955 | if (!urlParam) { 2956 | if (url.pathname === '/version') { 2957 | const version = await fetch(`${backend}/version`); 2958 | const versionText = await version.text(); 2959 | return new Response(versionText, { 2960 | status: 200, 2961 | headers: { 2962 | 'Content-Type': 'application/json', 2963 | 'Access-Control-Allow-Origin': '*', 2964 | }, 2965 | }); 2966 | } else { 2967 | return new Response("Missing URL parameter", { status: 400 }); 2968 | } 2969 | } 2970 | const backendParam = url.searchParams.get("bd"); 2971 | if (backendParam && /^(https?:\/\/[^/]+)[.].+$/g.test(backendParam)) 2972 | backend = backendParam.replace(/(https?:\/\/[^/]+).*$/, "$1"); 2973 | const replacements = {}; 2974 | const replacedURIs = []; 2975 | const keys = []; 2976 | if (urlParam.startsWith("proxies:")) { 2977 | const { format, data } = parseData(urlParam.replace(/\|/g, "\r\n")); 2978 | if ("yaml" === format) { 2979 | const key = generateRandomStr(11); 2980 | const replacedYAMLData = replaceYAML(data, replacements); 2981 | if (replacedYAMLData) { 2982 | await SUB_BUCKET.put(key, replacedYAMLData); 2983 | keys.push(key); 2984 | replacedURIs.push(`${host}/${subDir}/${key}`); 2985 | } 2986 | } 2987 | } else { 2988 | const urlParts = urlParam.split("|").filter((part) => part.trim() !== ""); 2989 | if (urlParts.length === 0) 2990 | return new Response("There are no valid links", { status: 400 }); 2991 | let response, parsedObj; 2992 | for (const url2 of urlParts) { 2993 | const key = generateRandomStr(11); 2994 | if (url2.startsWith("https://") || url2.startsWith("http://")) { 2995 | response = await fetch(url2, { 2996 | method: request.method, 2997 | headers: request.headers, 2998 | redirect: 'follow', // https://developers.cloudflare.com/workers/runtime-apis/request#constructor 2999 | }); 3000 | if (!response.ok) 3001 | continue; 3002 | const plaintextData = await response.text(); 3003 | parsedObj = parseData(plaintextData); 3004 | await SUB_BUCKET.put(key + "_headers", JSON.stringify(Object.fromEntries(response.headers))); 3005 | keys.push(key); 3006 | } else { 3007 | parsedObj = parseData(url2); 3008 | } 3009 | if (/^(ssr?|vmess1?|trojan|vless|hysteria|hysteria2):\/\//.test(url2)) { 3010 | const newLink = replaceInUri(url2, replacements, false); 3011 | if (newLink) 3012 | replacedURIs.push(newLink); 3013 | continue; 3014 | } else if ("base64" === parsedObj.format) { 3015 | const links = parsedObj.data.split(/\r?\n/).filter((link) => link.trim() !== ""); 3016 | const newLinks = []; 3017 | for (const link of links) { 3018 | const newLink = replaceInUri(link, replacements, false); 3019 | if (newLink) 3020 | newLinks.push(newLink); 3021 | } 3022 | const replacedBase64Data = btoa(newLinks.join("\r\n")); 3023 | if (replacedBase64Data) { 3024 | await SUB_BUCKET.put(key, replacedBase64Data); 3025 | keys.push(key); 3026 | replacedURIs.push(`${host}/${subDir}/${key}`); 3027 | } 3028 | } else if ("yaml" === parsedObj.format) { 3029 | const replacedYAMLData = replaceYAML(parsedObj.data, replacements); 3030 | if (replacedYAMLData) { 3031 | await SUB_BUCKET.put(key, replacedYAMLData); 3032 | keys.push(key); 3033 | replacedURIs.push(`${host}/${subDir}/${key}`); 3034 | } 3035 | } 3036 | } 3037 | } 3038 | const newUrl = replacedURIs.join("|"); 3039 | url.searchParams.set("url", newUrl); 3040 | const modifiedRequest = new Request(backend + url.pathname + url.search, request); 3041 | const rpResponse = await fetch(modifiedRequest); 3042 | for (const key of keys) { 3043 | await SUB_BUCKET.delete(key); 3044 | } 3045 | if (rpResponse.status === 200) { 3046 | const plaintextData = await rpResponse.text(); 3047 | try { 3048 | const decodedData = urlSafeBase64Decode(plaintextData); 3049 | const links = decodedData.split(/\r?\n/).filter((link) => link.trim() !== ""); 3050 | const newLinks = []; 3051 | for (const link of links) { 3052 | const newLink = replaceInUri(link, replacements, true); 3053 | if (newLink) 3054 | newLinks.push(newLink); 3055 | } 3056 | const replacedBase64Data = btoa(newLinks.join("\r\n")); 3057 | return new Response(replacedBase64Data, rpResponse); 3058 | } catch (base64Error) { 3059 | const result = plaintextData.replace( 3060 | new RegExp(Object.keys(replacements).join("|"), "g"), 3061 | (match) => replacements[match] || match 3062 | ); 3063 | return new Response(result, rpResponse); 3064 | } 3065 | } 3066 | return rpResponse; 3067 | } 3068 | }; 3069 | function replaceInUri(link, replacements, isRecovery) { 3070 | switch (true) { 3071 | case link.startsWith("ss://"): 3072 | return replaceSS(link, replacements, isRecovery); 3073 | case link.startsWith("ssr://"): 3074 | return replaceSSR(link, replacements, isRecovery); 3075 | case link.startsWith("vmess://"): 3076 | case link.startsWith("vmess1://"): 3077 | return replaceVmess(link, replacements, isRecovery); 3078 | case link.startsWith("trojan://"): 3079 | case link.startsWith("vless://"): 3080 | return replaceTrojan(link, replacements, isRecovery); 3081 | case link.startsWith("hysteria://"): 3082 | return replaceHysteria(link, replacements); 3083 | case link.startsWith("hysteria2://"): 3084 | return replaceHysteria2(link, replacements, isRecovery); 3085 | default: 3086 | return; 3087 | } 3088 | } 3089 | 3090 | function replaceSSR(link, replacements, isRecovery) { 3091 | link = link.slice("ssr://".length).replace("\r", "").split("#")[0]; 3092 | link = urlSafeBase64Decode(link); 3093 | const regexMatch = link.match(/(\S+):(\d+?):(\S+?):(\S+?):(\S+?):(\S+)\//); 3094 | if (!regexMatch) { 3095 | return; 3096 | } 3097 | const [, server, , , , , password] = regexMatch; 3098 | let replacedString; 3099 | if (isRecovery) { 3100 | replacedString = "ssr://" + urlSafeBase64Encode(link.replace(password, urlSafeBase64Encode(replacements[urlSafeBase64Decode(password)])).replace(server, replacements[server])); 3101 | } else { 3102 | const randomPassword = generateRandomStr(12); 3103 | const randomDomain = generateRandomStr(12) + ".com"; 3104 | replacements[randomDomain] = server; 3105 | replacements[randomPassword] = urlSafeBase64Decode(password); 3106 | replacedString = "ssr://" + urlSafeBase64Encode(link.replace(server, randomDomain).replace(password, urlSafeBase64Encode(randomPassword))); 3107 | } 3108 | return replacedString; 3109 | } 3110 | function replaceVmess(link, replacements, isRecovery) { 3111 | const randomUUID = generateRandomUUID(); 3112 | const randomDomain = generateRandomStr(10) + ".com"; 3113 | const regexMatchRocketStyle = link.match(/vmess:\/\/([A-Za-z0-9-_]+)\?(.*)/); 3114 | if (regexMatchRocketStyle) { 3115 | const base64Data = regexMatchRocketStyle[1]; 3116 | const regexMatch = urlSafeBase64Decode(base64Data).match(/(.*?):(.*?)@(.*):(.*)/); 3117 | if (!regexMatch) 3118 | return; 3119 | const [, cipher, uuid, server, port] = regexMatch; 3120 | replacements[randomDomain] = server; 3121 | replacements[randomUUID] = uuid; 3122 | const newStr = urlSafeBase64Encode(`${cipher}:${randomUUID}@${randomDomain}:${port}`); 3123 | const result = link.replace(base64Data, newStr); 3124 | return result; 3125 | } 3126 | const regexMatchKitsunebiStyle = link.match(/vmess1:\/\/(.*?)@(.*):(.*?)\?(.*)/); 3127 | if (regexMatchKitsunebiStyle) { 3128 | const [, uuid, server] = regexMatchKitsunebiStyle; 3129 | replacements[randomDomain] = server; 3130 | replacements[randomUUID] = uuid; 3131 | const regex = new RegExp(`${uuid}|${server}`, "g"); 3132 | const result = link.replace(regex, (match) => cReplace(match, uuid, randomUUID, server, randomDomain)); 3133 | return result; 3134 | } 3135 | let tempLink = link.replace(/vmess:\/\/|vmess1:\/\//g, ""); 3136 | try { 3137 | tempLink = urlSafeBase64Decode(tempLink); 3138 | const regexMatchQuanStyle = tempLink.match(/(.*?) = (.*)/); 3139 | if (regexMatchQuanStyle) { 3140 | const configs = regexMatchQuanStyle[2].split(","); 3141 | if (configs.length < 6) 3142 | return; 3143 | const server2 = configs[1].trim(); 3144 | const uuid2 = configs[4].trim().replace(/^"|"$/g, ""); 3145 | replacements[randomDomain] = server2; 3146 | replacements[randomUUID] = uuid2; 3147 | const regex2 = new RegExp(`${uuid2}|${server2}`, "g"); 3148 | const result2 = tempLink.replace(regex2, (match) => cReplace(match, uuid2, randomUUID, server2, randomDomain)); 3149 | return "vmess://" + btoa(result2); 3150 | } 3151 | const jsonData = JSON.parse(tempLink); 3152 | const server = jsonData.add; 3153 | const uuid = jsonData.id; 3154 | const regex = new RegExp(`${uuid}|${server}`, "g"); 3155 | let result; 3156 | if (isRecovery) { 3157 | result = tempLink.replace(regex, (match) => cReplace(match, uuid, replacements[uuid], server, replacements[server])); 3158 | } else { 3159 | replacements[randomDomain] = server; 3160 | replacements[randomUUID] = uuid; 3161 | result = tempLink.replace(regex, (match) => cReplace(match, uuid, randomUUID, server, randomDomain)); 3162 | } 3163 | return "vmess://" + btoa(result); 3164 | } catch (error) { 3165 | return; 3166 | } 3167 | } 3168 | function replaceSS(link, replacements, isRecovery) { 3169 | const randomPassword = generateRandomStr(12); 3170 | const randomDomain = randomPassword + ".com"; 3171 | let replacedString; 3172 | let tempLink = link.slice("ss://".length).split("#")[0]; 3173 | if (tempLink.includes("@")) { 3174 | const regexMatch1 = tempLink.match(/(\S+?)@(\S+):/); 3175 | if (!regexMatch1) { 3176 | return; 3177 | } 3178 | const [, base64Data, server] = regexMatch1; 3179 | const regexMatch2 = urlSafeBase64Decode(base64Data).match(/(\S+?):(\S+)/); 3180 | if (!regexMatch2) { 3181 | return; 3182 | } 3183 | const [, encryption, password] = regexMatch2; 3184 | if (isRecovery) { 3185 | const newStr = urlSafeBase64Encode(encryption + ":" + replacements[password]); 3186 | replacedString = link.replace(base64Data, newStr).replace(server, replacements[server]); 3187 | } else { 3188 | replacements[randomDomain] = server; 3189 | replacements[randomPassword] = password; 3190 | const newStr = urlSafeBase64Encode(encryption + ":" + randomPassword); 3191 | replacedString = link.replace(base64Data, newStr).replace(/@.*:/, `@${randomDomain}:`); 3192 | } 3193 | } else { 3194 | try { 3195 | const decodedValue = urlSafeBase64Decode(tempLink); 3196 | const regexMatch = decodedValue.match(/(\S+?):(\S+)@(\S+):/); 3197 | if (!regexMatch) { 3198 | return; 3199 | } 3200 | const [, , password, server] = regexMatch; 3201 | replacements[randomDomain] = server; 3202 | replacements[randomPassword] = password; 3203 | replacedString = "ss://" + urlSafeBase64Encode(decodedValue.replace(/:.*@/, `:${randomPassword}@`).replace(/@.*:/, `@${randomDomain}:`)); 3204 | const hashPart = link.match(/#.*/); 3205 | if (hashPart) 3206 | replacedString += hashPart[0]; 3207 | } catch (error) { 3208 | return; 3209 | } 3210 | } 3211 | return replacedString; 3212 | } 3213 | function replaceTrojan(link, replacements, isRecovery) { 3214 | const randomUUID = generateRandomUUID(); 3215 | const randomDomain = generateRandomStr(10) + ".com"; 3216 | const regexMatch = link.match(/(vless|trojan):\/\/(.*?)@(.*):/); 3217 | if (!regexMatch) { 3218 | return; 3219 | } 3220 | const [, , uuid, server] = regexMatch; 3221 | replacements[randomDomain] = server; 3222 | replacements[randomUUID] = uuid; 3223 | const regex = new RegExp(`${uuid}|${server}`, "g"); 3224 | if (isRecovery) { 3225 | return link.replace(regex, (match) => cReplace(match, uuid, replacements[uuid], server, replacements[server])); 3226 | } else { 3227 | return link.replace(regex, (match) => cReplace(match, uuid, randomUUID, server, randomDomain)); 3228 | } 3229 | } 3230 | function replaceHysteria(link, replacements) { 3231 | const regexMatch = link.match(/hysteria:\/\/(.*):(.*?)\?/); 3232 | if (!regexMatch) { 3233 | return; 3234 | } 3235 | const server = regexMatch[1]; 3236 | const randomDomain = generateRandomStr(12) + ".com"; 3237 | replacements[randomDomain] = server; 3238 | return link.replace(server, randomDomain); 3239 | } 3240 | function replaceHysteria2(link, replacements) { 3241 | const randomUUID = generateRandomUUID(); 3242 | const randomDomain = generateRandomStr(10) + ".com"; 3243 | const regexMatch = link.match(/(hysteria2):\/\/(.*)@(.*?):/); 3244 | if (!regexMatch) { 3245 | return; 3246 | } 3247 | const [, , uuid, server] = regexMatch; 3248 | replacements[randomDomain] = server; 3249 | replacements[randomUUID] = uuid; 3250 | const regex = new RegExp(`${uuid}|${server}`, "g"); 3251 | if (isRecovery) { 3252 | return link.replace(regex, (match) => cReplace(match, uuid, replacements[uuid], server, replacements[server])); 3253 | } else { 3254 | return link.replace(regex, (match) => cReplace(match, uuid, randomUUID, server, randomDomain)); 3255 | } 3256 | } 3257 | function replaceYAML(yamlObj, replacements) { 3258 | if (!yamlObj.proxies) { 3259 | return; 3260 | } 3261 | yamlObj.proxies.forEach((proxy) => { 3262 | const randomPassword = generateRandomStr(12); 3263 | const randomDomain = randomPassword + ".com"; 3264 | const originalServer = proxy.server; 3265 | proxy.server = randomDomain; 3266 | replacements[randomDomain] = originalServer; 3267 | if (proxy.password) { 3268 | const originalPassword = proxy.password; 3269 | proxy.password = randomPassword; 3270 | replacements[randomPassword] = originalPassword; 3271 | } 3272 | if (proxy.uuid) { 3273 | const originalUUID = proxy.uuid; 3274 | const randomUUID = generateRandomUUID(); 3275 | proxy.uuid = randomUUID; 3276 | replacements[randomUUID] = originalUUID; 3277 | } 3278 | }); 3279 | return yaml.dump(yamlObj); 3280 | } 3281 | function urlSafeBase64Encode(input) { 3282 | return btoa(input).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); 3283 | } 3284 | function urlSafeBase64Decode(input) { 3285 | const padded = input + "=".repeat((4 - input.length % 4) % 4); 3286 | return atob(padded.replace(/-/g, "+").replace(/_/g, "/")); 3287 | } 3288 | function generateRandomStr(len) { 3289 | return Math.random().toString(36).substring(2, len); 3290 | } 3291 | function generateRandomUUID() { 3292 | return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) { 3293 | const r = Math.random() * 16 | 0; 3294 | const v = c == "x" ? r : r & 3 | 8; 3295 | return v.toString(16); 3296 | }); 3297 | } 3298 | function parseData(data) { 3299 | try { 3300 | return { format: "base64", data: urlSafeBase64Decode(data) }; 3301 | } catch (base64Error) { 3302 | try { 3303 | return { format: "yaml", data: yaml.load(data) }; 3304 | } catch (yamlError) { 3305 | return { format: "unknown", data }; 3306 | } 3307 | } 3308 | } 3309 | function cReplace(match, ...replacementPairs) { 3310 | for (let i = 0; i < replacementPairs.length; i += 2) { 3311 | if (match === replacementPairs[i]) { 3312 | return replacementPairs[i + 1]; 3313 | } 3314 | } 3315 | return match; 3316 | } 3317 | export { 3318 | src_default as default 3319 | }; 3320 | //# sourceMappingURL=index.js.map 3321 | --------------------------------------------------------------------------------