Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bbob/html

Package Overview
Dependencies
Maintainers
0
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bbob/html - npm Package Compare versions

Comparing version 4.0.3 to 4.1.0

86

dist/index.js

@@ -137,2 +137,8 @@ (function (global, factory) {

}
setStart(value) {
this.start = value;
}
setEnd(value) {
this.end = value;
}
get length() {

@@ -149,3 +155,10 @@ return getNodeLength(this);

toTagNode() {
return new TagNode(String(this.tag).toLowerCase(), this.attrs, this.content);
const newNode = new TagNode(String(this.tag).toLowerCase(), this.attrs, this.content);
if (this.start) {
newNode.setStart(this.start);
}
if (this.end) {
newNode.setEnd(this.end);
}
return newNode;
}

@@ -166,4 +179,8 @@ toString({ openTag = OPEN_BRAKET, closeTag = CLOSE_BRAKET } = {}) {

}
static create(tag, attrs = {}, content = null) {
return new TagNode(tag, attrs, content);
static create(tag, attrs = {}, content = null, start) {
const node = new TagNode(tag, attrs, content);
if (start) {
node.setStart(start);
}
return node;
}

@@ -180,3 +197,3 @@ static isOf(node, type) {

// type, value, line, row,
// type, value, line, row, start pos, end pos
const TOKEN_TYPE_ID = 't'; // 0;

@@ -186,2 +203,4 @@ const TOKEN_VALUE_ID = 'v'; // 1;

const TOKEN_LINE_ID = 'l'; // 3;
const TOKEN_START_POS_ID = 's'; // 4;
const TOKEN_END_POS_ID = 'e'; // 5;
const TOKEN_TYPE_WORD = 1; // 'word';

@@ -201,2 +220,4 @@ const TOKEN_TYPE_TAG = 2; // 'tag';

const getTokenColumn = (token)=>token && token[TOKEN_COLUMN_ID] || 0;
const getStartPosition = (token)=>token && token[TOKEN_START_POS_ID] || 0;
const getEndPosition = (token)=>token && token[TOKEN_END_POS_ID] || 0;
const isTextToken = (token)=>{

@@ -278,6 +299,12 @@ if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {

}
getStart() {
return getStartPosition(this);
}
getEnd() {
return getEndPosition(this);
}
toString() {
return tokenToText(this);
}
constructor(type, value, row = 0, col = 0){
constructor(type, value, row = 0, col = 0, start = 0, end = 0){
this[TOKEN_LINE_ID] = row;

@@ -287,2 +314,4 @@ this[TOKEN_COLUMN_ID] = col;

this[TOKEN_VALUE_ID] = String(value);
this[TOKEN_START_POS_ID] = start;
this[TOKEN_END_POS_ID] = end;
}

@@ -313,2 +342,8 @@ }

}
getPos() {
return this.c.pos;
}
getLength() {
return this.c.len;
}
getRest() {

@@ -387,4 +422,4 @@ return this.s.substring(this.c.pos);

const EM = '!';
function createTokenOfType(type, value, r = 0, cl = 0) {
return new Token(type, value, r, cl);
function createTokenOfType(type, value, r = 0, cl = 0, p = 0, e = 0) {
return new Token(type, value, r, cl, p, e);
}

@@ -406,2 +441,3 @@ const STATE_WORD = 0;

];
const END_POS_OFFSET = 2; // length + start position offset
const isWhiteSpace = (char)=>WHITESPACES.indexOf(char) >= 0;

@@ -414,2 +450,3 @@ const isEscapeChar = (char)=>char === BACKSLASH;

let row = 0;
let prevCol = 0;
let col = 0;

@@ -465,9 +502,10 @@ let tokenIndex = -1;

* @param {String} value
*/ function emitToken(type, value) {
const token = createTokenOfType(type, value, row, col);
*/ function emitToken(type, value, startPos, endPos) {
const token = createTokenOfType(type, value, row, prevCol, startPos, endPos);
onToken(token);
prevCol = col;
tokenIndex += 1;
tokens[tokenIndex] = token;
}
function nextTagState(tagChars, isSingleValueTag) {
function nextTagState(tagChars, isSingleValueTag, masterStartPos) {
if (tagMode === TAG_STATE_ATTR) {

@@ -522,2 +560,5 @@ const validAttrName = (char)=>!(char === EQ || isWhiteSpace(char));

emitToken(TYPE_ATTR_VALUE, unq(name));
if (tagChars.getPrev() === QUOTEMARK) {
prevCol++;
}
if (tagChars.isLast()) {

@@ -528,7 +569,9 @@ return TAG_STATE_NAME;

}
const start = masterStartPos + tagChars.getPos() - 1;
const validName = (char)=>!(char === EQ || isWhiteSpace(char) || tagChars.isLast());
const name = tagChars.grabWhile(validName);
emitToken(TYPE_TAG, name);
emitToken(TYPE_TAG, name, start, masterStartPos + tagChars.getLength() + 1);
checkContextFreeMode(name);
tagChars.skip();
prevCol++;
// in cases when we has [url=someval]GET[/url] and we dont need to parse all

@@ -557,5 +600,7 @@ if (isSingleValueTag) {

if (isNoAttrsInTag || isClosingTag) {
const startPos = chars.getPos() - 1;
const name = chars.grabWhile((char)=>char !== closeTag);
const endPos = startPos + name.length + END_POS_OFFSET;
chars.skip(); // skip closeTag
emitToken(TYPE_TAG, name);
emitToken(TYPE_TAG, name, startPos, endPos);
checkContextFreeMode(name, isClosingTag);

@@ -567,2 +612,3 @@ return STATE_WORD;

function stateAttrs() {
const startPos = chars.getPos();
const silent = true;

@@ -576,3 +622,3 @@ const tagStr = chars.grabWhile((char)=>char !== closeTag, silent);

while(tagGrabber.hasNext()){
tagMode = nextTagState(tagGrabber, !hasSpace);
tagMode = nextTagState(tagGrabber, !hasSpace, startPos);
}

@@ -587,2 +633,3 @@ chars.skip(); // skip closeTag

col = 0;
prevCol = 0;
row++;

@@ -610,2 +657,3 @@ return STATE_WORD;

chars.skip();
prevCol++;
return STATE_WORD;

@@ -799,3 +847,6 @@ }

flushTagNodes();
const tagNode = TagNode.create(token.getValue(), {}, []);
const tagNode = TagNode.create(token.getValue(), {}, [], {
from: token.getStart(),
to: token.getEnd()
});
const isNested = isTokenNested(token);

@@ -814,2 +865,9 @@ tagNodes.push(tagNode);

*/ function handleTagEnd(token) {
const lastTagNode = nestedNodes.last();
if (isTagNode(lastTagNode)) {
lastTagNode.setEnd({
from: token.getStart(),
to: token.getEnd()
});
}
flushTagNodes();

@@ -816,0 +874,0 @@ const lastNestedNode = nestedNodes.flush();

2

dist/index.min.js

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).BbobHtml={})}(this,function(t){"use strict";function e(t){return"object"==typeof t&&null!==t&&"tag"in t}function r(t,e,r){return Object.keys(t).reduce((r,n)=>e(r,n,t),r)}function n(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/(javascript|data|vbscript):/gi,"$1%3A")}function s(t,e){switch(typeof e){case"boolean":return e?""+t:"";case"number":return`${t}="${e}"`;case"string":return`${t}="${n(e)}"`;case"object":return`${t}="${n(JSON.stringify(e))}"`;default:return""}}function i(t){return null==t?"":r(t,(t,e,r)=>[...t,s(e,r[e])],[""]).join(" ")}let u=(t,e)=>{let n=r(e||{},(t,e,r)=>r[e]===e?r[e]:null,null);if(n){let r=s(t,n),u={...e};delete u[n+""];let o=i(u);return`${r}${o}`}return`${t}${i(e)}`},o=(t,r,n)=>{let s=t=>e(t)?t.toString({openTag:r,closeTag:n}):t+"";return Array.isArray(t)?t.reduce((t,e)=>null!==e?t+s(e):t,""):t?s(t):null};class l{attr(t,e){return void 0!==e&&(this.attrs[t]=e),this.attrs[t]}append(t){Array.isArray(this.content)&&this.content.push(t)}get length(){return function t(r){return e(r)&&Array.isArray(r.content)?r.content.reduce((e,r)=>e+t(r),0):"string"==typeof r?(r+"").length:0}(this)}toTagStart({openTag:t="[",closeTag:e="]"}={}){let r=u(this.tag+"",this.attrs);return`${t}${r}${e}`}toTagEnd({openTag:t="[",closeTag:e="]"}={}){return`${t}/${this.tag}${e}`}toTagNode(){return new l((this.tag+"").toLowerCase(),this.attrs,this.content)}toString({openTag:t="[",closeTag:e="]"}={}){let r=this.content?o(this.content,t,e):"",n=this.toTagStart({openTag:t,closeTag:e});return null===this.content||Array.isArray(this.content)&&0===this.content.length?n:`${n}${r}${this.toTagEnd({openTag:t,closeTag:e})}`}static create(t,e={},r=null){return new l(t,e,r)}static isOf(t,e){return t.tag===e}constructor(t,e,r){this.tag=t,this.attrs=e,this.content=r}}let a=t=>t&&void 0!==t.v?t.v:"",h=t=>t&&t.l||0,c=t=>t&&t.r||0,f=t=>!!t&&void 0!==t.t&&(5===t.t||6===t.t||1===t.t),g=t=>!!t&&void 0!==t.t&&2===t.t,p=t=>47===a(t).charCodeAt(0),d=t=>!p(t),y=t=>!!t&&void 0!==t.t&&3===t.t,A=t=>!!t&&void 0!==t.t&&4===t.t,b=t=>{let e=a(t);return p(t)?e.slice(1):e},T=t=>"["+a(t)+"]";class k{get type(){return this.t}isEmpty(){return 0===this.t||isNaN(this.t)}isText(){return f(this)}isTag(){return g(this)}isAttrName(){return y(this)}isAttrValue(){return A(this)}isStart(){return d(this)}isEnd(){return p(this)}getName(){return b(this)}getValue(){return a(this)}getLine(){return h(this)}getColumn(){return c(this)}toString(){return T(this)}constructor(t,e,r=0,n=0){this.l=r,this.r=n,this.t=t||0,this.v=e+""}}class x{skip(t=1,e){this.c.pos+=t,this.o&&this.o.onSkip&&!e&&this.o.onSkip()}hasNext(){return this.c.len>this.c.pos}getCurr(){return void 0===this.s[this.c.pos]?"":this.s[this.c.pos]}getRest(){return this.s.substring(this.c.pos)}getNext(){let t=this.c.pos+1;return t<=this.s.length-1?this.s[t]:null}getPrev(){let t=this.c.pos-1;return void 0===this.s[t]?null:this.s[t]}isLast(){return this.c.pos===this.c.len}includes(t){return this.s.indexOf(t,this.c.pos)>=0}grabWhile(t,e){let r=0;if(this.hasNext())for(r=this.c.pos;this.hasNext()&&t(this.getCurr());)this.skip(1,e);return this.s.substring(r,this.c.pos)}grabN(t=0){return this.s.substring(this.c.pos,this.c.pos+t)}substrUntilChar(t){let{pos:e}=this.c,r=this.s.indexOf(t,e);return r>=0?this.s.substring(e,r):""}constructor(t,e={}){this.s=t,this.c={pos:0,len:t.length},this.o=e}}let m=(t,e)=>new x(t,e),v=(t,e)=>{for(;t.charAt(0)===e;)t=t.substring(1);for(;t.charAt(t.length-1)===e;)t=t.substring(0,t.length-1);return t},C=t=>t.replace('\\"','"'),N=[" "," "],$=["="," "," "],w=t=>N.indexOf(t)>=0,O=t=>"\\"===t,S=t=>$.indexOf(t)>=0,E=t=>"\n"===t,L=t=>C(v(t,'"'));class j{last(){return Array.isArray(this.n)&&this.n.length>0&&void 0!==this.n[this.n.length-1]?this.n[this.n.length-1]:null}flush(){return!!this.n.length&&this.n.pop()}push(t){this.n.push(t)}toArray(){return this.n}constructor(){this.n=[]}}let W=()=>new j;function V(t,r={}){var n;let s=r.openTag||"[",i=r.closeTag||"]",u=(r.onlyAllowTags||[]).filter(Boolean).map(t=>t.toLowerCase()),o=null,a=W(),h=W(),c=W(),f=W(),g=new Set;function p(){c.flush()&&f.flush()}function d(){let t=h.last();return t&&e(t)?t.content:a.toArray()}function y(t,e,r=!0){Array.isArray(t)&&void 0!==e&&(t.push(e.toTagStart({openTag:s,closeTag:i})),Array.isArray(e.content)&&e.content.length&&(e.content.forEach(e=>{t.push(e)}),r&&t.push(e.toTagEnd({openTag:s,closeTag:i}))))}function A(t,r){if(Array.isArray(t)&&void 0!==r){if(e(r)){var n;(n=r.tag,!u.length||u.indexOf(n.toLowerCase())>=0)?t.push(r.toTagNode()):y(t,r)}else t.push(r)}}(o=(r.createTokenizer?r.createTokenizer:function(t,e={}){let r=0,n=0,s=-1,i=0,u=0,o="",l=Array(Math.floor(t.length)),a=e.openTag||"[",h=e.closeTag||"]",c=!!e.enableEscapeTags,f=(e.contextFreeTags||[]).filter(Boolean).map(t=>t.toLowerCase()),g=new Map,p=e.onToken||(()=>{}),d=[h,a,'"',"\\"," "," ","=","\n","!"],y=[a," "," ","\n"],A=t=>d.indexOf(t)>=0,b=t=>-1===y.indexOf(t),T=t=>t===a||t===h||"\\"===t,x=()=>{n++},v=(t,e)=>{""!==o&&e&&(o=""),""===o&&f.includes(t.toLowerCase())&&(o=t)},C=m(t,{onSkip:x});function N(t,e){let i=function(t,e,r=0,n=0){return new k(t,e,r,n)}(t,e,r,n);p(i),l[s+=1]=i}return{tokenize:function(){for(i=0;C.hasNext();)switch(i){case 1:i=function(){let t=C.getCurr(),e=C.getNext();C.skip();let r=C.substrUntilChar(h),n=0===r.length||r.indexOf(a)>=0;if(e&&A(e)||n||C.isLast())return N(1,t),0;let s=-1===r.indexOf("="),i="/"===r[0];if(s||i){let t=C.grabWhile(t=>t!==h);return C.skip(),N(2,t),v(t,i),0}return 2}();break;case 2:i=function(){let t=m(C.grabWhile(t=>t!==h,!0),{onSkip:x}),e=t.includes(" ");for(u=0;t.hasNext();)u=function(t,e){if(1===u){let e=t.grabWhile(t=>!("="===t||w(t))),r=t.isLast(),n="="!==t.getCurr();return(t.skip(),r||n?N(4,L(e)):N(3,e),r)?0:n?1:2}if(2===u){let r=!1,n=t.grabWhile(n=>{let s='"'===n,i=t.getPrev(),u=t.getNext(),o="="===u,l=w(n),a=u&&w(u);return!!(r&&S(n))||(!s||"\\"===i||!!(r=!r)||!!o||!!a)&&(!!e||!l)});return(t.skip(),N(4,L(n)),t.isLast())?0:1}let r=t.grabWhile(e=>!("="===e||w(e)||t.isLast()));return(N(2,r),v(r),t.skip(),e)?2:t.includes("=")?1:2}(t,!e);return C.skip(),0}();break;default:i=function(){if(E(C.getCurr()))return N(6,C.getCurr()),C.skip(),n=0,r++,0;if(w(C.getCurr()))return N(5,C.grabWhile(w)),0;if(C.getCurr()===a){if(o){let t=a.length+1+o.length,e=`${a}/${o}`;if(C.grabN(t)===e)return 1}else if(C.includes(h))return 1;return N(1,C.getCurr()),C.skip(),0}if(c){if(O(C.getCurr())){let t=C.getCurr(),e=C.getNext();return(C.skip(),e&&T(e))?(C.skip(),N(1,e)):N(1,t),0}return N(1,C.grabWhile(t=>b(t)&&!O(t))),0}return N(1,C.grabWhile(b)),0}()}return l.length=s+1,l},isTokenNested:function(e){let r=a+"/"+e.getValue();if(g.has(r))return!!g.get(r);{let e=t.indexOf(r)>-1;return g.set(r,e),e}}}})(t,{onToken:function(t){t.isTag()?(t.isStart()&&function(t){p();let e=l.create(t.getValue(),{},[]),r=function(t){let e=t.getValue(),{isTokenNested:r}=o||{};return!g.has(e)&&r&&r(t)?(g.add(e),!0):g.has(e)}(t);c.push(e),r?h.push(e):A(d(),e)}(t),t.isEnd()&&function(t){p();let e=h.flush();if(e)A(d(),e);else if("function"==typeof r.onError){let e=t.getValue(),n=t.getLine(),s=t.getColumn();r.onError({tagName:e,lineNumber:n,columnNumber:s})}}(t)):!function(t){var e;let r=c.last(),n=t.getValue(),s=(e=t.toString(),!!g.has(e)),i=d();if(null!==r){if(t.isAttrName()){f.push(n);let t=f.last();t&&r.attr(t,"")}else if(t.isAttrValue()){let t=f.last();t?(r.attr(t,n),f.flush()):r.attr(n,n)}else t.isText()?s?r.append(n):A(i,n):t.isTag()&&A(i,t.toString())}else t.isText()?A(i,n):t.isTag()&&A(i,t.toString())}(t)},openTag:s,closeTag:i,onlyAllowTags:r.onlyAllowTags,contextFreeTags:r.contextFreeTags,enableEscapeTags:r.enableEscapeTags})).tokenize();let b=h.flush();return null!==b&&b&&e(b)&&(n=b.tag,g.has(n))&&y(d(),b,!1),a.toArray()}let P=t=>"object"==typeof t&&null!==t,z=t=>"boolean"==typeof t;function B(t,e){if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]=B(e(t[r]),e);else P(t)&&"content"in t&&B(t.content,e);return t}function F(t,e){return typeof t==typeof e&&(P(t)&&null!==t?Array.isArray(t)?t.every(t=>[].some.call(e,e=>F(t,e))):!!(P(t)&&P(e))&&Object.keys(t).every(r=>{let n=e[r],s=t[r];return P(s)&&P(n)?F(s,n):z(s)?s!==(null===n):n===s}):t===e)}function M(t,e){return t.messages=[...t.messages||[]],t.options={...e,...t.options},t.walk=function(t){return B(this,t)},t.match=function(t,e){return Array.isArray(t)?B(this,r=>{for(let n=0;n<t.length;n++)if(F(t[n],r))return e(r);return r}):B(this,r=>F(t,r)?e(r):r)},t}function U(t,r){let{stripTags:n=!1}=r||{};if(null==t)return"";if("string"==typeof t||"number"==typeof t)return t+"";if(Array.isArray(t))return _(t,r);if(e(t)){if(n)return _(t.content,r);let e=i(t.attrs);return null===t.content?"<"+t.tag+e+"/>":"<"+t.tag+e+">"+_(t.content,r)+"</"+t.tag+">"}return""}function _(t,e){return t&&Array.isArray(t)?t.reduce((t,r)=>t+U(r,e),""):t?U(t,e):""}function q(t,e,r){return(function(t){let e="function"==typeof t?[t]:t||[],r=()=>"";return{process(t,n){let s=n||{skipParse:!1,parser:V,render:r,data:null},i=s.parser||V,u=s.render,o=s.data||null;if("function"!=typeof i)throw Error("C1");let l=s.skipParse&&Array.isArray(t)?t:i(t,s),a=s.skipParse&&Array.isArray(t)?M(t||[],s):M(l,s);for(let t=0;t<e.length;t++){let r=e[t];"function"==typeof r&&u&&(a=M(r(a,{parse:i,render:u,iterate:B,data:o})||a,s))}return{get html(){if("function"!=typeof u)throw Error("C2");return u(a,a.options)},tree:a,raw:l,messages:a.messages}}}})(e).process(t,{...r,render:_}).html}t.default=q,t.html=q,t.render=_,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).BbobHtml={})}(this,function(t){"use strict";function e(t){return"object"==typeof t&&null!==t&&"tag"in t}function r(t,e,r){return Object.keys(t).reduce((r,n)=>e(r,n,t),r)}function n(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/(javascript|data|vbscript):/gi,"$1%3A")}function s(t,e){switch(typeof e){case"boolean":return e?""+t:"";case"number":return`${t}="${e}"`;case"string":return`${t}="${n(e)}"`;case"object":return`${t}="${n(JSON.stringify(e))}"`;default:return""}}function i(t){return null==t?"":r(t,(t,e,r)=>[...t,s(e,r[e])],[""]).join(" ")}let o=(t,e)=>{let n=r(e||{},(t,e,r)=>r[e]===e?r[e]:null,null);if(n){let r=s(t,n),o={...e};delete o[n+""];let u=i(o);return`${r}${u}`}return`${t}${i(e)}`},u=(t,r,n)=>{let s=t=>e(t)?t.toString({openTag:r,closeTag:n}):t+"";return Array.isArray(t)?t.reduce((t,e)=>null!==e?t+s(e):t,""):t?s(t):null};class a{attr(t,e){return void 0!==e&&(this.attrs[t]=e),this.attrs[t]}append(t){Array.isArray(this.content)&&this.content.push(t)}setStart(t){this.start=t}setEnd(t){this.end=t}get length(){return function t(r){return e(r)&&Array.isArray(r.content)?r.content.reduce((e,r)=>e+t(r),0):"string"==typeof r?(r+"").length:0}(this)}toTagStart({openTag:t="[",closeTag:e="]"}={}){let r=o(this.tag+"",this.attrs);return`${t}${r}${e}`}toTagEnd({openTag:t="[",closeTag:e="]"}={}){return`${t}/${this.tag}${e}`}toTagNode(){let t=new a((this.tag+"").toLowerCase(),this.attrs,this.content);return this.start&&t.setStart(this.start),this.end&&t.setEnd(this.end),t}toString({openTag:t="[",closeTag:e="]"}={}){let r=this.content?u(this.content,t,e):"",n=this.toTagStart({openTag:t,closeTag:e});return null===this.content||Array.isArray(this.content)&&0===this.content.length?n:`${n}${r}${this.toTagEnd({openTag:t,closeTag:e})}`}static create(t,e={},r=null,n){let s=new a(t,e,r);return n&&s.setStart(n),s}static isOf(t,e){return t.tag===e}constructor(t,e,r){this.tag=t,this.attrs=e,this.content=r}}let l=t=>t&&void 0!==t.v?t.v:"",h=t=>t&&t.l||0,c=t=>t&&t.r||0,g=t=>t&&t.s||0,f=t=>t&&t.e||0,p=t=>!!t&&void 0!==t.t&&(5===t.t||6===t.t||1===t.t),d=t=>!!t&&void 0!==t.t&&2===t.t,y=t=>47===l(t).charCodeAt(0),A=t=>!y(t),b=t=>!!t&&void 0!==t.t&&3===t.t,T=t=>!!t&&void 0!==t.t&&4===t.t,k=t=>{let e=l(t);return y(t)?e.slice(1):e},m=t=>"["+l(t)+"]";class x{get type(){return this.t}isEmpty(){return 0===this.t||isNaN(this.t)}isText(){return p(this)}isTag(){return d(this)}isAttrName(){return b(this)}isAttrValue(){return T(this)}isStart(){return A(this)}isEnd(){return y(this)}getName(){return k(this)}getValue(){return l(this)}getLine(){return h(this)}getColumn(){return c(this)}getStart(){return g(this)}getEnd(){return f(this)}toString(){return m(this)}constructor(t,e,r=0,n=0,s=0,i=0){this.l=r,this.r=n,this.t=t||0,this.v=e+"",this.s=s,this.e=i}}class v{skip(t=1,e){this.c.pos+=t,this.o&&this.o.onSkip&&!e&&this.o.onSkip()}hasNext(){return this.c.len>this.c.pos}getCurr(){return void 0===this.s[this.c.pos]?"":this.s[this.c.pos]}getPos(){return this.c.pos}getLength(){return this.c.len}getRest(){return this.s.substring(this.c.pos)}getNext(){let t=this.c.pos+1;return t<=this.s.length-1?this.s[t]:null}getPrev(){let t=this.c.pos-1;return void 0===this.s[t]?null:this.s[t]}isLast(){return this.c.pos===this.c.len}includes(t){return this.s.indexOf(t,this.c.pos)>=0}grabWhile(t,e){let r=0;if(this.hasNext())for(r=this.c.pos;this.hasNext()&&t(this.getCurr());)this.skip(1,e);return this.s.substring(r,this.c.pos)}grabN(t=0){return this.s.substring(this.c.pos,this.c.pos+t)}substrUntilChar(t){let{pos:e}=this.c,r=this.s.indexOf(t,e);return r>=0?this.s.substring(e,r):""}constructor(t,e={}){this.s=t,this.c={pos:0,len:t.length},this.o=e}}let C=(t,e)=>new v(t,e),N=(t,e)=>{for(;t.charAt(0)===e;)t=t.substring(1);for(;t.charAt(t.length-1)===e;)t=t.substring(0,t.length-1);return t},$=t=>t.replace('\\"','"'),S=[" "," "],w=["="," "," "],E=t=>S.indexOf(t)>=0,O=t=>"\\"===t,L=t=>w.indexOf(t)>=0,P=t=>"\n"===t,j=t=>$(N(t,'"'));class W{last(){return Array.isArray(this.n)&&this.n.length>0&&void 0!==this.n[this.n.length-1]?this.n[this.n.length-1]:null}flush(){return!!this.n.length&&this.n.pop()}push(t){this.n.push(t)}toArray(){return this.n}constructor(){this.n=[]}}let V=()=>new W;function z(t,r={}){var n;let s=r.openTag||"[",i=r.closeTag||"]",o=(r.onlyAllowTags||[]).filter(Boolean).map(t=>t.toLowerCase()),u=null,l=V(),h=V(),c=V(),g=V(),f=new Set;function p(){c.flush()&&g.flush()}function d(){let t=h.last();return t&&e(t)?t.content:l.toArray()}function y(t,e,r=!0){Array.isArray(t)&&void 0!==e&&(t.push(e.toTagStart({openTag:s,closeTag:i})),Array.isArray(e.content)&&e.content.length&&(e.content.forEach(e=>{t.push(e)}),r&&t.push(e.toTagEnd({openTag:s,closeTag:i}))))}function A(t,r){if(Array.isArray(t)&&void 0!==r){if(e(r)){var n;(n=r.tag,!o.length||o.indexOf(n.toLowerCase())>=0)?t.push(r.toTagNode()):y(t,r)}else t.push(r)}}(u=(r.createTokenizer?r.createTokenizer:function(t,e={}){let r=0,n=0,s=0,i=-1,o=0,u=0,a="",l=Array(Math.floor(t.length)),h=e.openTag||"[",c=e.closeTag||"]",g=!!e.enableEscapeTags,f=(e.contextFreeTags||[]).filter(Boolean).map(t=>t.toLowerCase()),p=new Map,d=e.onToken||(()=>{}),y=[c,h,'"',"\\"," "," ","=","\n","!"],A=[h," "," ","\n"],b=t=>y.indexOf(t)>=0,T=t=>-1===A.indexOf(t),k=t=>t===h||t===c||"\\"===t,m=()=>{s++},v=(t,e)=>{""!==a&&e&&(a=""),""===a&&f.includes(t.toLowerCase())&&(a=t)},N=C(t,{onSkip:m});function $(t,e,o,u){let a=function(t,e,r=0,n=0,s=0,i=0){return new x(t,e,r,n,s,i)}(t,e,r,n,o,u);d(a),n=s,l[i+=1]=a}return{tokenize:function(){for(o=0;N.hasNext();)switch(o){case 1:o=function(){let t=N.getCurr(),e=N.getNext();N.skip();let r=N.substrUntilChar(c),n=0===r.length||r.indexOf(h)>=0;if(e&&b(e)||n||N.isLast())return $(1,t),0;let s=-1===r.indexOf("="),i="/"===r[0];if(s||i){let t=N.getPos()-1,e=N.grabWhile(t=>t!==c),r=t+e.length+2;return N.skip(),$(2,e,t,r),v(e,i),0}return 2}();break;case 2:o=function(){let t=N.getPos(),e=C(N.grabWhile(t=>t!==c,!0),{onSkip:m}),r=e.includes(" ");for(u=0;e.hasNext();)u=function(t,e,r){if(1===u){let e=t.grabWhile(t=>!("="===t||E(t))),r=t.isLast(),n="="!==t.getCurr();return(t.skip(),r||n?$(4,j(e)):$(3,e),r)?0:n?1:2}if(2===u){let r=!1,s=t.grabWhile(n=>{let s='"'===n,i=t.getPrev(),o=t.getNext(),u="="===o,a=E(n),l=o&&E(o);return!!(r&&L(n))||(!s||"\\"===i||!!(r=!r)||!!u||!!l)&&(!!e||!a)});return(t.skip(),$(4,j(s)),'"'===t.getPrev()&&n++,t.isLast())?0:1}let s=r+t.getPos()-1,i=t.grabWhile(e=>!("="===e||E(e)||t.isLast()));return($(2,i,s,r+t.getLength()+1),v(i),t.skip(),n++,e)?2:t.includes("=")?1:2}(e,!r,t);return N.skip(),0}();break;default:o=function(){if(P(N.getCurr()))return $(6,N.getCurr()),N.skip(),s=0,n=0,r++,0;if(E(N.getCurr()))return $(5,N.grabWhile(E)),0;if(N.getCurr()===h){if(a){let t=h.length+1+a.length,e=`${h}/${a}`;if(N.grabN(t)===e)return 1}else if(N.includes(c))return 1;return $(1,N.getCurr()),N.skip(),n++,0}if(g){if(O(N.getCurr())){let t=N.getCurr(),e=N.getNext();return(N.skip(),e&&k(e))?(N.skip(),$(1,e)):$(1,t),0}return $(1,N.grabWhile(t=>T(t)&&!O(t))),0}return $(1,N.grabWhile(T)),0}()}return l.length=i+1,l},isTokenNested:function(e){let r=h+"/"+e.getValue();if(p.has(r))return!!p.get(r);{let e=t.indexOf(r)>-1;return p.set(r,e),e}}}})(t,{onToken:function(t){t.isTag()?(t.isStart()&&function(t){p();let e=a.create(t.getValue(),{},[],{from:t.getStart(),to:t.getEnd()}),r=function(t){let e=t.getValue(),{isTokenNested:r}=u||{};return!f.has(e)&&r&&r(t)?(f.add(e),!0):f.has(e)}(t);c.push(e),r?h.push(e):A(d(),e)}(t),t.isEnd()&&function(t){let n=h.last();e(n)&&n.setEnd({from:t.getStart(),to:t.getEnd()}),p();let s=h.flush();if(s)A(d(),s);else if("function"==typeof r.onError){let e=t.getValue(),n=t.getLine(),s=t.getColumn();r.onError({tagName:e,lineNumber:n,columnNumber:s})}}(t)):!function(t){var e;let r=c.last(),n=t.getValue(),s=(e=t.toString(),!!f.has(e)),i=d();if(null!==r){if(t.isAttrName()){g.push(n);let t=g.last();t&&r.attr(t,"")}else if(t.isAttrValue()){let t=g.last();t?(r.attr(t,n),g.flush()):r.attr(n,n)}else t.isText()?s?r.append(n):A(i,n):t.isTag()&&A(i,t.toString())}else t.isText()?A(i,n):t.isTag()&&A(i,t.toString())}(t)},openTag:s,closeTag:i,onlyAllowTags:r.onlyAllowTags,contextFreeTags:r.contextFreeTags,enableEscapeTags:r.enableEscapeTags})).tokenize();let b=h.flush();return null!==b&&b&&e(b)&&(n=b.tag,f.has(n))&&y(d(),b,!1),l.toArray()}let B=t=>"object"==typeof t&&null!==t,F=t=>"boolean"==typeof t;function M(t,e){if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]=M(e(t[r]),e);else B(t)&&"content"in t&&M(t.content,e);return t}function U(t,e){return typeof t==typeof e&&(B(t)&&null!==t?Array.isArray(t)?t.every(t=>[].some.call(e,e=>U(t,e))):!!(B(t)&&B(e))&&Object.keys(t).every(r=>{let n=e[r],s=t[r];return B(s)&&B(n)?U(s,n):F(s)?s!==(null===n):n===s}):t===e)}function _(t,e){return t.messages=[...t.messages||[]],t.options={...e,...t.options},t.walk=function(t){return M(this,t)},t.match=function(t,e){return Array.isArray(t)?M(this,r=>{for(let n=0;n<t.length;n++)if(U(t[n],r))return e(r);return r}):M(this,r=>U(t,r)?e(r):r)},t}function q(t,r){let{stripTags:n=!1}=r||{};if(null==t)return"";if("string"==typeof t||"number"==typeof t)return t+"";if(Array.isArray(t))return H(t,r);if(e(t)){if(n)return H(t.content,r);let e=i(t.attrs);return null===t.content?"<"+t.tag+e+"/>":"<"+t.tag+e+">"+H(t.content,r)+"</"+t.tag+">"}return""}function H(t,e){return t&&Array.isArray(t)?t.reduce((t,r)=>t+q(r,e),""):t?q(t,e):""}function J(t,e,r){return(function(t){let e="function"==typeof t?[t]:t||[],r=()=>"";return{process(t,n){let s=n||{skipParse:!1,parser:z,render:r,data:null},i=s.parser||z,o=s.render,u=s.data||null;if("function"!=typeof i)throw Error("C1");let a=s.skipParse&&Array.isArray(t)?t:i(t,s),l=s.skipParse&&Array.isArray(t)?_(t||[],s):_(a,s);for(let t=0;t<e.length;t++){let r=e[t];"function"==typeof r&&o&&(l=_(r(l,{parse:i,render:o,iterate:M,data:u})||l,s))}return{get html(){if("function"!=typeof o)throw Error("C2");return o(l,l.options)},tree:l,raw:a,messages:l.messages}}}})(e).process(t,{...r,render:H}).html}t.default=J,t.html=J,t.render=H,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "@bbob/html",
"version": "4.0.3",
"version": "4.1.0",
"description": "A BBCode to HTML Renderer part of @bbob",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

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