@bbob/plugin-helper
Advanced tools
Comparing version 0.0.0-alpha.a733494 to 0.0.0-alpha.cad4675
@@ -146,2 +146,8 @@ (function (global, factory) { | ||
} | ||
setStart(value) { | ||
this.start = value; | ||
} | ||
setEnd(value) { | ||
this.end = value; | ||
} | ||
get length() { | ||
@@ -151,3 +157,3 @@ return getNodeLength(this); | ||
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}`; | ||
@@ -159,3 +165,10 @@ } | ||
toTagNode() { | ||
return new TagNode(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; | ||
} | ||
@@ -176,4 +189,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,0 +197,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() { | ||
@@ -54,3 +60,3 @@ return getNodeLength(this); | ||
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}`; | ||
@@ -62,3 +68,10 @@ } | ||
toTagNode() { | ||
return new TagNode(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; | ||
} | ||
@@ -79,4 +92,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; | ||
} | ||
@@ -83,0 +100,0 @@ static isOf(node, type) { |
@@ -92,5 +92,11 @@ "use strict"; | ||
}; | ||
_proto.setStart = function setStart(value) { | ||
this.start = value; | ||
}; | ||
_proto.setEnd = function setEnd(value) { | ||
this.end = value; | ||
}; | ||
_proto.toTagStart = function toTagStart(param) { | ||
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 +109,10 @@ }; | ||
_proto.toTagNode = function toTagNode() { | ||
return new TagNode(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.a733494", | ||
"version": "0.0.0-alpha.cad4675", | ||
"description": "Set of utils to help write plugins for @bbob/core", | ||
@@ -66,2 +66,15 @@ "keywords": [ | ||
}, | ||
"scripts": { | ||
"build:commonjs": "pkg-task", | ||
"build:es": "pkg-task", | ||
"build:umd": "pkg-task", | ||
"build": "pkg-task", | ||
"test": "pkg-task", | ||
"cover": "pkg-task", | ||
"lint": "pkg-task", | ||
"size": "pkg-task", | ||
"bundlesize": "pkg-task", | ||
"types": "pkg-task", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"size-limit": [ | ||
@@ -81,15 +94,3 @@ { | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"scripts": { | ||
"build:commonjs": "pkg-task", | ||
"build:es": "pkg-task", | ||
"build:umd": "pkg-task", | ||
"build": "pkg-task", | ||
"test": "pkg-task", | ||
"cover": "pkg-task", | ||
"lint": "pkg-task", | ||
"size": "pkg-task", | ||
"bundlesize": "pkg-task", | ||
"types": "pkg-task" | ||
} | ||
} | ||
} |
@@ -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,25 +43,27 @@ 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 implements TagNodeObject { | ||
public readonly tag: string | ||
public attrs: Record<string, unknown> | ||
public content: TagNodeTree | ||
export class TagNode<TagValue extends any = any> implements TagNodeObject { | ||
public readonly tag: string | TagValue; | ||
public attrs: Record<string, unknown>; | ||
public content: TagNodeTree; | ||
public start?: TagPosition; | ||
public end?: TagPosition; | ||
constructor(tag: string, attrs: Record<string, unknown>, content: TagNodeTree) { | ||
constructor(tag: string | TagValue, attrs: Record<string, unknown>, content: TagNodeTree) { | ||
this.tag = tag; | ||
this.attrs = attrs; | ||
this.content = content | ||
this.content = content; | ||
} | ||
@@ -81,2 +83,10 @@ | ||
setStart(value: TagPosition) { | ||
this.start = value; | ||
} | ||
setEnd(value: TagPosition) { | ||
this.end = value; | ||
} | ||
get length(): number { | ||
@@ -87,3 +97,3 @@ return getNodeLength(this); | ||
toTagStart({ openTag = OPEN_BRAKET, closeTag = CLOSE_BRAKET } = {}) { | ||
const tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
const tagAttrs = getTagAttrs(String(this.tag), this.attrs); | ||
@@ -98,10 +108,17 @@ return `${openTag}${tagAttrs}${closeTag}`; | ||
toTagNode() { | ||
return new TagNode(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,9 +0,13 @@ | ||
import type { TagNodeObject, TagNodeTree } from "@bbob/types"; | ||
export declare class TagNode implements TagNodeObject { | ||
readonly tag: string; | ||
import type { TagNodeObject, TagNodeTree, TagPosition } from "@bbob/types"; | ||
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); | ||
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; | ||
@@ -18,3 +22,3 @@ toTagStart({ openTag, closeTag }?: { | ||
}): string; | ||
toTagNode(): TagNode; | ||
toTagNode(): TagNode<string>; | ||
toString({ openTag, closeTag }?: { | ||
@@ -24,5 +28,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, 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
86580
1113
24