Skip to content

Instantly share code, notes, and snippets.

@patrickdevivo
Created February 25, 2023 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickdevivo/668f512c96c7f755532370e146acd6ed to your computer and use it in GitHub Desktop.
Save patrickdevivo/668f512c96c7f755532370e146acd6ed to your computer and use it in GitHub Desktop.
Example of parsing YAML (by converting it to JSONB) in PostgreSQL
-- enable plv8 extension
CREATE EXTENSION plv8;
-- define plv8_yaml_to_json() UDF using implementation from: https://github.com/nodeca/js-yaml
CREATE OR REPLACE FUNCTION plv8_yaml_to_json(yaml_input TEXT) RETURNS JSONB AS $$
/*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */ function isNothing(e){return null==e}function isObject(e){return"object"==typeof e&&null!==e}function toArray(e){return Array.isArray(e)?e:isNothing(e)?[]:[e]}function extend(e,t){var n,r,o,a;if(t)for(n=0,r=(a=Object.keys(t)).length;n<r;n+=1)e[o=a[n]]=t[o];return e}function repeat(e,t){var n,r="";for(n=0;n<t;n+=1)r+=e;return r}function isNegativeZero(e){return 0===e&&Number.NEGATIVE_INFINITY===1/e}var isNothing_1=isNothing,isObject_1=isObject,toArray_1=toArray,repeat_1=repeat,isNegativeZero_1=isNegativeZero,extend_1=extend,common={isNothing:isNothing_1,isObject:isObject_1,toArray:toArray_1,repeat:repeat_1,isNegativeZero:isNegativeZero_1,extend:extend_1};function formatError(e,t){var n="",r=e.reason||"(unknown reason)";return e.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!t&&e.mark.snippet&&(n+="\n\n"+e.mark.snippet),r+" "+n):r}function YAMLException$1(e,t){Error.call(this),this.name="YAMLException",this.reason=e,this.mark=t,this.message=formatError(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=Error().stack||""}YAMLException$1.prototype=Object.create(Error.prototype),YAMLException$1.prototype.constructor=YAMLException$1,YAMLException$1.prototype.toString=function e(t){return this.name+": "+formatError(this,t)};var exception=YAMLException$1;function getLine(e,t,n,r,o){var a="",l="",s=Math.floor(o/2)-1;return r-t>s&&(t=r-s+(a=" ... ").length),n-r>s&&(n=r+s-(l=" ...").length),{str:a+e.slice(t,n).replace(/\t/g,"→")+l,pos:r-t+a.length}}function padStart(e,t){return common.repeat(" ",t-e.length)+e}function makeSnippet(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),"number"!=typeof t.indent&&(t.indent=1),"number"!=typeof t.linesBefore&&(t.linesBefore=3),"number"!=typeof t.linesAfter&&(t.linesAfter=2);for(var n=/\r?\n|\r|\0/g,r=[0],o=[],a=-1;l=n.exec(e.buffer);)o.push(l.index),r.push(l.index+l[0].length),e.position<=l.index&&a<0&&(a=r.length-2);a<0&&(a=r.length-1);var l,s,c,p="",u=Math.min(e.line+t.linesAfter,o.length).toString().length,$=t.maxLength-(t.indent+u+3);for(s=1;s<=t.linesBefore&&!(a-s<0);s++)c=getLine(e.buffer,r[a-s],o[a-s],e.position-(r[a]-r[a-s]),$),p=common.repeat(" ",t.indent)+padStart((e.line-s+1).toString(),u)+" | "+c.str+"\n"+p;for(c=getLine(e.buffer,r[a],o[a],e.position,$),p+=common.repeat(" ",t.indent)+padStart((e.line+1).toString(),u)+" | "+c.str+"\n",p+=common.repeat("-",t.indent+u+3+c.pos)+"^\n",s=1;s<=t.linesAfter&&!(a+s>=o.length);s++)c=getLine(e.buffer,r[a+s],o[a+s],e.position-(r[a]-r[a+s]),$),p+=common.repeat(" ",t.indent)+padStart((e.line+s+1).toString(),u)+" | "+c.str+"\n";return p.replace(/\n$/,"")}var snippet=makeSnippet,TYPE_CONSTRUCTOR_OPTIONS=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],YAML_NODE_KINDS=["scalar","sequence","mapping"];function compileStyleAliases(e){var t={};return null!==e&&Object.keys(e).forEach(function(n){e[n].forEach(function(e){t[String(e)]=n})}),t}function Type$1(e,t){if(Object.keys(t=t||{}).forEach(function(t){if(-1===TYPE_CONSTRUCTOR_OPTIONS.indexOf(t))throw new exception('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')}),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=compileStyleAliases(t.styleAliases||null),-1===YAML_NODE_KINDS.indexOf(this.kind))throw new exception('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')}var type=Type$1;function compileList(e,t){var n=[];return e[t].forEach(function(e){var t=n.length;n.forEach(function(n,r){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=r)}),n[t]=e}),n}function compileMap(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function r(e){e.multi?(n.multi[e.kind].push(e),n.multi.fallback.push(e)):n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e<t;e+=1)arguments[e].forEach(r);return n}function Schema$1(e){return this.extend(e)}Schema$1.prototype.extend=function e(t){var n=[],r=[];if(t instanceof type)r.push(t);else if(Array.isArray(t))r=r.concat(t);else if(t&&(Array.isArray(t.implicit)||Array.isArray(t.explicit)))t.implicit&&(n=n.concat(t.implicit)),t.explicit&&(r=r.concat(t.explicit));else throw new exception("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");n.forEach(function(e){if(!(e instanceof type))throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")}),r.forEach(function(e){if(!(e instanceof type))throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.")});var o=Object.create(Schema$1.prototype);return o.implicit=(this.implicit||[]).concat(n),o.explicit=(this.explicit||[]).concat(r),o.compiledImplicit=compileList(o,"implicit"),o.compiledExplicit=compileList(o,"explicit"),o.compiledTypeMap=compileMap(o.compiledImplicit,o.compiledExplicit),o};var schema=Schema$1,str=new type("tag:yaml.org,2002:str",{kind:"scalar",construct:function(e){return null!==e?e:""}}),seq=new type("tag:yaml.org,2002:seq",{kind:"sequence",construct:function(e){return null!==e?e:[]}}),map=new type("tag:yaml.org,2002:map",{kind:"mapping",construct:function(e){return null!==e?e:{}}}),failsafe=new schema({explicit:[str,seq,map]});function resolveYamlNull(e){if(null===e)return!0;var t=e.length;return 1===t&&"~"===e||4===t&&("null"===e||"Null"===e||"NULL"===e)}function constructYamlNull(){return null}function isNull(e){return null===e}var _null=new type("tag:yaml.org,2002:null",{kind:"scalar",resolve:resolveYamlNull,construct:constructYamlNull,predicate:isNull,represent:{canonical:function(){return"~"},lowercase:function(){return"null"},uppercase:function(){return"NULL"},camelcase:function(){return"Null"},empty:function(){return""}},defaultStyle:"lowercase"});function resolveYamlBoolean(e){if(null===e)return!1;var t=e.length;return 4===t&&("true"===e||"True"===e||"TRUE"===e)||5===t&&("false"===e||"False"===e||"FALSE"===e)}function constructYamlBoolean(e){return"true"===e||"True"===e||"TRUE"===e}function isBoolean(e){return"[object Boolean]"===Object.prototype.toString.call(e)}var bool=new type("tag:yaml.org,2002:bool",{kind:"scalar",resolve:resolveYamlBoolean,construct:constructYamlBoolean,predicate:isBoolean,represent:{lowercase:function(e){return e?"true":"false"},uppercase:function(e){return e?"TRUE":"FALSE"},camelcase:function(e){return e?"True":"False"}},defaultStyle:"lowercase"});function isHexCode(e){return 48<=e&&e<=57||65<=e&&e<=70||97<=e&&e<=102}function isOctCode(e){return 48<=e&&e<=55}function isDecCode(e){return 48<=e&&e<=57}function resolveYamlInteger(e){if(null===e)return!1;var t,n=e.length,r=0,o=!1;if(!n)return!1;if(("-"===(t=e[r])||"+"===t)&&(t=e[++r]),"0"===t){if(r+1===n)return!0;if("b"===(t=e[++r])){for(r++;r<n;r++)if("_"!==(t=e[r])){if("0"!==t&&"1"!==t)return!1;o=!0}return o&&"_"!==t}if("x"===t){for(r++;r<n;r++)if("_"!==(t=e[r])){if(!isHexCode(e.charCodeAt(r)))return!1;o=!0}return o&&"_"!==t}if("o"===t){for(r++;r<n;r++)if("_"!==(t=e[r])){if(!isOctCode(e.charCodeAt(r)))return!1;o=!0}return o&&"_"!==t}}if("_"===t)return!1;for(;r<n;r++)if("_"!==(t=e[r])){if(!isDecCode(e.charCodeAt(r)))return!1;o=!0}return!!o&&"_"!==t}function constructYamlInteger(e){var t,n=e,r=1;if(-1!==n.indexOf("_")&&(n=n.replace(/_/g,"")),("-"===(t=n[0])||"+"===t)&&("-"===t&&(r=-1),t=(n=n.slice(1))[0]),"0"===n)return 0;if("0"===t){if("b"===n[1])return r*parseInt(n.slice(2),2);if("x"===n[1])return r*parseInt(n.slice(2),16);if("o"===n[1])return r*parseInt(n.slice(2),8)}return r*parseInt(n,10)}function isInteger(e){return"[object Number]"===Object.prototype.toString.call(e)&&e%1==0&&!common.isNegativeZero(e)}var int=new type("tag:yaml.org,2002:int",{kind:"scalar",resolve:resolveYamlInteger,construct:constructYamlInteger,predicate:isInteger,represent:{binary:function(e){return e>=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),YAML_FLOAT_PATTERN=RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");function resolveYamlFloat(e){return!!(null!==e&&YAML_FLOAT_PATTERN.test(e)&&"_"!==e[e.length-1])}function constructYamlFloat(e){var t,n;return(n="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t)?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:n*parseFloat(t,10)}var SCIENTIFIC_WITHOUT_DOT=/^[-+]?[0-9]+e/;function representYamlFloat(e,t){var n;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(common.isNegativeZero(e))return"-0.0";return n=e.toString(10),SCIENTIFIC_WITHOUT_DOT.test(n)?n.replace("e",".e"):n}function isFloat(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||common.isNegativeZero(e))}var float=new type("tag:yaml.org,2002:float",{kind:"scalar",resolve:resolveYamlFloat,construct:constructYamlFloat,predicate:isFloat,represent:representYamlFloat,defaultStyle:"lowercase"}),json=failsafe.extend({implicit:[_null,bool,int,float]}),core=json,YAML_DATE_REGEXP=RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),YAML_TIMESTAMP_REGEXP=RegExp("^([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]))?))?$");function resolveYamlTimestamp(e){return null!==e&&(null!==YAML_DATE_REGEXP.exec(e)||null!==YAML_TIMESTAMP_REGEXP.exec(e))}function constructYamlTimestamp(e){var t,n,r,o,a,l,s,c,p,u,$=0,d=null;if(null===(t=YAML_DATE_REGEXP.exec(e))&&(t=YAML_TIMESTAMP_REGEXP.exec(e)),null===t)throw Error("Date resolve error");if(n=+t[1],r=+t[2]-1,o=+t[3],!t[4])return new Date(Date.UTC(n,r,o));if(a=+t[4],l=+t[5],s=+t[6],t[7]){for($=t[7].slice(0,3);$.length<3;)$+="0";$=+$}return t[9]&&(d=(60*(c=+t[10])+(p=+(t[11]||0)))*6e4,"-"===t[9]&&(d=-d)),u=new Date(Date.UTC(n,r,o,a,l,s,$)),d&&u.setTime(u.getTime()-d),u}function representYamlTimestamp(e){return e.toISOString()}var timestamp=new type("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:resolveYamlTimestamp,construct:constructYamlTimestamp,instanceOf:Date,represent:representYamlTimestamp});function resolveYamlMerge(e){return"<<"===e||null===e}var merge=new type("tag:yaml.org,2002:merge",{kind:"scalar",resolve:resolveYamlMerge}),BASE64_MAP="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";function resolveYamlBinary(e){if(null===e)return!1;var t,n,r=0,o=e.length,a=BASE64_MAP;for(n=0;n<o;n++)if(!((t=a.indexOf(e.charAt(n)))>64)){if(t<0)return!1;r+=6}return r%8==0}function constructYamlBinary(e){var t,n,r=e.replace(/[\r\n=]/g,""),o=r.length,a=BASE64_MAP,l=0,s=[];for(t=0;t<o;t++)t%4==0&&t&&(s.push(l>>16&255),s.push(l>>8&255),s.push(255&l)),l=l<<6|a.indexOf(r.charAt(t));return 0==(n=o%4*6)?(s.push(l>>16&255),s.push(l>>8&255),s.push(255&l)):18===n?(s.push(l>>10&255),s.push(l>>2&255)):12===n&&s.push(l>>4&255),new Uint8Array(s)}function representYamlBinary(e){var t,n,r="",o=0,a=e.length,l=BASE64_MAP;for(t=0;t<a;t++)t%3==0&&t&&(r+=l[o>>18&63],r+=l[o>>12&63],r+=l[o>>6&63],r+=l[63&o]),o=(o<<8)+e[t];return 0==(n=a%3)?(r+=l[o>>18&63],r+=l[o>>12&63],r+=l[o>>6&63],r+=l[63&o]):2===n?(r+=l[o>>10&63],r+=l[o>>4&63],r+=l[o<<2&63],r+=l[64]):1===n&&(r+=l[o>>2&63],r+=l[o<<4&63],r+=l[64],r+=l[64]),r}function isBinary(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)}var binary=new type("tag:yaml.org,2002:binary",{kind:"scalar",resolve:resolveYamlBinary,construct:constructYamlBinary,predicate:isBinary,represent:representYamlBinary}),_hasOwnProperty$3=Object.prototype.hasOwnProperty,_toString$2=Object.prototype.toString;function resolveYamlOmap(e){if(null===e)return!0;var t,n,r,o,a,l=[],s=e;for(t=0,n=s.length;t<n;t+=1){if(r=s[t],a=!1,"[object Object]"!==_toString$2.call(r))return!1;for(o in r)if(_hasOwnProperty$3.call(r,o)){if(a)return!1;a=!0}if(!a||-1!==l.indexOf(o))return!1;l.push(o)}return!0}function constructYamlOmap(e){return null!==e?e:[]}var omap=new type("tag:yaml.org,2002:omap",{kind:"sequence",resolve:resolveYamlOmap,construct:constructYamlOmap}),_toString$1=Object.prototype.toString;function resolveYamlPairs(e){if(null===e)return!0;var t,n,r,o,a,l=e;for(t=0,a=Array(l.length),n=l.length;t<n;t+=1){if(r=l[t],"[object Object]"!==_toString$1.call(r)||1!==(o=Object.keys(r)).length)return!1;a[t]=[o[0],r[o[0]]]}return!0}function constructYamlPairs(e){if(null===e)return[];var t,n,r,o,a,l=e;for(t=0,a=Array(l.length),n=l.length;t<n;t+=1)o=Object.keys(r=l[t]),a[t]=[o[0],r[o[0]]];return a}var pairs=new type("tag:yaml.org,2002:pairs",{kind:"sequence",resolve:resolveYamlPairs,construct:constructYamlPairs}),_hasOwnProperty$2=Object.prototype.hasOwnProperty;function resolveYamlSet(e){if(null===e)return!0;var t,n=e;for(t in n)if(_hasOwnProperty$2.call(n,t)&&null!==n[t])return!1;return!0}function constructYamlSet(e){return null!==e?e:{}}var set=new type("tag:yaml.org,2002:set",{kind:"mapping",resolve:resolveYamlSet,construct:constructYamlSet}),_default=core.extend({implicit:[timestamp,merge],explicit:[binary,omap,pairs,set]}),_hasOwnProperty$1=Object.prototype.hasOwnProperty,CONTEXT_FLOW_IN=1,CONTEXT_FLOW_OUT=2,CONTEXT_BLOCK_IN=3,CONTEXT_BLOCK_OUT=4,CHOMPING_CLIP=1,CHOMPING_STRIP=2,CHOMPING_KEEP=3,PATTERN_NON_PRINTABLE=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,PATTERN_NON_ASCII_LINE_BREAKS=/[\x85\u2028\u2029]/,PATTERN_FLOW_INDICATORS=/[,\[\]\{\}]/,PATTERN_TAG_HANDLE=/^(?:!|!!|![a-z\-]+!)$/i,PATTERN_TAG_URI=/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;function _class(e){return Object.prototype.toString.call(e)}function is_EOL(e){return 10===e||13===e}function is_WHITE_SPACE(e){return 9===e||32===e}function is_WS_OR_EOL(e){return 9===e||32===e||10===e||13===e}function is_FLOW_INDICATOR(e){return 44===e||91===e||93===e||123===e||125===e}function fromHexCode(e){var t;return 48<=e&&e<=57?e-48:97<=(t=32|e)&&t<=102?t-97+10:-1}function escapedHexLen(e){return 120===e?2:117===e?4:85===e?8:0}function fromDecimalCode(e){return 48<=e&&e<=57?e-48:-1}function simpleEscapeSequence(e){return 48===e?"\0":97===e?"\x07":98===e?"\b":116===e?" ":9===e?" ":110===e?"\n":118===e?"\v":102===e?"\f":114===e?"\r":101===e?"\x1b":32===e?" ":34===e?'"':47===e?"/":92===e?"\\":78===e?"\x85":95===e?"\xa0":76===e?"\u2028":80===e?"\u2029":""}function charFromCodepoint(e){return e<=65535?String.fromCharCode(e):String.fromCharCode((e-65536>>10)+55296,(e-65536&1023)+56320)}for(var simpleEscapeCheck=Array(256),simpleEscapeMap=Array(256),i=0;i<256;i++)simpleEscapeCheck[i]=simpleEscapeSequence(i)?1:0,simpleEscapeMap[i]=simpleEscapeSequence(i);function State$1(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||_default,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function generateError(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=snippet(n),new exception(t,n)}function throwError(e,t){throw generateError(e,t)}function throwWarning(e,t){e.onWarning&&e.onWarning.call(null,generateError(e,t))}var directiveHandlers={YAML:function e(t,n,r){var o,a,l;null!==t.version&&throwError(t,"duplication of %YAML directive"),1!==r.length&&throwError(t,"YAML directive accepts exactly one argument"),null===(o=/^([0-9]+)\.([0-9]+)$/.exec(r[0]))&&throwError(t,"ill-formed argument of the YAML directive"),a=parseInt(o[1],10),l=parseInt(o[2],10),1!==a&&throwError(t,"unacceptable YAML version of the document"),t.version=r[0],t.checkLineBreaks=l<2,1!==l&&2!==l&&throwWarning(t,"unsupported YAML version of the document")},TAG:function e(t,n,r){var o,a;2!==r.length&&throwError(t,"TAG directive accepts exactly two arguments"),o=r[0],a=r[1],PATTERN_TAG_HANDLE.test(o)||throwError(t,"ill-formed tag handle (first argument) of the TAG directive"),_hasOwnProperty$1.call(t.tagMap,o)&&throwError(t,'there is a previously declared suffix for "'+o+'" tag handle'),PATTERN_TAG_URI.test(a)||throwError(t,"ill-formed tag prefix (second argument) of the TAG directive");try{a=decodeURIComponent(a)}catch(l){throwError(t,"tag prefix is malformed: "+a)}t.tagMap[o]=a}};function captureSegment(e,t,n,r){var o,a,l,s;if(t<n){if(s=e.input.slice(t,n),r)for(o=0,a=s.length;o<a;o+=1)9===(l=s.charCodeAt(o))||32<=l&&l<=1114111||throwError(e,"expected valid JSON character");else PATTERN_NON_PRINTABLE.test(s)&&throwError(e,"the stream contains non-printable characters");e.result+=s}}function mergeMappings(e,t,n,r){var o,a,l,s;for(common.isObject(n)||throwError(e,"cannot merge mappings; the provided source object is unacceptable"),o=Object.keys(n),l=0,s=o.length;l<s;l+=1)a=o[l],_hasOwnProperty$1.call(t,a)||(t[a]=n[a],r[a]=!0)}function storeMappingPair(e,t,n,r,o,a,l,s,c){var p,u;if(Array.isArray(o))for(p=0,u=(o=Array.prototype.slice.call(o)).length;p<u;p+=1)Array.isArray(o[p])&&throwError(e,"nested arrays are not supported inside keys"),"object"==typeof o&&"[object Object]"===_class(o[p])&&(o[p]="[object Object]");if("object"==typeof o&&"[object Object]"===_class(o)&&(o="[object Object]"),o=String(o),null===t&&(t={}),"tag:yaml.org,2002:merge"===r){if(Array.isArray(a))for(p=0,u=a.length;p<u;p+=1)mergeMappings(e,t,a[p],n);else mergeMappings(e,t,a,n)}else!e.json&&!_hasOwnProperty$1.call(n,o)&&_hasOwnProperty$1.call(t,o)&&(e.line=l||e.line,e.lineStart=s||e.lineStart,e.position=c||e.position,throwError(e,"duplicated mapping key")),"__proto__"===o?Object.defineProperty(t,o,{configurable:!0,enumerable:!0,writable:!0,value:a}):t[o]=a,delete n[o];return t}function readLineBreak(e){var t;10===(t=e.input.charCodeAt(e.position))?e.position++:13===t?(e.position++,10===e.input.charCodeAt(e.position)&&e.position++):throwError(e,"a line break is expected"),e.line+=1,e.lineStart=e.position,e.firstTabInLine=-1}function skipSeparationSpace(e,t,n){for(var r=0,o=e.input.charCodeAt(e.position);0!==o;){for(;is_WHITE_SPACE(o);)9===o&&-1===e.firstTabInLine&&(e.firstTabInLine=e.position),o=e.input.charCodeAt(++e.position);if(t&&35===o)do o=e.input.charCodeAt(++e.position);while(10!==o&&13!==o&&0!==o);if(is_EOL(o))for(readLineBreak(e),o=e.input.charCodeAt(e.position),r++,e.lineIndent=0;32===o;)e.lineIndent++,o=e.input.charCodeAt(++e.position);else break}return -1!==n&&0!==r&&e.lineIndent<n&&throwWarning(e,"deficient indentation"),r}function testDocumentSeparator(e){var t,n=e.position;return!!((45===(t=e.input.charCodeAt(n))||46===t)&&t===e.input.charCodeAt(n+1)&&t===e.input.charCodeAt(n+2)&&(n+=3,0===(t=e.input.charCodeAt(n))||is_WS_OR_EOL(t)))}function writeFoldedLines(e,t){1===t?e.result+=" ":t>1&&(e.result+=common.repeat("\n",t-1))}function readPlainScalar(e,t,n){var r,o,a,l,s,c,p,u,$,d=e.kind,f=e.result;if(is_WS_OR_EOL($=e.input.charCodeAt(e.position))||is_FLOW_INDICATOR($)||35===$||38===$||42===$||33===$||124===$||62===$||39===$||34===$||37===$||64===$||96===$||(63===$||45===$)&&(is_WS_OR_EOL(o=e.input.charCodeAt(e.position+1))||n&&is_FLOW_INDICATOR(o)))return!1;for(e.kind="scalar",e.result="",a=l=e.position,s=!1;0!==$;){if(58===$){if(is_WS_OR_EOL(o=e.input.charCodeAt(e.position+1))||n&&is_FLOW_INDICATOR(o))break}else if(35===$){if(is_WS_OR_EOL(r=e.input.charCodeAt(e.position-1)))break}else if(e.position===e.lineStart&&testDocumentSeparator(e)||n&&is_FLOW_INDICATOR($))break;else if(is_EOL($)){if(c=e.line,p=e.lineStart,u=e.lineIndent,skipSeparationSpace(e,!1,-1),e.lineIndent>=t){s=!0,$=e.input.charCodeAt(e.position);continue}e.position=l,e.line=c,e.lineStart=p,e.lineIndent=u;break}s&&(captureSegment(e,a,l,!1),writeFoldedLines(e,e.line-c),a=l=e.position,s=!1),is_WHITE_SPACE($)||(l=e.position+1),$=e.input.charCodeAt(++e.position)}return captureSegment(e,a,l,!1),!!e.result||(e.kind=d,e.result=f,!1)}function readSingleQuotedScalar(e,t){var n,r,o;if(39!==(n=e.input.charCodeAt(e.position)))return!1;for(e.kind="scalar",e.result="",e.position++,r=o=e.position;0!==(n=e.input.charCodeAt(e.position));)if(39===n){if(captureSegment(e,r,e.position,!0),39!==(n=e.input.charCodeAt(++e.position)))return!0;r=e.position,e.position++,o=e.position}else is_EOL(n)?(captureSegment(e,r,o,!0),writeFoldedLines(e,skipSeparationSpace(e,!1,t)),r=o=e.position):e.position===e.lineStart&&testDocumentSeparator(e)?throwError(e,"unexpected end of the document within a single quoted scalar"):(e.position++,o=e.position);throwError(e,"unexpected end of the stream within a single quoted scalar")}function readDoubleQuotedScalar(e,t){var n,r,o,a,l,s;if(34!==(s=e.input.charCodeAt(e.position)))return!1;for(e.kind="scalar",e.result="",e.position++,n=r=e.position;0!==(s=e.input.charCodeAt(e.position));){if(34===s)return captureSegment(e,n,e.position,!0),e.position++,!0;if(92===s){if(captureSegment(e,n,e.position,!0),is_EOL(s=e.input.charCodeAt(++e.position)))skipSeparationSpace(e,!1,t);else if(s<256&&simpleEscapeCheck[s])e.result+=simpleEscapeMap[s],e.position++;else if((l=escapedHexLen(s))>0){for(o=l,a=0;o>0;o--)(l=fromHexCode(s=e.input.charCodeAt(++e.position)))>=0?a=(a<<4)+l:throwError(e,"expected hexadecimal character");e.result+=charFromCodepoint(a),e.position++}else throwError(e,"unknown escape sequence");n=r=e.position}else is_EOL(s)?(captureSegment(e,n,r,!0),writeFoldedLines(e,skipSeparationSpace(e,!1,t)),n=r=e.position):e.position===e.lineStart&&testDocumentSeparator(e)?throwError(e,"unexpected end of the document within a double quoted scalar"):(e.position++,r=e.position)}throwError(e,"unexpected end of the stream within a double quoted scalar")}function readFlowCollection(e,t){var n,r,o,a,l,s,c,p,u,$,d,f,h,E=!0,m=e.tag,A=e.anchor,g=Object.create(null);if(91===(h=e.input.charCodeAt(e.position)))s=93,u=!1,a=[];else{if(123!==h)return!1;s=125,u=!0,a={}}for(null!==e.anchor&&(e.anchorMap[e.anchor]=a),h=e.input.charCodeAt(++e.position);0!==h;){if(skipSeparationSpace(e,!0,t),(h=e.input.charCodeAt(e.position))===s)return e.position++,e.tag=m,e.anchor=A,e.kind=u?"mapping":"sequence",e.result=a,!0;E?44===h&&throwError(e,"expected the node content, but found ','"):throwError(e,"missed comma between flow collection entries"),d=$=f=null,c=p=!1,63===h&&is_WS_OR_EOL(l=e.input.charCodeAt(e.position+1))&&(c=p=!0,e.position++,skipSeparationSpace(e,!0,t)),n=e.line,r=e.lineStart,o=e.position,composeNode(e,t,CONTEXT_FLOW_IN,!1,!0),d=e.tag,$=e.result,skipSeparationSpace(e,!0,t),h=e.input.charCodeAt(e.position),(p||e.line===n)&&58===h&&(c=!0,h=e.input.charCodeAt(++e.position),skipSeparationSpace(e,!0,t),composeNode(e,t,CONTEXT_FLOW_IN,!1,!0),f=e.result),u?storeMappingPair(e,a,g,d,$,f,n,r,o):c?a.push(storeMappingPair(e,null,g,d,$,f,n,r,o)):a.push($),skipSeparationSpace(e,!0,t),44===(h=e.input.charCodeAt(e.position))?(E=!0,h=e.input.charCodeAt(++e.position)):E=!1}throwError(e,"unexpected end of the stream within a flow collection")}function readBlockScalar(e,t){var n,r,o,a,l=CHOMPING_CLIP,s=!1,c=!1,p=t,u=0,$=!1;if(124===(a=e.input.charCodeAt(e.position)))r=!1;else{if(62!==a)return!1;r=!0}for(e.kind="scalar",e.result="";0!==a;)if(43===(a=e.input.charCodeAt(++e.position))||45===a)CHOMPING_CLIP===l?l=43===a?CHOMPING_KEEP:CHOMPING_STRIP:throwError(e,"repeat of a chomping mode identifier");else if((o=fromDecimalCode(a))>=0)0===o?throwError(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):c?throwError(e,"repeat of an indentation width identifier"):(p=t+o-1,c=!0);else break;if(is_WHITE_SPACE(a)){do a=e.input.charCodeAt(++e.position);while(is_WHITE_SPACE(a));if(35===a)do a=e.input.charCodeAt(++e.position);while(!is_EOL(a)&&0!==a)}for(;0!==a;){for(readLineBreak(e),e.lineIndent=0,a=e.input.charCodeAt(e.position);(!c||e.lineIndent<p)&&32===a;)e.lineIndent++,a=e.input.charCodeAt(++e.position);if(!c&&e.lineIndent>p&&(p=e.lineIndent),is_EOL(a)){u++;continue}if(e.lineIndent<p){l===CHOMPING_KEEP?e.result+=common.repeat("\n",s?1+u:u):l===CHOMPING_CLIP&&s&&(e.result+="\n");break}for(r?is_WHITE_SPACE(a)?($=!0,e.result+=common.repeat("\n",s?1+u:u)):$?($=!1,e.result+=common.repeat("\n",u+1)):0===u?s&&(e.result+=" "):e.result+=common.repeat("\n",u):e.result+=common.repeat("\n",s?1+u:u),s=!0,c=!0,u=0,n=e.position;!is_EOL(a)&&0!==a;)a=e.input.charCodeAt(++e.position);captureSegment(e,n,e.position,!1)}return!0}function readBlockSequence(e,t){var n,r,o,a=e.tag,l=e.anchor,s=[],c=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=s),o=e.input.charCodeAt(e.position);0!==o&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,throwError(e,"tab characters must not be used in indentation")),45===o&&is_WS_OR_EOL(r=e.input.charCodeAt(e.position+1)));){if(c=!0,e.position++,skipSeparationSpace(e,!0,-1)&&e.lineIndent<=t){s.push(null),o=e.input.charCodeAt(e.position);continue}if(n=e.line,composeNode(e,t,CONTEXT_BLOCK_IN,!1,!0),s.push(e.result),skipSeparationSpace(e,!0,-1),o=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&0!==o)throwError(e,"bad indentation of a sequence entry");else if(e.lineIndent<t)break}return!!c&&(e.tag=a,e.anchor=l,e.kind="sequence",e.result=s,!0)}function readBlockMapping(e,t,n){var r,o,a,l,s,c,p,u=e.tag,$=e.anchor,d={},f=Object.create(null),h=null,E=null,m=null,A=!1,g=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=d),p=e.input.charCodeAt(e.position);0!==p;){if(A||-1===e.firstTabInLine||(e.position=e.firstTabInLine,throwError(e,"tab characters must not be used in indentation")),r=e.input.charCodeAt(e.position+1),a=e.line,(63===p||58===p)&&is_WS_OR_EOL(r))63===p?(A&&(storeMappingPair(e,d,f,h,E,null,l,s,c),h=E=m=null),g=!0,A=!0,o=!0):A?(A=!1,o=!0):throwError(e,"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"),e.position+=1,p=r;else{if(l=e.line,s=e.lineStart,c=e.position,!composeNode(e,n,CONTEXT_FLOW_OUT,!1,!0))break;if(e.line===a){for(p=e.input.charCodeAt(e.position);is_WHITE_SPACE(p);)p=e.input.charCodeAt(++e.position);if(58===p)is_WS_OR_EOL(p=e.input.charCodeAt(++e.position))||throwError(e,"a whitespace character is expected after the key-value separator within a block mapping"),A&&(storeMappingPair(e,d,f,h,E,null,l,s,c),h=E=m=null),g=!0,A=!1,o=!1,h=e.tag,E=e.result;else{if(!g)return e.tag=u,e.anchor=$,!0;throwError(e,"can not read an implicit mapping pair; a colon is missed")}}else{if(!g)return e.tag=u,e.anchor=$,!0;throwError(e,"can not read a block mapping entry; a multiline key may not be an implicit key")}}if((e.line===a||e.lineIndent>t)&&(A&&(l=e.line,s=e.lineStart,c=e.position),composeNode(e,t,CONTEXT_BLOCK_OUT,!0,o)&&(A?E=e.result:m=e.result),A||(storeMappingPair(e,d,f,h,E,m,l,s,c),h=E=m=null),skipSeparationSpace(e,!0,-1),p=e.input.charCodeAt(e.position)),(e.line===a||e.lineIndent>t)&&0!==p)throwError(e,"bad indentation of a mapping entry");else if(e.lineIndent<t)break}return A&&storeMappingPair(e,d,f,h,E,null,l,s,c),g&&(e.tag=u,e.anchor=$,e.kind="mapping",e.result=d),g}function readTagProperty(e){var t,n,r,o,a=!1,l=!1;if(33!==(o=e.input.charCodeAt(e.position)))return!1;if(null!==e.tag&&throwError(e,"duplication of a tag property"),60===(o=e.input.charCodeAt(++e.position))?(a=!0,o=e.input.charCodeAt(++e.position)):33===o?(l=!0,n="!!",o=e.input.charCodeAt(++e.position)):n="!",t=e.position,a){do o=e.input.charCodeAt(++e.position);while(0!==o&&62!==o);e.position<e.length?(r=e.input.slice(t,e.position),o=e.input.charCodeAt(++e.position)):throwError(e,"unexpected end of the stream within a verbatim tag")}else{for(;0!==o&&!is_WS_OR_EOL(o);)33===o&&(l?throwError(e,"tag suffix cannot contain exclamation marks"):(n=e.input.slice(t-1,e.position+1),PATTERN_TAG_HANDLE.test(n)||throwError(e,"named tag handle cannot contain such characters"),l=!0,t=e.position+1)),o=e.input.charCodeAt(++e.position);r=e.input.slice(t,e.position),PATTERN_FLOW_INDICATORS.test(r)&&throwError(e,"tag suffix cannot contain flow indicator characters")}r&&!PATTERN_TAG_URI.test(r)&&throwError(e,"tag name cannot contain such characters: "+r);try{r=decodeURIComponent(r)}catch(s){throwError(e,"tag name is malformed: "+r)}return a?e.tag=r:_hasOwnProperty$1.call(e.tagMap,n)?e.tag=e.tagMap[n]+r:"!"===n?e.tag="!"+r:"!!"===n?e.tag="tag:yaml.org,2002:"+r:throwError(e,'undeclared tag handle "'+n+'"'),!0}function readAnchorProperty(e){var t,n;if(38!==(n=e.input.charCodeAt(e.position)))return!1;for(null!==e.anchor&&throwError(e,"duplication of an anchor property"),n=e.input.charCodeAt(++e.position),t=e.position;0!==n&&!is_WS_OR_EOL(n)&&!is_FLOW_INDICATOR(n);)n=e.input.charCodeAt(++e.position);return e.position===t&&throwError(e,"name of an anchor node must contain at least one character"),e.anchor=e.input.slice(t,e.position),!0}function readAlias(e){var t,n,r;if(42!==(r=e.input.charCodeAt(e.position)))return!1;for(r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!is_WS_OR_EOL(r)&&!is_FLOW_INDICATOR(r);)r=e.input.charCodeAt(++e.position);return e.position===t&&throwError(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),_hasOwnProperty$1.call(e.anchorMap,n)||throwError(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],skipSeparationSpace(e,!0,-1),!0}function composeNode(e,t,n,r,o){var a,l,s,c,p,u,$,d,f,h=1,E=!1,m=!1;if(null!==e.listener&&e.listener("open",e),e.tag=null,e.anchor=null,e.kind=null,e.result=null,a=l=s=CONTEXT_BLOCK_OUT===n||CONTEXT_BLOCK_IN===n,r&&skipSeparationSpace(e,!0,-1)&&(E=!0,e.lineIndent>t?h=1:e.lineIndent===t?h=0:e.lineIndent<t&&(h=-1)),1===h)for(;readTagProperty(e)||readAnchorProperty(e);)skipSeparationSpace(e,!0,-1)?(E=!0,s=a,e.lineIndent>t?h=1:e.lineIndent===t?h=0:e.lineIndent<t&&(h=-1)):s=!1;if(s&&(s=E||o),(1===h||CONTEXT_BLOCK_OUT===n)&&(d=CONTEXT_FLOW_IN===n||CONTEXT_FLOW_OUT===n?t:t+1,f=e.position-e.lineStart,1===h?s&&(readBlockSequence(e,f)||readBlockMapping(e,f,d))||readFlowCollection(e,d)?m=!0:(l&&readBlockScalar(e,d)||readSingleQuotedScalar(e,d)||readDoubleQuotedScalar(e,d)?m=!0:readAlias(e)?(m=!0,(null!==e.tag||null!==e.anchor)&&throwError(e,"alias node should not have any properties")):readPlainScalar(e,d,CONTEXT_FLOW_IN===n)&&(m=!0,null===e.tag&&(e.tag="?")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===h&&(m=s&&readBlockSequence(e,f))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&throwError(e,'unacceptable node kind for !<?> tag; it should be "scalar", not "'+e.kind+'"'),c=0,p=e.implicitTypes.length;c<p;c+=1)if(($=e.implicitTypes[c]).resolve(e.result)){e.result=$.construct(e.result),e.tag=$.tag,null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);break}}else if("!"!==e.tag){if(_hasOwnProperty$1.call(e.typeMap[e.kind||"fallback"],e.tag))$=e.typeMap[e.kind||"fallback"][e.tag];else for(c=0,$=null,p=(u=e.typeMap.multi[e.kind||"fallback"]).length;c<p;c+=1)if(e.tag.slice(0,u[c].tag.length)===u[c].tag){$=u[c];break}$||throwError(e,"unknown tag !<"+e.tag+">"),null!==e.result&&$.kind!==e.kind&&throwError(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+$.kind+'", not "'+e.kind+'"'),$.resolve(e.result,e.tag)?(e.result=$.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):throwError(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||m}function readDocument(e){var t,n,r,o,a=e.position,l=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(o=e.input.charCodeAt(e.position))&&(skipSeparationSpace(e,!0,-1),o=e.input.charCodeAt(e.position),!(e.lineIndent>0)&&37===o);){for(l=!0,o=e.input.charCodeAt(++e.position),t=e.position;0!==o&&!is_WS_OR_EOL(o);)o=e.input.charCodeAt(++e.position);for(n=e.input.slice(t,e.position),r=[],n.length<1&&throwError(e,"directive name must not be less than one character in length");0!==o;){for(;is_WHITE_SPACE(o);)o=e.input.charCodeAt(++e.position);if(35===o){do o=e.input.charCodeAt(++e.position);while(0!==o&&!is_EOL(o));break}if(is_EOL(o))break;for(t=e.position;0!==o&&!is_WS_OR_EOL(o);)o=e.input.charCodeAt(++e.position);r.push(e.input.slice(t,e.position))}0!==o&&readLineBreak(e),_hasOwnProperty$1.call(directiveHandlers,n)?directiveHandlers[n](e,n,r):throwWarning(e,'unknown document directive "'+n+'"')}if(skipSeparationSpace(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,skipSeparationSpace(e,!0,-1)):l&&throwError(e,"directives end mark is expected"),composeNode(e,e.lineIndent-1,CONTEXT_BLOCK_OUT,!1,!0),skipSeparationSpace(e,!0,-1),e.checkLineBreaks&&PATTERN_NON_ASCII_LINE_BREAKS.test(e.input.slice(a,e.position))&&throwWarning(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&testDocumentSeparator(e)){46===e.input.charCodeAt(e.position)&&(e.position+=3,skipSeparationSpace(e,!0,-1));return}e.position<e.length-1&&throwError(e,"end of the stream or a document separator is expected")}function loadDocuments(e,t){e=String(e),t=t||{},0!==e.length&&(10!==e.charCodeAt(e.length-1)&&13!==e.charCodeAt(e.length-1)&&(e+="\n"),65279===e.charCodeAt(0)&&(e=e.slice(1)));var n=new State$1(e,t),r=e.indexOf("\0");for(-1!==r&&(n.position=r,throwError(n,"null byte is not allowed in input")),n.input+="\0";32===n.input.charCodeAt(n.position);)n.lineIndent+=1,n.position+=1;for(;n.position<n.length-1;)readDocument(n);return n.documents}function loadAll$1(e,t,n){null!==t&&"object"==typeof t&&void 0===n&&(n=t,t=null);var r=loadDocuments(e,n);if("function"!=typeof t)return r;for(var o=0,a=r.length;o<a;o+=1)t(r[o])}function load$1(e,t){var n=loadDocuments(e,t);if(0!==n.length){if(1===n.length)return n[0];throw new exception("expected a single document in the stream, but found more")}}var loadAll_1=loadAll$1,load_1=load$1,loader={loadAll:loadAll_1,load:load_1},_toString=Object.prototype.toString,_hasOwnProperty=Object.prototype.hasOwnProperty,CHAR_BOM=65279,CHAR_TAB=9,CHAR_LINE_FEED=10,CHAR_CARRIAGE_RETURN=13,CHAR_SPACE=32,CHAR_EXCLAMATION=33,CHAR_DOUBLE_QUOTE=34,CHAR_SHARP=35,CHAR_PERCENT=37,CHAR_AMPERSAND=38,CHAR_SINGLE_QUOTE=39,CHAR_ASTERISK=42,CHAR_COMMA=44,CHAR_MINUS=45,CHAR_COLON=58,CHAR_EQUALS=61,CHAR_GREATER_THAN=62,CHAR_QUESTION=63,CHAR_COMMERCIAL_AT=64,CHAR_LEFT_SQUARE_BRACKET=91,CHAR_RIGHT_SQUARE_BRACKET=93,CHAR_GRAVE_ACCENT=96,CHAR_LEFT_CURLY_BRACKET=123,CHAR_VERTICAL_LINE=124,CHAR_RIGHT_CURLY_BRACKET=125,ESCAPE_SEQUENCES={};ESCAPE_SEQUENCES[0]="\\0",ESCAPE_SEQUENCES[7]="\\a",ESCAPE_SEQUENCES[8]="\\b",ESCAPE_SEQUENCES[9]="\\t",ESCAPE_SEQUENCES[10]="\\n",ESCAPE_SEQUENCES[11]="\\v",ESCAPE_SEQUENCES[12]="\\f",ESCAPE_SEQUENCES[13]="\\r",ESCAPE_SEQUENCES[27]="\\e",ESCAPE_SEQUENCES[34]='\\"',ESCAPE_SEQUENCES[92]="\\\\",ESCAPE_SEQUENCES[133]="\\N",ESCAPE_SEQUENCES[160]="\\_",ESCAPE_SEQUENCES[8232]="\\L",ESCAPE_SEQUENCES[8233]="\\P";var DEPRECATED_BOOLEANS_SYNTAX=["y","Y","yes","Yes","YES","on","On","ON","n","N","no","No","NO","off","Off","OFF"],DEPRECATED_BASE60_SYNTAX=/^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;function compileStyleMap(e,t){var n,r,o,a,l,s,c;if(null===t)return{};for(o=0,n={},a=(r=Object.keys(t)).length;o<a;o+=1)s=String(t[l=r[o]]),"!!"===l.slice(0,2)&&(l="tag:yaml.org,2002:"+l.slice(2)),(c=e.compiledTypeMap.fallback[l])&&_hasOwnProperty.call(c.styleAliases,s)&&(s=c.styleAliases[s]),n[l]=s;return n}function encodeHex(e){var t,n,r;if(t=e.toString(16).toUpperCase(),e<=255)n="x",r=2;else if(e<=65535)n="u",r=4;else if(e<=4294967295)n="U",r=8;else throw new exception("code point within a string may not be greater than 0xFFFFFFFF");return"\\"+n+common.repeat("0",r-t.length)+t}var QUOTING_TYPE_SINGLE=1,QUOTING_TYPE_DOUBLE=2;function State(e){this.schema=e.schema||_default,this.indent=Math.max(1,e.indent||2),this.noArrayIndent=e.noArrayIndent||!1,this.skipInvalid=e.skipInvalid||!1,this.flowLevel=common.isNothing(e.flowLevel)?-1:e.flowLevel,this.styleMap=compileStyleMap(this.schema,e.styles||null),this.sortKeys=e.sortKeys||!1,this.lineWidth=e.lineWidth||80,this.noRefs=e.noRefs||!1,this.noCompatMode=e.noCompatMode||!1,this.condenseFlow=e.condenseFlow||!1,this.quotingType='"'===e.quotingType?QUOTING_TYPE_DOUBLE:QUOTING_TYPE_SINGLE,this.forceQuotes=e.forceQuotes||!1,this.replacer="function"==typeof e.replacer?e.replacer:null,this.implicitTypes=this.schema.compiledImplicit,this.explicitTypes=this.schema.compiledExplicit,this.tag=null,this.result="",this.duplicates=[],this.usedDuplicates=null}function indentString(e,t){for(var n,r=common.repeat(" ",t),o=0,a=-1,l="",s=e.length;o<s;)-1===(a=e.indexOf("\n",o))?(n=e.slice(o),o=s):(n=e.slice(o,a+1),o=a+1),n.length&&"\n"!==n&&(l+=r),l+=n;return l}function generateNextLine(e,t){return"\n"+common.repeat(" ",e.indent*t)}function testImplicitResolving(e,t){var n,r,o;for(n=0,r=e.implicitTypes.length;n<r;n+=1)if((o=e.implicitTypes[n]).resolve(t))return!0;return!1}function isWhitespace(e){return e===CHAR_SPACE||e===CHAR_TAB}function isPrintable(e){return 32<=e&&e<=126||161<=e&&e<=55295&&8232!==e&&8233!==e||57344<=e&&e<=65533&&e!==CHAR_BOM||65536<=e&&e<=1114111}function isNsCharOrWhitespace(e){return isPrintable(e)&&e!==CHAR_BOM&&e!==CHAR_CARRIAGE_RETURN&&e!==CHAR_LINE_FEED}function isPlainSafe(e,t,n){var r=isNsCharOrWhitespace(e),o=r&&!isWhitespace(e);return(n?r:r&&e!==CHAR_COMMA&&e!==CHAR_LEFT_SQUARE_BRACKET&&e!==CHAR_RIGHT_SQUARE_BRACKET&&e!==CHAR_LEFT_CURLY_BRACKET&&e!==CHAR_RIGHT_CURLY_BRACKET)&&e!==CHAR_SHARP&&!(t===CHAR_COLON&&!o)||isNsCharOrWhitespace(t)&&!isWhitespace(t)&&e===CHAR_SHARP||t===CHAR_COLON&&o}function isPlainSafeFirst(e){return isPrintable(e)&&e!==CHAR_BOM&&!isWhitespace(e)&&e!==CHAR_MINUS&&e!==CHAR_QUESTION&&e!==CHAR_COLON&&e!==CHAR_COMMA&&e!==CHAR_LEFT_SQUARE_BRACKET&&e!==CHAR_RIGHT_SQUARE_BRACKET&&e!==CHAR_LEFT_CURLY_BRACKET&&e!==CHAR_RIGHT_CURLY_BRACKET&&e!==CHAR_SHARP&&e!==CHAR_AMPERSAND&&e!==CHAR_ASTERISK&&e!==CHAR_EXCLAMATION&&e!==CHAR_VERTICAL_LINE&&e!==CHAR_EQUALS&&e!==CHAR_GREATER_THAN&&e!==CHAR_SINGLE_QUOTE&&e!==CHAR_DOUBLE_QUOTE&&e!==CHAR_PERCENT&&e!==CHAR_COMMERCIAL_AT&&e!==CHAR_GRAVE_ACCENT}function isPlainSafeLast(e){return!isWhitespace(e)&&e!==CHAR_COLON}function codePointAt(e,t){var n,r=e.charCodeAt(t);return r>=55296&&r<=56319&&t+1<e.length&&(n=e.charCodeAt(t+1))>=56320&&n<=57343?(r-55296)*1024+n-56320+65536:r}function needIndentIndicator(e){return/^\n* /.test(e)}var STYLE_PLAIN=1,STYLE_SINGLE=2,STYLE_LITERAL=3,STYLE_FOLDED=4,STYLE_DOUBLE=5;function chooseScalarStyle(e,t,n,r,o,a,l,s){var c,p=0,u=null,$=!1,d=!1,f=-1!==r,h=-1,E=isPlainSafeFirst(codePointAt(e,0))&&isPlainSafeLast(codePointAt(e,e.length-1));if(t||l)for(c=0;c<e.length;p>=65536?c+=2:c++){if(p=codePointAt(e,c),!isPrintable(p))return STYLE_DOUBLE;E=E&&isPlainSafe(p,u,s),u=p}else{for(c=0;c<e.length;p>=65536?c+=2:c++){if((p=codePointAt(e,c))===CHAR_LINE_FEED)$=!0,f&&(d=d||c-h-1>r&&" "!==e[h+1],h=c);else if(!isPrintable(p))return STYLE_DOUBLE;E=E&&isPlainSafe(p,u,s),u=p}d=d||f&&c-h-1>r&&" "!==e[h+1]}return $||d?n>9&&needIndentIndicator(e)?STYLE_DOUBLE:l?a===QUOTING_TYPE_DOUBLE?STYLE_DOUBLE:STYLE_SINGLE:d?STYLE_FOLDED:STYLE_LITERAL:!E||l||o(e)?a===QUOTING_TYPE_DOUBLE?STYLE_DOUBLE:STYLE_SINGLE:STYLE_PLAIN}function writeScalar(e,t,n,r,o){e.dump=function(){if(0===t.length)return e.quotingType===QUOTING_TYPE_DOUBLE?'""':"''";if(!e.noCompatMode&&(-1!==DEPRECATED_BOOLEANS_SYNTAX.indexOf(t)||DEPRECATED_BASE60_SYNTAX.test(t)))return e.quotingType===QUOTING_TYPE_DOUBLE?'"'+t+'"':"'"+t+"'";var a=e.indent*Math.max(1,n),l=-1===e.lineWidth?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-a),s=r||e.flowLevel>-1&&n>=e.flowLevel;switch(chooseScalarStyle(t,s,e.indent,l,function t(n){return testImplicitResolving(e,n)},e.quotingType,e.forceQuotes&&!r,o)){case STYLE_PLAIN:return t;case STYLE_SINGLE:return"'"+t.replace(/'/g,"''")+"'";case STYLE_LITERAL:return"|"+blockHeader(t,e.indent)+dropEndingNewline(indentString(t,a));case STYLE_FOLDED:return">"+blockHeader(t,e.indent)+dropEndingNewline(indentString(foldString(t,l),a));case STYLE_DOUBLE:return'"'+escapeString(t)+'"';default:throw new exception("impossible error: invalid scalar style")}}()}function blockHeader(e,t){var n,r=needIndentIndicator(e)?String(t):"",o="\n"===e[e.length-1];return r+(o&&("\n"===e[e.length-2]||"\n"===e)?"+":o?"":"-")+"\n"}function dropEndingNewline(e){return"\n"===e[e.length-1]?e.slice(0,-1):e}function foldString(e,t){for(var n,r,o,a=/(\n+)([^\n]*)/g,l=(o=-1!==(o=e.indexOf("\n"))?o:e.length,a.lastIndex=o,foldLine(e.slice(0,o),t)),s="\n"===e[0]||" "===e[0];r=a.exec(e);){var c=r[1],p=r[2];n=" "===p[0],l+=c+(s||n||""===p?"":"\n")+foldLine(p,t),s=n}return l}function foldLine(e,t){if(""===e||" "===e[0])return e;for(var n,r,o=/ [^ ]/g,a=0,l=0,s=0,c="";n=o.exec(e);)(s=n.index)-a>t&&(r=l>a?l:s,c+="\n"+e.slice(a,r),a=r+1),l=s;return c+="\n",e.length-a>t&&l>a?c+=e.slice(a,l)+"\n"+e.slice(l+1):c+=e.slice(a),c.slice(1)}function escapeString(e){for(var t,n="",r=0,o=0;o<e.length;r>=65536?o+=2:o++)!(t=ESCAPE_SEQUENCES[r=codePointAt(e,o)])&&isPrintable(r)?(n+=e[o],r>=65536&&(n+=e[o+1])):n+=t||encodeHex(r);return n}function writeFlowSequence(e,t,n){var r,o,a,l="",s=e.tag;for(r=0,o=n.length;r<o;r+=1)a=n[r],e.replacer&&(a=e.replacer.call(n,String(r),a)),(writeNode(e,t,a,!1,!1)||void 0===a&&writeNode(e,t,null,!1,!1))&&(""!==l&&(l+=","+(e.condenseFlow?"":" ")),l+=e.dump);e.tag=s,e.dump="["+l+"]"}function writeBlockSequence(e,t,n,r){var o,a,l,s="",c=e.tag;for(o=0,a=n.length;o<a;o+=1)l=n[o],e.replacer&&(l=e.replacer.call(n,String(o),l)),(writeNode(e,t+1,l,!0,!0,!1,!0)||void 0===l&&writeNode(e,t+1,null,!0,!0,!1,!0))&&(r&&""===s||(s+=generateNextLine(e,t)),e.dump&&CHAR_LINE_FEED===e.dump.charCodeAt(0)?s+="-":s+="- ",s+=e.dump);e.tag=c,e.dump=s||"[]"}function writeFlowMapping(e,t,n){var r,o,a,l,s,c="",p=e.tag,u=Object.keys(n);for(r=0,o=u.length;r<o;r+=1){if(s="",""!==c&&(s+=", "),e.condenseFlow&&(s+='"'),l=n[a=u[r]],e.replacer&&(l=e.replacer.call(n,a,l)),writeNode(e,t,a,!1,!1))e.dump.length>1024&&(s+="? "),s+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),writeNode(e,t,l,!1,!1)&&(s+=e.dump,c+=s)}e.tag=p,e.dump="{"+c+"}"}function writeBlockMapping(e,t,n,r){var o,a,l,s,c,p,u="",$=e.tag,d=Object.keys(n);if(!0===e.sortKeys)d.sort();else if("function"==typeof e.sortKeys)d.sort(e.sortKeys);else if(e.sortKeys)throw new exception("sortKeys must be a boolean or a function");for(o=0,a=d.length;o<a;o+=1){if(p="",r&&""===u||(p+=generateNextLine(e,t)),s=n[l=d[o]],e.replacer&&(s=e.replacer.call(n,l,s)),writeNode(e,t+1,l,!0,!0,!0))(c=null!==e.tag&&"?"!==e.tag||e.dump&&e.dump.length>1024)&&(e.dump&&CHAR_LINE_FEED===e.dump.charCodeAt(0)?p+="?":p+="? "),p+=e.dump,c&&(p+=generateNextLine(e,t)),writeNode(e,t+1,s,!0,c)&&(e.dump&&CHAR_LINE_FEED===e.dump.charCodeAt(0)?p+=":":p+=": ",p+=e.dump,u+=p)}e.tag=$,e.dump=u||"{}"}function detectType(e,t,n){var r,o,a,l,s,c;for(a=0,l=(o=n?e.explicitTypes:e.implicitTypes).length;a<l;a+=1)if(((s=o[a]).instanceOf||s.predicate)&&(!s.instanceOf||"object"==typeof t&&t instanceof s.instanceOf)&&(!s.predicate||s.predicate(t))){if(n?s.multi&&s.representName?e.tag=s.representName(t):e.tag=s.tag:e.tag="?",s.represent){if(c=e.styleMap[s.tag]||s.defaultStyle,"[object Function]"===_toString.call(s.represent))r=s.represent(t,c);else if(_hasOwnProperty.call(s.represent,c))r=s.represent[c](t,c);else throw new exception("!<"+s.tag+'> tag resolver accepts not "'+c+'" style');e.dump=r}return!0}return!1}function writeNode(e,t,n,r,o,a,l){e.tag=null,e.dump=n,detectType(e,n,!1)||detectType(e,n,!0);var s=_toString.call(e.dump),c=r;r&&(r=e.flowLevel<0||e.flowLevel>t);var p,u,$,d="[object Object]"===s||"[object Array]"===s;if(d&&($=-1!==(u=e.duplicates.indexOf(n))),(null!==e.tag&&"?"!==e.tag||$||2!==e.indent&&t>0)&&(o=!1),$&&e.usedDuplicates[u])e.dump="*ref_"+u;else{if(d&&$&&!e.usedDuplicates[u]&&(e.usedDuplicates[u]=!0),"[object Object]"===s)r&&0!==Object.keys(e.dump).length?(writeBlockMapping(e,t,e.dump,o),$&&(e.dump="&ref_"+u+e.dump)):(writeFlowMapping(e,t,e.dump),$&&(e.dump="&ref_"+u+" "+e.dump));else if("[object Array]"===s)r&&0!==e.dump.length?(e.noArrayIndent&&!l&&t>0?writeBlockSequence(e,t-1,e.dump,o):writeBlockSequence(e,t,e.dump,o),$&&(e.dump="&ref_"+u+e.dump)):(writeFlowSequence(e,t,e.dump),$&&(e.dump="&ref_"+u+" "+e.dump));else if("[object String]"===s)"?"!==e.tag&&writeScalar(e,e.dump,t,a,c);else{if("[object Undefined]"===s||e.skipInvalid)return!1;throw new exception("unacceptable kind of an object to dump "+s)}null!==e.tag&&"?"!==e.tag&&(p=encodeURI("!"===e.tag[0]?e.tag.slice(1):e.tag).replace(/!/g,"%21"),p="!"===e.tag[0]?"!"+p:"tag:yaml.org,2002:"===p.slice(0,18)?"!!"+p.slice(18):"!<"+p+">",e.dump=p+" "+e.dump)}return!0}function getDuplicateReferences(e,t){var n,r,o=[],a=[];for(inspectNode(e,o,a),n=0,r=a.length;n<r;n+=1)t.duplicates.push(o[a[n]]);t.usedDuplicates=Array(r)}function inspectNode(e,t,n){var r,o,a;if(null!==e&&"object"==typeof e){if(-1!==(o=t.indexOf(e)))-1===n.indexOf(o)&&n.push(o);else if(t.push(e),Array.isArray(e))for(o=0,a=e.length;o<a;o+=1)inspectNode(e[o],t,n);else for(o=0,a=(r=Object.keys(e)).length;o<a;o+=1)inspectNode(e[r[o]],t,n)}}function dump$1(e,t){t=t||{};var n=new State(t);n.noRefs||getDuplicateReferences(e,n);var r=e;return(n.replacer&&(r=n.replacer.call({"":r},"",r)),writeNode(n,0,r,!0,!0))?n.dump+"\n":""}var dump_1=dump$1,dumper={dump:dump_1};function renamed(e,t){return function(){throw Error("Function yaml."+e+" is removed in js-yaml 4. Use yaml."+t+" instead, which is now safe by default.")}}var Type=type,Schema=schema,FAILSAFE_SCHEMA=failsafe,JSON_SCHEMA=json,CORE_SCHEMA=core,DEFAULT_SCHEMA=_default,load=loader.load,loadAll=loader.loadAll,dump=dumper.dump,YAMLException=exception,types={binary:binary,float:float,map:map,null:_null,pairs:pairs,set:set,timestamp:timestamp,bool:bool,int:int,merge:merge,omap:omap,seq:seq,str:str},safeLoad=renamed("safeLoad","load"),safeLoadAll=renamed("safeLoadAll","loadAll"),safeDump=renamed("safeDump","dump"),jsYaml={Type:Type,Schema:Schema,FAILSAFE_SCHEMA:FAILSAFE_SCHEMA,JSON_SCHEMA:JSON_SCHEMA,CORE_SCHEMA:CORE_SCHEMA,DEFAULT_SCHEMA:DEFAULT_SCHEMA,load:load,loadAll:loadAll,dump:dump,YAMLException:YAMLException,types:types,safeLoad:safeLoad,safeLoadAll:safeLoadAll,safeDump:safeDump};
return load(yaml_input)
$$ LANGUAGE plv8 IMMUTABLE STRICT;
-- example
SELECT plv8_yaml_to_json('hello: world');
-- {"hello": "world"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment