Socket
Socket
Sign inDemoInstall

@bbob/parser

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bbob/parser - npm Package Compare versions

Comparing version 2.5.3 to 2.5.4

18

CHANGELOG.md

@@ -6,2 +6,20 @@ # Change Log

<a name="2.5.4"></a>
## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25)
### Bug Fixes
* **parser:** infinity loop problem when escape `[\b]` ([#31](https://github.com/JiLiZART/bbob/issues/31)) ([b4cf271](https://github.com/JiLiZART/bbob/commit/b4cf271)), closes [#23](https://github.com/JiLiZART/bbob/issues/23)
* **parser:** try to hack terser minifier that removes working code ([#49](https://github.com/JiLiZART/bbob/issues/49)) ([be938fd](https://github.com/JiLiZART/bbob/commit/be938fd)), closes [#48](https://github.com/JiLiZART/bbob/issues/48)
### Features
* **parse:** allow tags to be escaped with backslash ([#17](https://github.com/JiLiZART/bbob/issues/17)) ([c4f78c1](https://github.com/JiLiZART/bbob/commit/c4f78c1))
* **plugin-helper:** lowercase resulting tag names ([#42](https://github.com/JiLiZART/bbob/issues/42)) ([597c2a9](https://github.com/JiLiZART/bbob/commit/597c2a9))
<a name="2.5.3"></a>

@@ -8,0 +26,0 @@ ## [2.5.3](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.3) (2019-08-11)

48

dist/index.js

@@ -403,26 +403,28 @@ (function (global, factory) {

* @param {String} source
* @param {Function} onSkip
* @param {Object} options
* @param {Function} options.onSkip
* @returns
*/
var createCharGrabber = function createCharGrabber(source) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
onSkip = _ref.onSkip;
var createCharGrabber = function createCharGrabber(source, options) {
// let idx = 0;
var cursor = {
pos: 0,
length: source.length
};
var idx = 0;
var skip = function skip() {
idx += 1;
cursor.pos += 1;
if (onSkip) {
onSkip();
if (options && options.onSkip) {
options.onSkip();
}
};
var hasNext = function hasNext() {
return source.length > idx;
return cursor.length > cursor.pos;
};
var getRest = function getRest() {
return source.substr(idx);
return source.substr(cursor.pos);
};
var getCurr = function getCurr() {
return source[idx];
return source[cursor.pos];
};

@@ -434,18 +436,26 @@

isLast: function isLast() {
return idx === source.length;
return cursor.pos === cursor.length;
},
/**
* @param {Function} cond
* @returns {string}
*/
grabWhile: function grabWhile(cond) {
var start = idx;
var start = 0;
while (hasNext() && cond(getCurr())) {
skip();
if (hasNext()) {
start = cursor.pos;
while (hasNext() && cond(getCurr())) {
skip();
}
}
return source.substr(start, idx - start);
return source.substr(start, cursor.pos - start);
},
getNext: function getNext() {
return source[idx + 1];
return source[cursor.pos + 1];
},
getPrev: function getPrev() {
return source[idx - 1];
return source[cursor.pos - 1];
},

@@ -452,0 +462,0 @@ getCurr: getCurr,

@@ -1,1 +0,1 @@

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.BbobParser={})}(this,function(t){"use strict";function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function e(t,n){return t(n={exports:{}},n.exports),n.exports}var a=e(function(t,n){n.__esModule=!0;n.N="\n",n.F="\f",n.R="\r",n.TAB="\t",n.EQ="=",n.QUOTEMARK='"',n.SPACE=" ",n.OPEN_BRAKET="[",n.CLOSE_BRAKET="]",n.SLASH="/",n.PLACEHOLDER_SPACE_TAB=" ",n.PLACEHOLDER_SPACE=" ",n.BACKSLASH="\\"});n(a);var L=a.N,b=a.TAB,O=a.EQ,S=a.QUOTEMARK,x=a.SPACE,k=a.OPEN_BRAKET,C=a.CLOSE_BRAKET,m=a.SLASH,w=a.BACKSLASH,o=e(function(t,n){n.__esModule=!0,n.isEOL=n.isStringNode=n.isTagNode=n.getNodeLength=n.appendToNode=n.attrValue=n.attrsToString=void 0;var r=function(t){return"object"==typeof t&&!!t.tag},o=function(t){return"string"==typeof t},i=function(t){return t.replace(/"/g,"&quot;")},u=function(t,n){var e=typeof n,r={boolean:function(){return n?""+t:""},number:function(){return t+'="'+n+'"'},string:function(){return t+'="'+i(n)+'"'},object:function(){return t+'="'+i(JSON.stringify(n))+'"'}};return r[e]?r[e]():""};n.attrsToString=function(e){return void 0===e?"":Object.keys(e).reduce(function(t,n){return[].concat(t,[u(n,e[n])])},[""]).join(" ")},n.attrValue=u,n.appendToNode=function(t,n){t.content.push(n)},n.getNodeLength=function e(t){return r(t)?t.content.reduce(function(t,n){return t+e(n)},0):o(t)?t.length:0},n.isTagNode=r,n.isStringNode=o,n.isEOL=function(t){return t===a.N}});n(o);var r=e(function(t,n){n.__esModule=!0,n.TagNode=void 0;var e=function(){function r(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,n,e){return n&&r(t.prototype,n),e&&r(t,e),t}}();var r=function(){function r(t,n,e){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,r),this.tag=t.toLowerCase(),this.attrs=n,this.content=[].concat(e)}return r.prototype.attr=function(t,n){return void 0!==n&&(this.attrs[t]=n),this.attrs[t]},r.prototype.append=function(t){return(0,o.appendToNode)(this,t)},r.prototype.toString=function(){var t=a.OPEN_BRAKET,n=a.CLOSE_BRAKET;return t+this.tag+n+this.content.reduce(function(t,n){return t+""+n},"")+t+a.SLASH+this.tag+n},e(r,[{key:"length",get:function(){return(0,o.getNodeLength)(this)}}]),r}();r.create=function(t){return new r(t,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},2<arguments.length&&void 0!==arguments[2]?arguments[2]:[])},r.isOf=function(t,n){return t.tag===n},n.TagNode=r,n.default=r}),h=n(r),i=r.TagNode,u="type",s="value",f="line",c="word",l="attr-name",g="attr-value",p="space",d="new-line",v=function(t){return t[s]},T=function(t){return v(t).charCodeAt(0)==m.charCodeAt(0)},y=function(){function o(t,n,e,r){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,o),this[u]=t+"",this[s]=n+"",this[f]=+e,this.row=+r}return o.prototype.isEmpty=function(){return!!this[u]},o.prototype.isText=function(){return(t=this)[u]===p||t[u]===d||t[u]===c;var t},o.prototype.isTag=function(){return"tag"===this[u]},o.prototype.isAttrName=function(){return this[u]===l},o.prototype.isAttrValue=function(){return this[u]===g},o.prototype.isStart=function(){return!T(this)},o.prototype.isEnd=function(){return T(this)},o.prototype.getName=function(){return n=v(t=this),T(t)?n.slice(1):n;var t,n},o.prototype.getValue=function(){return v(this)},o.prototype.getLine=function(){return this[f]},o.prototype.getColumn=function(){return this.row},o.prototype.toString=function(){return t=k,t+=v(this),t+=C;var t},o}(),_=c,P=function(e){var t=(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).onSkip,r=0,o=function(){r+=1,t&&t()},i=function(){return r<e.length},u=function(){return e.substr(r)},a=function(){return e[r]};return{skip:o,hasNext:i,isLast:function(){return r===e.length},grabWhile:function(t){for(var n=r;i()&&t(a());)o();return e.substr(n,r-n)},getNext:function(){return e[r+1]},getPrev:function(){return e[r-1]},getCurr:a,getRest:u,substrUntilChar:function(t){var n=u(),e=n.indexOf(t);return e<0?"":n.substr(0,e)}}},A=function(){var n=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];return{getLast:function(){return n.length?n[n.length-1]:null},flushLast:function(){return!!n.length&&n.pop()},push:function(t){return n.push(t)},toArray:function(){return n}}},B=function(t,n){return new y(t,n,2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,3<arguments.length&&void 0!==arguments[3]?arguments[3]:0)};function N(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},f=0,c=0,r=-1,o=Array(Math.floor(e.length)),s=n.openTag||k,l=n.closeTag||C,g=n.enableEscapeTags,p=[l,s,S,w,x,b,O,L,"!"],i=[s,x,b,L],u=[x,b],h=[O,x,b],d=function(t){return 0<=u.indexOf(t)},v=function(t){return-1==i.indexOf(t)},T=function(t){return t===s||t===l||t===w},y=function(t){return t===w},A=function(t){n.onToken&&n.onToken(t),o[r+=1]=t},N=function(t){for(var u=null,a=!1,r=[],s=P(t),o=function(t){var n=t===O,e=d(t),r=s.getPrev(),o=s.getNext(),i=r===w;return null===u?!1===(n||e||s.isLast()):!(!a||h.indexOf(t)<0)||!!(t!==S||i||(a=!a)||o===O||d(o))&&!1===(n||e)},n=function(){var t=s.grabWhile(o),n=s.getCurr();if(null===u)u=t;else if(d(n)||n===S||!s.hasNext()){var e=function(t,n){for(;t.charAt(0)===n;)t=t.substring(1);for(;t.charAt(t.length-1)===n;)t=t.substring(0,t.length-1);return t}(t,S).replace(w+S,S);r.push(B("attr-value",e,f,c))}else r.push(B("attr-name",t,f,c));s.skip()};s.hasNext();)n();return{tag:u,attrs:r}},E=P(e,{onSkip:function(){c++}}),t=function(){var t=E.getCurr(),n=E.getNext();if(t===L)E.skip(),A(B("new-line",t,++f,c=0));else if(d(t)){var e=E.grabWhile(d);A(B("space",e,f,c))}else if(g&&y(t)&&T(n))E.skip(),E.skip(),A(B(_,n,f,c));else if(t===s){E.skip();var r=E.substrUntilChar(l),o=0===r.length||0<=r.indexOf(s);if(0<=p.indexOf(n)||o||E.isLast())A(B(_,t,f,c));else{var i=E.grabWhile(function(t){return t!==l});if(E.skip(),-1==i.indexOf(O)||i[0]===m)A(B("tag",i,f,c));else{var u=N(i);A(B("tag",u.tag,f,c)),u.attrs.map(A)}}}else if(t===l)E.skip(),A(B(_,t,f,c));else if(v(t))if(g&&y(t)&&!T(n))E.skip(),A(B(_,t,f,c));else{var a=E.grabWhile(function(t){return g?v(t)&&!y(t):v(t)});A(B(_,a,f,c))}};return{tokenize:function(){for(;E.hasNext();)t();return o.length=r+1,o},isTokenNested:function(t){var n=s+m+t.getValue();return-1<e.indexOf(n)}}}var E=function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=n,o=null,e=A(),u=A(),a=A(),s=A(),f={},c=function(){a.flushLast()&&s.flushLast()},l=function(t){var n;(n=u.getLast(),n?n.content:e.toArray()).push(t)},r=function(t){c();var n,e=h.create(t.getValue()),r=(void 0===f[(n=t).getValue()]&&(f[n.getValue()]=o.isTokenNested(n)),f[n.getValue()]);a.push(e),r?u.push(e):l(e)},g=function(t){t.isStart()&&r(t),t.isEnd()&&function(t){c();var n=u.flushLast();if(n)l(n);else if(i.onError){var e=t.getValue(),r=t.getLine(),o=t.getColumn();i.onError({message:"Inconsistent tag '"+e+"' on line "+r+" and column "+o,tagName:e,lineNumber:r,columnNumber:o})}}(t)},p=function(t){var n=a.getLast(),e=t.getValue(),r=!!f[t];if(n)if(t.isAttrName())s.push(e),n.attr(s.getLast(),"");else if(t.isAttrValue()){var o=s.getLast();o?(n.attr(o,e),s.flushLast()):n.attr(e,e)}else t.isText()?r?n.append(e):l(e):t.isTag()&&l(""+t);else t.isText()?l(e):t.isTag()&&l(""+t)};(o=(n.createTokenizer?n.createTokenizer:N)(t,{onToken:function(t){var n;!t.isTag()||(n=t.getName(),i.onlyAllowTags&&i.onlyAllowTags.length&&i.onlyAllowTags.indexOf(n)<0)?p(t):g(t)},onlyAllowTags:i.onlyAllowTags,openTag:i.openTag,closeTag:i.closeTag,enableEscapeTags:i.enableEscapeTags})).tokenize();return e.toArray()};t.default=E,t.parse=E,t.TagNode=i,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.BbobParser={})}(this,function(t){"use strict";function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function e(t,n){return t(n={exports:{}},n.exports),n.exports}var a=e(function(t,n){n.__esModule=!0;n.N="\n",n.F="\f",n.R="\r",n.TAB="\t",n.EQ="=",n.QUOTEMARK='"',n.SPACE=" ",n.OPEN_BRAKET="[",n.CLOSE_BRAKET="]",n.SLASH="/",n.PLACEHOLDER_SPACE_TAB=" ",n.PLACEHOLDER_SPACE=" ",n.BACKSLASH="\\"});n(a);var L=a.N,b=a.TAB,S=a.EQ,O=a.QUOTEMARK,x=a.SPACE,k=a.OPEN_BRAKET,C=a.CLOSE_BRAKET,m=a.SLASH,w=a.BACKSLASH,o=e(function(t,n){n.__esModule=!0,n.isEOL=n.isStringNode=n.isTagNode=n.getNodeLength=n.appendToNode=n.attrValue=n.attrsToString=void 0;var r=function(t){return"object"==typeof t&&!!t.tag},o=function(t){return"string"==typeof t},i=function(t){return t.replace(/"/g,"&quot;")},u=function(t,n){var e=typeof n,r={boolean:function(){return n?""+t:""},number:function(){return t+'="'+n+'"'},string:function(){return t+'="'+i(n)+'"'},object:function(){return t+'="'+i(JSON.stringify(n))+'"'}};return r[e]?r[e]():""};n.attrsToString=function(e){return void 0===e?"":Object.keys(e).reduce(function(t,n){return[].concat(t,[u(n,e[n])])},[""]).join(" ")},n.attrValue=u,n.appendToNode=function(t,n){t.content.push(n)},n.getNodeLength=function e(t){return r(t)?t.content.reduce(function(t,n){return t+e(n)},0):o(t)?t.length:0},n.isTagNode=r,n.isStringNode=o,n.isEOL=function(t){return t===a.N}});n(o);var r=e(function(t,n){n.__esModule=!0,n.TagNode=void 0;var e=function(){function r(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,n,e){return n&&r(t.prototype,n),e&&r(t,e),t}}();var r=function(){function r(t,n,e){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,r),this.tag=t.toLowerCase(),this.attrs=n,this.content=[].concat(e)}return r.prototype.attr=function(t,n){return void 0!==n&&(this.attrs[t]=n),this.attrs[t]},r.prototype.append=function(t){return(0,o.appendToNode)(this,t)},r.prototype.toString=function(){var t=a.OPEN_BRAKET,n=a.CLOSE_BRAKET;return t+this.tag+n+this.content.reduce(function(t,n){return t+""+n},"")+t+a.SLASH+this.tag+n},e(r,[{key:"length",get:function(){return(0,o.getNodeLength)(this)}}]),r}();r.create=function(t){return new r(t,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},2<arguments.length&&void 0!==arguments[2]?arguments[2]:[])},r.isOf=function(t,n){return t.tag===n},n.TagNode=r,n.default=r}),h=n(r),i=r.TagNode,u="type",s="value",f="line",c="word",l="attr-name",g="attr-value",p="space",d="new-line",v=function(t){return t[s]},T=function(t){return v(t).charCodeAt(0)==m.charCodeAt(0)},y=function(){function o(t,n,e,r){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,o),this[u]=t+"",this[s]=n+"",this[f]=+e,this.row=+r}return o.prototype.isEmpty=function(){return!!this[u]},o.prototype.isText=function(){return(t=this)[u]===p||t[u]===d||t[u]===c;var t},o.prototype.isTag=function(){return"tag"===this[u]},o.prototype.isAttrName=function(){return this[u]===l},o.prototype.isAttrValue=function(){return this[u]===g},o.prototype.isStart=function(){return!T(this)},o.prototype.isEnd=function(){return T(this)},o.prototype.getName=function(){return n=v(t=this),T(t)?n.slice(1):n;var t,n},o.prototype.getValue=function(){return v(this)},o.prototype.getLine=function(){return this[f]},o.prototype.getColumn=function(){return this.row},o.prototype.toString=function(){return t=k,t+=v(this),t+=C;var t},o}(),_=c,P=function(e,t){var r={pos:0,length:e.length},o=function(){r.pos+=1,t&&t.onSkip&&t.onSkip()},i=function(){return r.pos<r.length},u=function(){return e.substr(r.pos)},a=function(){return e[r.pos]};return{skip:o,hasNext:i,isLast:function(){return r.pos===r.length},grabWhile:function(t){var n=0;if(i())for(n=r.pos;i()&&t(a());)o();return e.substr(n,r.pos-n)},getNext:function(){return e[r.pos+1]},getPrev:function(){return e[r.pos-1]},getCurr:a,getRest:u,substrUntilChar:function(t){var n=u(),e=n.indexOf(t);return e<0?"":n.substr(0,e)}}},A=function(){var n=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];return{getLast:function(){return n.length?n[n.length-1]:null},flushLast:function(){return!!n.length&&n.pop()},push:function(t){return n.push(t)},toArray:function(){return n}}},B=function(t,n){return new y(t,n,2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,3<arguments.length&&void 0!==arguments[3]?arguments[3]:0)};function N(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},f=0,c=0,r=-1,o=Array(Math.floor(e.length)),s=n.openTag||k,l=n.closeTag||C,g=n.enableEscapeTags,p=[l,s,O,w,x,b,S,L,"!"],i=[s,x,b,L],u=[x,b],h=[S,x,b],d=function(t){return 0<=u.indexOf(t)},v=function(t){return-1==i.indexOf(t)},T=function(t){return t===s||t===l||t===w},y=function(t){return t===w},A=function(t){n.onToken&&n.onToken(t),o[r+=1]=t},N=function(t){for(var u=null,a=!1,r=[],s=P(t),o=function(t){var n=t===S,e=d(t),r=s.getPrev(),o=s.getNext(),i=r===w;return null===u?!1===(n||e||s.isLast()):!(!a||h.indexOf(t)<0)||!!(t!==O||i||(a=!a)||o===S||d(o))&&!1===(n||e)},n=function(){var t=s.grabWhile(o),n=s.getCurr();if(null===u)u=t;else if(d(n)||n===O||!s.hasNext()){var e=function(t,n){for(;t.charAt(0)===n;)t=t.substring(1);for(;t.charAt(t.length-1)===n;)t=t.substring(0,t.length-1);return t}(t,O).replace(w+O,O);r.push(B("attr-value",e,f,c))}else r.push(B("attr-name",t,f,c));s.skip()};s.hasNext();)n();return{tag:u,attrs:r}},E=P(e,{onSkip:function(){c++}}),t=function(){var t=E.getCurr(),n=E.getNext();if(t===L)E.skip(),A(B("new-line",t,++f,c=0));else if(d(t)){var e=E.grabWhile(d);A(B("space",e,f,c))}else if(g&&y(t)&&T(n))E.skip(),E.skip(),A(B(_,n,f,c));else if(t===s){E.skip();var r=E.substrUntilChar(l),o=0===r.length||0<=r.indexOf(s);if(0<=p.indexOf(n)||o||E.isLast())A(B(_,t,f,c));else{var i=E.grabWhile(function(t){return t!==l});if(E.skip(),-1==i.indexOf(S)||i[0]===m)A(B("tag",i,f,c));else{var u=N(i);A(B("tag",u.tag,f,c)),u.attrs.map(A)}}}else if(t===l)E.skip(),A(B(_,t,f,c));else if(v(t))if(g&&y(t)&&!T(n))E.skip(),A(B(_,t,f,c));else{var a=E.grabWhile(function(t){return g?v(t)&&!y(t):v(t)});A(B(_,a,f,c))}};return{tokenize:function(){for(;E.hasNext();)t();return o.length=r+1,o},isTokenNested:function(t){var n=s+m+t.getValue();return-1<e.indexOf(n)}}}var E=function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=n,o=null,e=A(),u=A(),a=A(),s=A(),f={},c=function(){a.flushLast()&&s.flushLast()},l=function(t){var n;(n=u.getLast(),n?n.content:e.toArray()).push(t)},r=function(t){c();var n,e=h.create(t.getValue()),r=(void 0===f[(n=t).getValue()]&&(f[n.getValue()]=o.isTokenNested(n)),f[n.getValue()]);a.push(e),r?u.push(e):l(e)},g=function(t){t.isStart()&&r(t),t.isEnd()&&function(t){c();var n=u.flushLast();if(n)l(n);else if(i.onError){var e=t.getValue(),r=t.getLine(),o=t.getColumn();i.onError({message:"Inconsistent tag '"+e+"' on line "+r+" and column "+o,tagName:e,lineNumber:r,columnNumber:o})}}(t)},p=function(t){var n=a.getLast(),e=t.getValue(),r=!!f[t];if(n)if(t.isAttrName())s.push(e),n.attr(s.getLast(),"");else if(t.isAttrValue()){var o=s.getLast();o?(n.attr(o,e),s.flushLast()):n.attr(e,e)}else t.isText()?r?n.append(e):l(e):t.isTag()&&l(""+t);else t.isText()?l(e):t.isTag()&&l(""+t)};(o=(n.createTokenizer?n.createTokenizer:N)(t,{onToken:function(t){var n;!t.isTag()||(n=t.getName(),i.onlyAllowTags&&i.onlyAllowTags.length&&i.onlyAllowTags.indexOf(n)<0)?p(t):g(t)},onlyAllowTags:i.onlyAllowTags,openTag:i.openTag,closeTag:i.closeTag,enableEscapeTags:i.enableEscapeTags})).tokenize();return e.toArray()};t.default=E,t.parse=E,t.TagNode=i,Object.defineProperty(t,"__esModule",{value:!0})});

@@ -14,26 +14,28 @@ import { QUOTEMARK, BACKSLASH } from '@bbob/plugin-helper/lib/char';

* @param {String} source
* @param {Function} onSkip
* @param {Object} options
* @param {Function} options.onSkip
* @returns
*/
export var createCharGrabber = function createCharGrabber(source) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
onSkip = _ref.onSkip;
export var createCharGrabber = function createCharGrabber(source, options) {
// let idx = 0;
var cursor = {
pos: 0,
length: source.length
};
var idx = 0;
var skip = function skip() {
idx += 1;
cursor.pos += 1;
if (onSkip) {
onSkip();
if (options && options.onSkip) {
options.onSkip();
}
};
var hasNext = function hasNext() {
return source.length > idx;
return cursor.length > cursor.pos;
};
var getRest = function getRest() {
return source.substr(idx);
return source.substr(cursor.pos);
};
var getCurr = function getCurr() {
return source[idx];
return source[cursor.pos];
};

@@ -45,18 +47,26 @@

isLast: function isLast() {
return idx === source.length;
return cursor.pos === cursor.length;
},
/**
* @param {Function} cond
* @returns {string}
*/
grabWhile: function grabWhile(cond) {
var start = idx;
var start = 0;
while (hasNext() && cond(getCurr())) {
skip();
if (hasNext()) {
start = cursor.pos;
while (hasNext() && cond(getCurr())) {
skip();
}
}
return source.substr(start, idx - start);
return source.substr(start, cursor.pos - start);
},
getNext: function getNext() {
return source[idx + 1];
return source[cursor.pos + 1];
},
getPrev: function getPrev() {
return source[idx - 1];
return source[cursor.pos - 1];
},

@@ -63,0 +73,0 @@ getCurr: getCurr,

@@ -19,26 +19,28 @@ 'use strict';

* @param {String} source
* @param {Function} onSkip
* @param {Object} options
* @param {Function} options.onSkip
* @returns
*/
var createCharGrabber = exports.createCharGrabber = function createCharGrabber(source) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
onSkip = _ref.onSkip;
var createCharGrabber = exports.createCharGrabber = function createCharGrabber(source, options) {
// let idx = 0;
var cursor = {
pos: 0,
length: source.length
};
var idx = 0;
var skip = function skip() {
idx += 1;
cursor.pos += 1;
if (onSkip) {
onSkip();
if (options && options.onSkip) {
options.onSkip();
}
};
var hasNext = function hasNext() {
return source.length > idx;
return cursor.length > cursor.pos;
};
var getRest = function getRest() {
return source.substr(idx);
return source.substr(cursor.pos);
};
var getCurr = function getCurr() {
return source[idx];
return source[cursor.pos];
};

@@ -50,18 +52,26 @@

isLast: function isLast() {
return idx === source.length;
return cursor.pos === cursor.length;
},
/**
* @param {Function} cond
* @returns {string}
*/
grabWhile: function grabWhile(cond) {
var start = idx;
var start = 0;
while (hasNext() && cond(getCurr())) {
skip();
if (hasNext()) {
start = cursor.pos;
while (hasNext() && cond(getCurr())) {
skip();
}
}
return source.substr(start, idx - start);
return source.substr(start, cursor.pos - start);
},
getNext: function getNext() {
return source[idx + 1];
return source[cursor.pos + 1];
},
getPrev: function getPrev() {
return source[idx - 1];
return source[cursor.pos - 1];
},

@@ -68,0 +78,0 @@ getCurr: getCurr,

{
"name": "@bbob/parser",
"version": "2.5.3",
"version": "2.5.4",
"description": "Just parses BBcode to AST array. Part of @bbob bbcode parser",

@@ -16,3 +16,3 @@ "keywords": [

"dependencies": {
"@bbob/plugin-helper": "^2.5.3"
"@bbob/plugin-helper": "^2.5.4"
},

@@ -19,0 +19,0 @@ "main": "lib/index.js",

@@ -17,18 +17,23 @@ import {

* @param {String} source
* @param {Function} onSkip
* @param {Object} options
* @param {Function} options.onSkip
* @returns
*/
export const createCharGrabber = (source, { onSkip } = {}) => {
let idx = 0;
export const createCharGrabber = (source, options) => {
// let idx = 0;
const cursor = {
pos: 0,
length: source.length,
};
const skip = () => {
idx += 1;
cursor.pos += 1;
if (onSkip) {
onSkip();
if (options && options.onSkip) {
options.onSkip();
}
};
const hasNext = () => source.length > idx;
const getRest = () => source.substr(idx);
const getCurr = () => source[idx];
const hasNext = () => cursor.length > cursor.pos;
const getRest = () => source.substr(cursor.pos);
const getCurr = () => source[cursor.pos];

@@ -38,14 +43,22 @@ return {

hasNext,
isLast: () => (idx === source.length),
isLast: () => (cursor.pos === cursor.length),
/**
* @param {Function} cond
* @returns {string}
*/
grabWhile: (cond) => {
const start = idx;
let start = 0;
while (hasNext() && cond(getCurr())) {
skip();
if (hasNext()) {
start = cursor.pos;
while (hasNext() && cond(getCurr())) {
skip();
}
}
return source.substr(start, idx - start);
return source.substr(start, cursor.pos - start);
},
getNext: () => source[idx + 1],
getPrev: () => source[idx - 1],
getNext: () => source[cursor.pos + 1],
getPrev: () => source[cursor.pos - 1],
getCurr,

@@ -52,0 +65,0 @@ getRest,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc