!function(E,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.sqlFormatter=e():E.sqlFormatter=e()}(window,(function(){return function(E){var e={};function t(T){if(e[T])return e[T].exports;var R=e[T]={i:T,l:!1,exports:{}};return E[T].call(R.exports,R,R.exports,t),R.l=!0,R.exports}return t.m=E,t.c=e,t.d=function(E,e,T){t.o(E,e)||Object.defineProperty(E,e,{enumerable:!0,get:T})},t.r=function(E){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(E,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(E,"__esModule",{value:!0})},t.t=function(E,e){if(1&e&&(E=t(E)),8&e)return E;if(4&e&&"object"==typeof E&&E&&E.__esModule)return E;var T=Object.create(null);if(t.r(T),Object.defineProperty(T,"default",{enumerable:!0,value:E}),2&e&&"string"!=typeof E)for(var R in E)t.d(T,R,function(e){return E[e]}.bind(null,R));return T},t.n=function(E){var e=E&&E.__esModule?function(){return E.default}:function(){return E};return t.d(e,"a",e),e},t.o=function(E,e){return Object.prototype.hasOwnProperty.call(E,e)},t.p="",t(t.s=0)}([function(E,e,t){"use strict";t.r(e),t.d(e,"format",(function(){return Ze})),t.d(e,"supportedDialects",(function(){return Qe}));var T={WORD:"word",STRING:"string",RESERVED:"reserved",RESERVED_TOP_LEVEL:"reserved-top-level",RESERVED_TOP_LEVEL_NO_INDENT:"reserved-top-level-no-indent",RESERVED_NEWLINE:"reserved-newline",OPERATOR:"operator",OPEN_PAREN:"open-paren",CLOSE_PAREN:"close-paren",LINE_COMMENT:"line-comment",BLOCK_COMMENT:"block-comment",NUMBER:"number",PLACEHOLDER:"placeholder"},R=function(E){return E.replace(/[\t ]+$/,"")},n=function(E){return E.replace(/[\$\(-\+\.\?\[-\^\{-\}]/g,"\\$&")},r=function(E){return E.sort((function(E,e){return e.length-E.length||E.localeCompare(e)}))};function N(E,e){for(var t=0;t0&&"top-level"===(E=this.indentTypes)[E.length-1]&&this.indentTypes.pop()}},{key:"decreaseBlockLevel",value:function(){for(;this.indentTypes.length>0&&"top-level"===this.indentTypes.pop(););}},{key:"resetIndentation",value:function(){this.indentTypes=[]}}])&&N(e.prototype,t),T&&N(e,T),E}();function A(E,e){for(var t=0;t0?this.level++:this.level=0}},{key:"end",value:function(){this.level--}},{key:"isActive",value:function(){return this.level>0}},{key:"isInlineBlock",value:function(E,e){for(var t=0,R=0,n=e;n50)return!1;if(r.type===T.OPEN_PAREN)R++;else if(r.type===T.CLOSE_PAREN&&0==--R)return!0;if(this.isForbiddenToken(r))return!1}return!1}},{key:"isForbiddenToken",value:function(E){var e=E.type,t=E.value;return e===T.RESERVED_TOP_LEVEL||e===T.RESERVED_NEWLINE||e===T.COMMENT||e===T.BLOCK_COMMENT||";"===t}}])&&A(e.prototype,t),R&&A(e,R),E}();function o(E,e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:1;return this.tokens[this.index-E]}},{key:"tokenLookAhead",value:function(){var E=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.tokens[this.index+E]}}])&&l(e.prototype,t),n&&l(e,n),E}();function P(E){if(0===E.length)return new RegExp("^\b$","u");var e=r(E).join("|").replace(/ /g,"\\s+");return new RegExp("^(".concat(e,")\\b"),"iu")}function M(E){var e={"``":"((`[^`]*($|`))+)","{}":"((\\{[^\\}]*($|\\}))+)","[]":"((\\[[^\\]]*($|\\]))(\\][^\\]]*($|\\]))*)",'""':'(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)',"''":"(('[^'\\\\]*(?:\\\\.[^'\\\\]*)*('|$))+)","N''":"((N'[^'\\\\]*(?:\\\\.[^'\\\\]*)*('|$))+)","U&''":"((U&'[^'\\\\]*(?:\\\\.[^'\\\\]*)*('|$))+)",'U&""':'((U&"[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)',$$:"((?\\$\\w*\\$)[\\s\\S]*?(?:\\k|$))"};return E.map((function(E){return e[E]})).join("|")}function p(E){return new RegExp("^("+E.map(y).join("|")+")","iu")}function y(E){return 1===E.length?n(E):"\\b"+E+"\\b"}function _(E,e){if(t=E,!Array.isArray(t)||0===t.length)return!1;var t,T=E.map(n).join("|");return new RegExp("^((?:".concat(T,")(?:").concat(e,"))"),"u")}function h(E,e){var t=Object.keys(E);if(Object.getOwnPropertySymbols){var T=Object.getOwnPropertySymbols(E);e&&(T=T.filter((function(e){return Object.getOwnPropertyDescriptor(E,e).enumerable}))),t.push.apply(t,T)}return t}function G(E){for(var e=1;eE.length)&&(e=E.length);for(var t=0,T=new Array(e);t","<=",">="].concat(F(e.operators||[])),new RegExp("^(".concat(r(t).map(n).join("|"),"|.)"),"u")),this.BLOCK_COMMENT_REGEX=/^(\/\*(?:(?![])[\s\S])*?(?:\*\/|$))/,this.LINE_COMMENT_REGEX=(T=e.lineCommentTypes,new RegExp("^((?:".concat(T.map((function(E){return n(E)})).join("|"),").*?)(?:\r\n|\r|\n|$)"),"u")),this.RESERVED_TOP_LEVEL_REGEX=P(e.reservedTopLevelWords),this.RESERVED_TOP_LEVEL_NO_INDENT_REGEX=P(e.reservedTopLevelWordsNoIndent),this.RESERVED_NEWLINE_REGEX=P(e.reservedNewlineWords),this.RESERVED_PLAIN_REGEX=P(e.reservedWords),this.WORD_REGEX=function(){var E=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return new RegExp("^([\\p{Alphabetic}\\p{Mark}\\p{Decimal_Number}\\p{Connector_Punctuation}\\p{Join_Control}".concat(E.join(""),"]+)"),"u")}(e.specialWordChars),this.STRING_REGEX=(R=e.stringTypes,new RegExp("^("+M(R)+")","u")),this.OPEN_PAREN_REGEX=p(e.openParens),this.CLOSE_PAREN_REGEX=p(e.closeParens),this.INDEXED_PLACEHOLDER_REGEX=_(e.indexedPlaceholderTypes,"[0-9]*"),this.IDENT_NAMED_PLACEHOLDER_REGEX=_(e.namedPlaceholderTypes,"[a-zA-Z0-9._$]+"),this.STRING_NAMED_PLACEHOLDER_REGEX=_(e.namedPlaceholderTypes,M(e.stringTypes))}var e,t,R;return e=E,(t=[{key:"tokenize",value:function(E){for(var e,t=[];E.length;){var T=this.getWhitespace(E);(E=E.substring(T.length)).length&&(e=this.getNextToken(E,e),E=E.substring(e.value.length),t.push(G(G({},e),{},{whitespaceBefore:T})))}return t}},{key:"getWhitespace",value:function(E){var e=E.match(this.WHITESPACE_REGEX);return e?e[1]:""}},{key:"getNextToken",value:function(E,e){return this.getCommentToken(E)||this.getStringToken(E)||this.getOpenParenToken(E)||this.getCloseParenToken(E)||this.getPlaceholderToken(E)||this.getNumberToken(E)||this.getReservedWordToken(E,e)||this.getWordToken(E)||this.getOperatorToken(E)}},{key:"getCommentToken",value:function(E){return this.getLineCommentToken(E)||this.getBlockCommentToken(E)}},{key:"getLineCommentToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.LINE_COMMENT,regex:this.LINE_COMMENT_REGEX})}},{key:"getBlockCommentToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.BLOCK_COMMENT,regex:this.BLOCK_COMMENT_REGEX})}},{key:"getStringToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.STRING,regex:this.STRING_REGEX})}},{key:"getOpenParenToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.OPEN_PAREN,regex:this.OPEN_PAREN_REGEX})}},{key:"getCloseParenToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.CLOSE_PAREN,regex:this.CLOSE_PAREN_REGEX})}},{key:"getPlaceholderToken",value:function(E){return this.getIdentNamedPlaceholderToken(E)||this.getStringNamedPlaceholderToken(E)||this.getIndexedPlaceholderToken(E)}},{key:"getIdentNamedPlaceholderToken",value:function(E){return this.getPlaceholderTokenWithKey({input:E,regex:this.IDENT_NAMED_PLACEHOLDER_REGEX,parseKey:function(E){return E.slice(1)}})}},{key:"getStringNamedPlaceholderToken",value:function(E){var e=this;return this.getPlaceholderTokenWithKey({input:E,regex:this.STRING_NAMED_PLACEHOLDER_REGEX,parseKey:function(E){return e.getEscapedPlaceholderKey({key:E.slice(2,-1),quoteChar:E.slice(-1)})}})}},{key:"getIndexedPlaceholderToken",value:function(E){return this.getPlaceholderTokenWithKey({input:E,regex:this.INDEXED_PLACEHOLDER_REGEX,parseKey:function(E){return E.slice(1)}})}},{key:"getPlaceholderTokenWithKey",value:function(E){var e=E.input,t=E.regex,R=E.parseKey,n=this.getTokenOnFirstMatch({input:e,regex:t,type:T.PLACEHOLDER});return n&&(n.key=R(n.value)),n}},{key:"getEscapedPlaceholderKey",value:function(E){var e=E.key,t=E.quoteChar;return e.replace(new RegExp(n("\\"+t),"gu"),t)}},{key:"getNumberToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.NUMBER,regex:this.NUMBER_REGEX})}},{key:"getOperatorToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.OPERATOR,regex:this.OPERATOR_REGEX})}},{key:"getReservedWordToken",value:function(E,e){if(!e||!e.value||"."!==e.value)return this.getTopLevelReservedToken(E)||this.getNewlineReservedToken(E)||this.getTopLevelReservedTokenNoIndent(E)||this.getPlainReservedToken(E)}},{key:"getTopLevelReservedToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.RESERVED_TOP_LEVEL,regex:this.RESERVED_TOP_LEVEL_REGEX})}},{key:"getNewlineReservedToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.RESERVED_NEWLINE,regex:this.RESERVED_NEWLINE_REGEX})}},{key:"getTopLevelReservedTokenNoIndent",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.RESERVED_TOP_LEVEL_NO_INDENT,regex:this.RESERVED_TOP_LEVEL_NO_INDENT_REGEX})}},{key:"getPlainReservedToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.RESERVED,regex:this.RESERVED_PLAIN_REGEX})}},{key:"getWordToken",value:function(E){return this.getTokenOnFirstMatch({input:E,type:T.WORD,regex:this.WORD_REGEX})}},{key:"getTokenOnFirstMatch",value:function(E){var e=E.input,t=E.type,T=E.regex,R=e.match(T);return R?{type:t,value:R[1]}:void 0}}])&&H(e.prototype,t),R&&H(e,R),E}();function b(E){return(b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(E){return typeof E}:function(E){return E&&"function"==typeof Symbol&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E})(E)}function V(E,e){if(!(E instanceof e))throw new TypeError("Cannot call a class as a function")}function Y(E,e){for(var t=0;t","!>","||"]})}}])&&Y(e.prototype,t),T&&Y(e,T),n}(f);function x(E){return(x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(E){return typeof E}:function(E){return E&&"function"==typeof Symbol&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E})(E)}function Z(E,e){if(!(E instanceof e))throw new TypeError("Cannot call a class as a function")}function Q(E,e){for(var t=0;t>","!=","<>","<=>","&&","||"]})}}])&&Q(e.prototype,t),T&&Q(e,T),n}(f);function rE(E){return(rE="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(E){return typeof E}:function(E){return E&&"function"==typeof Symbol&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E})(E)}function NE(E,e){if(!(E instanceof e))throw new TypeError("Cannot call a class as a function")}function IE(E,e){for(var t=0;t>","!=","<>","<=>","&&","||","->","->>"]})}}])&&IE(e.prototype,t),T&&IE(e,T),n}(f);function aE(E){return(aE="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(E){return typeof E}:function(E){return E&&"function"==typeof Symbol&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E})(E)}function sE(E,e){if(!(E instanceof e))throw new TypeError("Cannot call a class as a function")}function UE(E,e){for(var t=0;t>","||/","|/","::","->>","->","~~*","~~","!~~*","!~~","~*","!~*","!~","!!"]})}}])&&wE(e.prototype,t),T&&wE(e,T),n}(f);function Ee(E){return(Ee="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(E){return typeof E}:function(E){return E&&"function"==typeof Symbol&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E})(E)}function ee(E,e){if(!(E instanceof e))throw new TypeError("Cannot call a class as a function")}function te(E,e){for(var t=0;t>","!=","||"]})}}])&&te(e.prototype,t),T&&te(e,T),n}(f);function Se(E){return(Se="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(E){return typeof E}:function(E){return E&&"function"==typeof Symbol&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E})(E)}function Le(E,e){if(!(E instanceof e))throw new TypeError("Cannot call a class as a function")}function ie(E,e){for(var t=0;t","&&","||","=="]})}},{key:"tokenOverride",value:function(E){if(s(E)){var e=this.tokenLookAhead();if(e&&e.type===T.OPEN_PAREN)return{type:T.RESERVED,value:E.value}}if(U(E)){var t=this.tokenLookBehind();if(t&&t.type===T.OPERATOR&&"."===t.value)return{type:T.WORD,value:E.value}}return E}}])&&ie(e.prototype,t),R&&ie(e,R),r}(f);function Pe(E){return(Pe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(E){return typeof E}:function(E){return E&&"function"==typeof Symbol&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E})(E)}function Me(E,e){if(!(E instanceof e))throw new TypeError("Cannot call a class as a function")}function pe(E,e){for(var t=0;t=","<=","<>","!=","!<","!>","+=","-=","*=","/=","%=","|=","&=","^=","::"]})}}])&&Ye(e.prototype,t),T&&Ye(e,T),n}(f)},Ze=function(E){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("string"!=typeof E)throw new Error("Invalid query argument. Extected string, instead got "+je(E));var t=Be;if(void 0!==e.language&&(t=xe[e.language]),void 0===t)throw Error("Unsupported SQL dialect: ".concat(e.language));return new t(e).format(E)},Qe=Object.keys(xe)}])})); //# sourceMappingURL=sql-formatter.min.js.map