@bbob/plugin-helper
Advanced tools
Comparing version 0.0.0-alpha.626820c to 0.0.0-alpha.7daea28
@@ -146,2 +146,8 @@ (function (global, factory) { | ||
} | ||
setStart(value) { | ||
this.start = value; | ||
} | ||
setEnd(value) { | ||
this.end = value; | ||
} | ||
get length() { | ||
@@ -158,3 +164,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; | ||
} | ||
@@ -175,4 +188,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; | ||
} | ||
@@ -179,0 +196,0 @@ static isOf(node, type) { |
@@ -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).BbobPluginHelper={})}(this,function(t){"use strict";function e(t){return"object"==typeof t&&null!==t&&"tag"in t}function n(t){return"string"==typeof t}function r(t,e,n){return Object.keys(t).reduce((n,r)=>e(n,r,t),n)}function i(t){return e(t)&&Array.isArray(t.content)?t.content.reduce((t,e)=>t+i(e),0):n(t)?(t+"").length:0}function o(t,e){Array.isArray(t.content)&&t.content.push(e)}function s(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript|data|vbscript):/gi,"$1%3A")}function a(t,e){switch(typeof e){case"boolean":return e?""+t:"";case"number":return`${t}="${e}"`;case"string":return`${t}="${s(e)}"`;case"object":return`${t}="${s(JSON.stringify(e))}"`;default:return""}}function u(t){return null==t?"":r(t,(t,e,n)=>[...t,a(e,n[e])],[""]).join(" ")}function c(t){return r(t||{},(t,e,n)=>n[e]===e?n[e]:null,null)}let l=(t,e)=>{let n=c(e);if(n){let r=a(t,n),i={...e};delete i[n+""];let o=u(i);return`${r}${o}`}return`${t}${u(e)}`},g=(t,n,r)=>{let i=t=>e(t)?t.toString({openTag:n,closeTag:r}):t+"";return Array.isArray(t)?t.reduce((t,e)=>null!==e?t+i(e):t,""):t?i(t):null};class f{attr(t,e){return void 0!==e&&(this.attrs[t]=e),this.attrs[t]}append(t){return o(this,t)}get length(){return i(this)}toTagStart({openTag:t="[",closeTag:e="]"}={}){let n=l(this.tag+"",this.attrs);return`${t}${n}${e}`}toTagEnd({openTag:t="[",closeTag:e="]"}={}){return`${t}/${this.tag}${e}`}toTagNode(){return new f((this.tag+"").toLowerCase(),this.attrs,this.content)}toString({openTag:t="[",closeTag:e="]"}={}){let n=this.content?g(this.content,t,e):"",r=this.toTagStart({openTag:t,closeTag:e});return null===this.content||Array.isArray(this.content)&&0===this.content.length?r:`${r}${n}${this.toTagEnd({openTag:t,closeTag:e})}`}static create(t,e={},n=null){return new f(t,e,n)}static isOf(t,e){return t.tag===e}constructor(t,e,n){this.tag=t,this.attrs=e,this.content=n}}t.BACKSLASH="\\",t.CLOSE_BRAKET="]",t.EQ="=",t.F="\f",t.N="\n",t.OPEN_BRAKET="[",t.QUOTEMARK='"',t.R="\r",t.SLASH="/",t.SPACE=" ",t.TAB=" ",t.TagNode=f,t.appendToNode=o,t.attrValue=a,t.attrsToString=u,t.escapeAttrValue=s,t.escapeHTML=s,t.getNodeLength=i,t.getUniqAttr=c,t.isEOL=function(t){return"\n"===t},t.isStringNode=n,t.isTagNode=e}); | ||
!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).BbobPluginHelper={})}(this,function(t){"use strict";function e(t){return"object"==typeof t&&null!==t&&"tag"in t}function n(t){return"string"==typeof t}function r(t,e,n){return Object.keys(t).reduce((n,r)=>e(n,r,t),n)}function s(t){return e(t)&&Array.isArray(t.content)?t.content.reduce((t,e)=>t+s(e),0):n(t)?(t+"").length:0}function i(t,e){Array.isArray(t.content)&&t.content.push(e)}function a(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript|data|vbscript):/gi,"$1%3A")}function o(t,e){switch(typeof e){case"boolean":return e?""+t:"";case"number":return`${t}="${e}"`;case"string":return`${t}="${a(e)}"`;case"object":return`${t}="${a(JSON.stringify(e))}"`;default:return""}}function u(t){return null==t?"":r(t,(t,e,n)=>[...t,o(e,n[e])],[""]).join(" ")}function c(t){return r(t||{},(t,e,n)=>n[e]===e?n[e]:null,null)}let l=(t,e)=>{let n=c(e);if(n){let r=o(t,n),s={...e};delete s[n+""];let i=u(s);return`${r}${i}`}return`${t}${u(e)}`},g=(t,n,r)=>{let s=t=>e(t)?t.toString({openTag:n,closeTag:r}):t+"";return Array.isArray(t)?t.reduce((t,e)=>null!==e?t+s(e):t,""):t?s(t):null};class h{attr(t,e){return void 0!==e&&(this.attrs[t]=e),this.attrs[t]}append(t){return i(this,t)}setStart(t){this.start=t}setEnd(t){this.end=t}get length(){return s(this)}toTagStart({openTag:t="[",closeTag:e="]"}={}){let n=l(this.tag+"",this.attrs);return`${t}${n}${e}`}toTagEnd({openTag:t="[",closeTag:e="]"}={}){return`${t}/${this.tag}${e}`}toTagNode(){let t=new h((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 n=this.content?g(this.content,t,e):"",r=this.toTagStart({openTag:t,closeTag:e});return null===this.content||Array.isArray(this.content)&&0===this.content.length?r:`${r}${n}${this.toTagEnd({openTag:t,closeTag:e})}`}static create(t,e={},n=null,r){let s=new h(t,e,n);return r&&s.setStart(r),s}static isOf(t,e){return t.tag===e}constructor(t,e,n){this.tag=t,this.attrs=e,this.content=n}}t.BACKSLASH="\\",t.CLOSE_BRAKET="]",t.EQ="=",t.F="\f",t.N="\n",t.OPEN_BRAKET="[",t.QUOTEMARK='"',t.R="\r",t.SLASH="/",t.SPACE=" ",t.TAB=" ",t.TagNode=h,t.appendToNode=i,t.attrValue=o,t.attrsToString=u,t.escapeAttrValue=a,t.escapeHTML=a,t.getNodeLength=s,t.getUniqAttr=c,t.isEOL=function(t){return"\n"===t},t.isStringNode=n,t.isTagNode=e}); |
@@ -49,2 +49,8 @@ import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from './char'; | ||
} | ||
setStart(value) { | ||
this.start = value; | ||
} | ||
setEnd(value) { | ||
this.end = value; | ||
} | ||
get length() { | ||
@@ -61,3 +67,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; | ||
} | ||
@@ -78,4 +91,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; | ||
} | ||
@@ -82,0 +99,0 @@ static isOf(node, type) { |
@@ -92,2 +92,8 @@ "use strict"; | ||
}; | ||
_proto.setStart = function setStart(value) { | ||
this.start = value; | ||
}; | ||
_proto.setEnd = function setEnd(value) { | ||
this.end = value; | ||
}; | ||
_proto.toTagStart = function toTagStart(param) { | ||
@@ -103,3 +109,10 @@ var _ref = param === void 0 ? {} : param, _ref_openTag = _ref.openTag, openTag = _ref_openTag === void 0 ? _char.OPEN_BRAKET : _ref_openTag, _ref_closeTag = _ref.closeTag, closeTag = _ref_closeTag === void 0 ? _char.CLOSE_BRAKET : _ref_closeTag; | ||
_proto.toTagNode = function toTagNode() { | ||
return new TagNode(String(this.tag).toLowerCase(), this.attrs, this.content); | ||
var 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; | ||
}; | ||
@@ -121,6 +134,10 @@ _proto.toString = function toString(param) { | ||
}; | ||
TagNode.create = function create(tag, attrs, content) { | ||
TagNode.create = function create(tag, attrs, content, start) { | ||
if (attrs === void 0) attrs = {}; | ||
if (content === void 0) content = null; | ||
return new TagNode(tag, attrs, content); | ||
var node = new TagNode(tag, attrs, content); | ||
if (start) { | ||
node.setStart(start); | ||
} | ||
return node; | ||
}; | ||
@@ -127,0 +144,0 @@ TagNode.isOf = function isOf(node, type) { |
{ | ||
"name": "@bbob/plugin-helper", | ||
"version": "0.0.0-alpha.626820c", | ||
"version": "0.0.0-alpha.7daea28", | ||
"description": "Set of utils to help write plugins for @bbob/core", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
import type { NodeContent, TagNodeObject, TagNodeTree } from "@bbob/types"; | ||
import type { NodeContent, TagNodeObject, TagNodeTree, TagPosition } from "@bbob/types"; | ||
@@ -33,7 +33,7 @@ import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from './char'; | ||
if (isTagNode(node)) { | ||
return node.toString({ openTag, closeTag }) | ||
return node.toString({ openTag, closeTag }); | ||
} | ||
return String(node) | ||
} | ||
return String(node); | ||
}; | ||
@@ -43,20 +43,22 @@ if (Array.isArray(content)) { | ||
if (node !== null) { | ||
return r + toString(node) | ||
return r + toString(node); | ||
} | ||
return r | ||
}, '') | ||
return r; | ||
}, ''); | ||
} | ||
if (content) { | ||
return toString(content) | ||
return toString(content); | ||
} | ||
return null | ||
} | ||
return null; | ||
}; | ||
export class TagNode<TagValue extends any = any> implements TagNodeObject { | ||
public readonly tag: string | TagValue | ||
public attrs: Record<string, unknown> | ||
public content: TagNodeTree | ||
public readonly tag: string | TagValue; | ||
public attrs: Record<string, unknown>; | ||
public content: TagNodeTree; | ||
public start?: TagPosition; | ||
public end?: TagPosition; | ||
@@ -66,3 +68,3 @@ constructor(tag: string | TagValue, attrs: Record<string, unknown>, content: TagNodeTree) { | ||
this.attrs = attrs; | ||
this.content = content | ||
this.content = content; | ||
} | ||
@@ -82,2 +84,10 @@ | ||
setStart(value: TagPosition) { | ||
this.start = value; | ||
} | ||
setEnd(value: TagPosition) { | ||
this.end = value; | ||
} | ||
get length(): number { | ||
@@ -98,10 +108,17 @@ 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; | ||
} | ||
toString({ openTag = OPEN_BRAKET, closeTag = CLOSE_BRAKET } = {}): string { | ||
const content = this.content ? renderContent(this.content, openTag, closeTag) : '' | ||
const content = this.content ? renderContent(this.content, openTag, closeTag) : ''; | ||
const tagStart = this.toTagStart({ openTag, closeTag }); | ||
if (this.content === null || Array.isArray(this.content) && this.content.length === 0) { | ||
if (this.content === null || Array.isArray(this.content) && this.content.length === 0) { | ||
return tagStart; | ||
@@ -113,9 +130,13 @@ } | ||
static create(tag: string, attrs: Record<string, unknown> = {}, content: TagNodeTree = null) { | ||
return new TagNode(tag, attrs, content) | ||
static create(tag: string, attrs: Record<string, unknown> = {}, content: TagNodeTree = null, start?: TagPosition) { | ||
const node = new TagNode(tag, attrs, content); | ||
if (start) { | ||
node.setStart(start); | ||
} | ||
return node; | ||
} | ||
static isOf(node: TagNode, type: string) { | ||
return (node.tag === type) | ||
return (node.tag === type); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import type { TagNodeObject, TagNodeTree } from "@bbob/types"; | ||
import type { TagNodeObject, TagNodeTree, TagPosition } from "@bbob/types"; | ||
export declare class TagNode<TagValue extends any = any> implements TagNodeObject { | ||
@@ -6,5 +6,9 @@ readonly tag: string | TagValue; | ||
content: TagNodeTree; | ||
start?: TagPosition; | ||
end?: TagPosition; | ||
constructor(tag: string | TagValue, attrs: Record<string, unknown>, content: TagNodeTree); | ||
attr(name: string, value?: unknown): unknown; | ||
append(value: string): void; | ||
setStart(value: TagPosition): void; | ||
setEnd(value: TagPosition): void; | ||
get length(): number; | ||
@@ -24,5 +28,5 @@ toTagStart({ openTag, closeTag }?: { | ||
}): string; | ||
static create(tag: string, attrs?: Record<string, unknown>, content?: TagNodeTree): TagNode<string>; | ||
static create(tag: string, attrs?: Record<string, unknown>, content?: TagNodeTree, start?: TagPosition): TagNode<string>; | ||
static isOf(node: TagNode, type: string): boolean; | ||
} | ||
//# sourceMappingURL=TagNode.d.ts.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86569
1113