@bbob/plugin-helper
Advanced tools
Comparing version 0.0.0-alpha.4a7856d to 0.0.0-alpha.626820c
@@ -150,3 +150,3 @@ (function (global, factory) { | ||
toTagStart({ openTag = OPEN_BRAKET, closeTag = CLOSE_BRAKET } = {}) { | ||
const tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
const tagAttrs = getTagAttrs(String(this.tag), this.attrs); | ||
return `${openTag}${tagAttrs}${closeTag}`; | ||
@@ -158,3 +158,3 @@ } | ||
toTagNode() { | ||
return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
return new TagNode(String(this.tag).toLowerCase(), this.attrs, this.content); | ||
} | ||
@@ -161,0 +161,0 @@ toString({ openTag = OPEN_BRAKET, closeTag = CLOSE_BRAKET } = {}) { |
@@ -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 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}); |
@@ -53,3 +53,3 @@ import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from './char'; | ||
toTagStart({ openTag = OPEN_BRAKET, closeTag = CLOSE_BRAKET } = {}) { | ||
const tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
const tagAttrs = getTagAttrs(String(this.tag), this.attrs); | ||
return `${openTag}${tagAttrs}${closeTag}`; | ||
@@ -61,3 +61,3 @@ } | ||
toTagNode() { | ||
return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
return new TagNode(String(this.tag).toLowerCase(), this.attrs, this.content); | ||
} | ||
@@ -64,0 +64,0 @@ toString({ openTag = OPEN_BRAKET, closeTag = CLOSE_BRAKET } = {}) { |
@@ -94,3 +94,3 @@ "use strict"; | ||
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; | ||
var tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
var tagAttrs = getTagAttrs(String(this.tag), this.attrs); | ||
return "" + openTag + tagAttrs + closeTag; | ||
@@ -103,3 +103,3 @@ }; | ||
_proto.toTagNode = function toTagNode() { | ||
return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
return new TagNode(String(this.tag).toLowerCase(), this.attrs, this.content); | ||
}; | ||
@@ -106,0 +106,0 @@ _proto.toString = function toString(param) { |
{ | ||
"name": "@bbob/plugin-helper", | ||
"version": "0.0.0-alpha.4a7856d", | ||
"version": "0.0.0-alpha.626820c", | ||
"description": "Set of utils to help write plugins for @bbob/core", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -56,8 +56,8 @@ import type { NodeContent, TagNodeObject, TagNodeTree } from "@bbob/types"; | ||
export class TagNode implements TagNodeObject { | ||
public readonly tag: string | ||
export class TagNode<TagValue extends any = any> implements TagNodeObject { | ||
public readonly tag: string | TagValue | ||
public attrs: Record<string, unknown> | ||
public content: TagNodeTree | ||
constructor(tag: string, attrs: Record<string, unknown>, content: TagNodeTree) { | ||
constructor(tag: string | TagValue, attrs: Record<string, unknown>, content: TagNodeTree) { | ||
this.tag = tag; | ||
@@ -85,3 +85,3 @@ this.attrs = attrs; | ||
toTagStart({ openTag = OPEN_BRAKET, closeTag = CLOSE_BRAKET } = {}) { | ||
const tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
const tagAttrs = getTagAttrs(String(this.tag), this.attrs); | ||
@@ -96,3 +96,3 @@ return `${openTag}${tagAttrs}${closeTag}`; | ||
toTagNode() { | ||
return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
return new TagNode(String(this.tag).toLowerCase(), this.attrs, this.content); | ||
} | ||
@@ -99,0 +99,0 @@ |
import type { TagNodeObject, TagNodeTree } from "@bbob/types"; | ||
export declare class TagNode implements TagNodeObject { | ||
readonly tag: string; | ||
export declare class TagNode<TagValue extends any = any> implements TagNodeObject { | ||
readonly tag: string | TagValue; | ||
attrs: Record<string, unknown>; | ||
content: TagNodeTree; | ||
constructor(tag: string, attrs: Record<string, unknown>, content: TagNodeTree); | ||
constructor(tag: string | TagValue, attrs: Record<string, unknown>, content: TagNodeTree); | ||
attr(name: string, value?: unknown): unknown; | ||
@@ -18,3 +18,3 @@ append(value: string): void; | ||
}): string; | ||
toTagNode(): TagNode; | ||
toTagNode(): TagNode<string>; | ||
toString({ openTag, closeTag }?: { | ||
@@ -24,5 +24,5 @@ openTag?: string | undefined; | ||
}): string; | ||
static create(tag: string, attrs?: Record<string, unknown>, content?: TagNodeTree): TagNode; | ||
static create(tag: string, attrs?: Record<string, unknown>, content?: TagNodeTree): 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
83293