@bbob/plugin-helper
Advanced tools
Comparing version 2.7.1 to 2.8.0
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.BbobPluginHelper = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BbobPluginHelper = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
var N = '\n'; | ||
var N = '\n'; | ||
var isTagNode = function isTagNode(el) { | ||
return typeof el === 'object' && !!el.tag; | ||
}; | ||
var isStringNode = function isStringNode(el) { | ||
return typeof el === 'string'; | ||
}; | ||
var isEOL = function isEOL(el) { | ||
return el === N; | ||
}; | ||
var keysReduce = function keysReduce(obj, reduce, def) { | ||
return Object.keys(obj).reduce(reduce, def); | ||
}; | ||
var getNodeLength = function getNodeLength(node) { | ||
if (isTagNode(node)) { | ||
return node.content.reduce(function (count, contentNode) { | ||
return count + getNodeLength(contentNode); | ||
}, 0); | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for(var i = 0, arr2 = new Array(arr.length); i < arr.length; i++){ | ||
arr2[i] = arr[i]; | ||
} | ||
return arr2; | ||
} | ||
} | ||
if (isStringNode(node)) { | ||
return node.length; | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
return 0; | ||
}; | ||
/** | ||
* Appends value to Tag Node | ||
* @param {TagNode} node | ||
* @param value | ||
*/ | ||
var appendToNode = function appendToNode(node, value) { | ||
node.content.push(value); | ||
}; | ||
/** | ||
* Replaces " to &qquot; | ||
* @param {String} value | ||
*/ | ||
var escapeHTML = function escapeHTML(value) { | ||
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''') // eslint-disable-next-line no-script-url | ||
.replace(/(javascript):/gi, '$1%3A'); | ||
}; | ||
/** | ||
* Acept name and value and return valid html5 attribute string | ||
* @param {String} name | ||
* @param {String} value | ||
* @return {string} | ||
*/ | ||
var attrValue = function attrValue(name, value) { | ||
var type = typeof value; | ||
var types = { | ||
boolean: function boolean() { | ||
return value ? "" + name : ''; | ||
}, | ||
number: function number() { | ||
return name + "=\"" + value + "\""; | ||
}, | ||
string: function string() { | ||
return name + "=\"" + escapeHTML(value) + "\""; | ||
}, | ||
object: function object() { | ||
return name + "=\"" + escapeHTML(JSON.stringify(value)) + "\""; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
var _typeof = function(obj) { | ||
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
return types[type] ? types[type]() : ''; | ||
}; | ||
/** | ||
* Transforms attrs to html params string | ||
* @param values | ||
*/ | ||
var isTagNode = function(el) { | ||
return typeof el === 'object' && !!el.tag; | ||
}; | ||
var isStringNode = function(el) { | ||
return typeof el === 'string'; | ||
}; | ||
var isEOL = function(el) { | ||
return el === N; | ||
}; | ||
var keysReduce = function(obj, reduce, def) { | ||
return Object.keys(obj).reduce(reduce, def); | ||
}; | ||
var getNodeLength = function(node) { | ||
if (isTagNode(node)) { | ||
return node.content.reduce(function(count, contentNode) { | ||
return count + getNodeLength(contentNode); | ||
}, 0); | ||
} | ||
if (isStringNode(node)) { | ||
return node.length; | ||
} | ||
return 0; | ||
}; | ||
/** | ||
* Appends value to Tag Node | ||
* @param {TagNode} node | ||
* @param value | ||
*/ var appendToNode = function(node, value) { | ||
node.content.push(value); | ||
}; | ||
/** | ||
* Replaces " to &qquot; | ||
* @param {String} value | ||
*/ var escapeHTML = function(value) { | ||
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''')// eslint-disable-next-line no-script-url | ||
.replace(/(javascript):/gi, '$1%3A'); | ||
}; | ||
/** | ||
* Acept name and value and return valid html5 attribute string | ||
* @param {String} name | ||
* @param {String} value | ||
* @return {string} | ||
*/ var attrValue = function(name, value) { | ||
var type = typeof value === "undefined" ? "undefined" : _typeof(value); | ||
var types = { | ||
boolean: function() { | ||
return value ? "".concat(name) : ''; | ||
}, | ||
number: function() { | ||
return "".concat(name, "=\"").concat(value, "\""); | ||
}, | ||
string: function() { | ||
return "".concat(name, "=\"").concat(escapeHTML(value), "\""); | ||
}, | ||
object: function() { | ||
return "".concat(name, "=\"").concat(escapeHTML(JSON.stringify(value)), "\""); | ||
} | ||
}; | ||
return types[type] ? types[type]() : ''; | ||
}; | ||
/** | ||
* Transforms attrs to html params string | ||
* @param values | ||
*/ var attrsToString = function(values) { | ||
// To avoid some malformed attributes | ||
if (values == null) { | ||
return ''; | ||
} | ||
return keysReduce(values, function(arr, key) { | ||
return _toConsumableArray(arr).concat([ | ||
attrValue(key, values[key]) | ||
]); | ||
}, [ | ||
'' | ||
]).join(' '); | ||
}; | ||
/** | ||
* Gets value from | ||
* @example | ||
* getUniqAttr({ 'foo': true, 'bar': bar' }) => 'bar' | ||
* @param attrs | ||
* @returns {string} | ||
*/ var getUniqAttr = function(attrs) { | ||
return keysReduce(attrs, function(res, key) { | ||
return attrs[key] === key ? attrs[key] : null; | ||
}, null); | ||
}; | ||
exports.appendToNode = appendToNode; | ||
exports.attrValue = attrValue; | ||
exports.attrsToString = attrsToString; | ||
exports.escapeHTML = escapeHTML; | ||
exports.getNodeLength = getNodeLength; | ||
exports.getUniqAttr = getUniqAttr; | ||
exports.isEOL = isEOL; | ||
exports.isStringNode = isStringNode; | ||
exports.isTagNode = isTagNode; | ||
var attrsToString = function attrsToString(values) { | ||
// To avoid some malformed attributes | ||
if (values == null) { | ||
return ''; | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
return keysReduce(values, function (arr, key) { | ||
return [].concat(arr, [attrValue(key, values[key])]); | ||
}, ['']).join(' '); | ||
}; | ||
/** | ||
* Gets value from | ||
* @example | ||
* getUniqAttr({ 'foo': true, 'bar': bar' }) => 'bar' | ||
* @param attrs | ||
* @returns {string} | ||
*/ | ||
var getUniqAttr = function getUniqAttr(attrs) { | ||
return keysReduce(attrs, function (res, key) { | ||
return attrs[key] === key ? attrs[key] : null; | ||
}, null); | ||
}; | ||
exports.appendToNode = appendToNode; | ||
exports.attrValue = attrValue; | ||
exports.attrsToString = attrsToString; | ||
exports.escapeHTML = escapeHTML; | ||
exports.getNodeLength = getNodeLength; | ||
exports.getUniqAttr = getUniqAttr; | ||
exports.isEOL = isEOL; | ||
exports.isStringNode = isStringNode; | ||
exports.isTagNode = isTagNode; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n=n||self).BbobPluginHelper={})}(this,(function(n){"use strict";var e=function(n){return"object"==typeof n&&!!n.tag},t=function(n){return"string"==typeof n},r=function(n,e,t){return Object.keys(n).reduce(e,t)},u=function(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript):/gi,"$1%3A")},o=function(n,e){var t=typeof e,r={boolean:function(){return e?""+n:""},number:function(){return n+'="'+e+'"'},string:function(){return n+'="'+u(e)+'"'},object:function(){return n+'="'+u(JSON.stringify(e))+'"'}};return r[t]?r[t]():""};n.appendToNode=function(n,e){n.content.push(e)},n.attrValue=o,n.attrsToString=function(n){return null==n?"":r(n,(function(e,t){return[].concat(e,[o(t,n[t])])}),[""]).join(" ")},n.escapeHTML=u,n.getNodeLength=function n(r){return e(r)?r.content.reduce((function(e,t){return e+n(t)}),0):t(r)?r.length:0},n.getUniqAttr=function(n){return r(n,(function(e,t){return n[t]===t?n[t]:null}),null)},n.isEOL=function(n){return"\n"===n},n.isStringNode=t,n.isTagNode=e,Object.defineProperty(n,"__esModule",{value:!0})})); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).BbobPluginHelper={})}(this,(function(n){"use strict";function t(n){return function(n){if(Array.isArray(n)){for(var t=0,e=Array(n.length);n.length>t;t++)e[t]=n[t];return e}}(n)||function(n){if(Symbol.iterator in Object(n)||"[object Arguments]"===Object.prototype.toString.call(n))return Array.from(n)}(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var e=function(n){return"object"==typeof n&&!!n.tag},r=function(n){return"string"==typeof n},o=function(n,t,e){return Object.keys(n).reduce(t,e)},c=function(n){return e(n)?n.content.reduce((function(n,t){return n+c(t)}),0):r(n)?n.length:0},u=function(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript):/gi,"$1%3A")},i=function(n,t){var e,r=void 0===t?"undefined":(e=t)&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e,o={boolean:function(){return t?"".concat(n):""},number:function(){return"".concat(n,'="').concat(t,'"')},string:function(){return"".concat(n,'="').concat(u(t),'"')},object:function(){return"".concat(n,'="').concat(u(JSON.stringify(t)),'"')}};return o[r]?o[r]():""};n.appendToNode=function(n,t){n.content.push(t)},n.attrValue=i,n.attrsToString=function(n){return null==n?"":o(n,(function(e,r){return t(e).concat([i(r,n[r])])}),[""]).join(" ")},n.escapeHTML=u,n.getNodeLength=c,n.getUniqAttr=function(n){return o(n,(function(t,e){return n[e]===e?n[e]:null}),null)},n.isEOL=function(n){return"\n"===n},n.isStringNode=r,n.isTagNode=e,Object.defineProperty(n,"__esModule",{value:!0})})); |
@@ -1,31 +0,15 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.BACKSLASH = exports.PLACEHOLDER_SPACE = exports.PLACEHOLDER_SPACE_TAB = exports.SLASH = exports.CLOSE_BRAKET = exports.OPEN_BRAKET = exports.SPACE = exports.QUOTEMARK = exports.EQ = exports.TAB = exports.R = exports.F = exports.N = void 0; | ||
var N = '\n'; | ||
exports.N = N; | ||
var TAB = '\t'; | ||
exports.TAB = TAB; | ||
var F = '\f'; | ||
exports.F = F; | ||
var R = '\r'; | ||
exports.R = R; | ||
var EQ = '='; | ||
exports.EQ = EQ; | ||
var QUOTEMARK = '"'; | ||
exports.QUOTEMARK = QUOTEMARK; | ||
var SPACE = ' '; | ||
exports.SPACE = SPACE; | ||
var OPEN_BRAKET = '['; | ||
exports.OPEN_BRAKET = OPEN_BRAKET; | ||
var CLOSE_BRAKET = ']'; | ||
exports.CLOSE_BRAKET = CLOSE_BRAKET; | ||
var SLASH = '/'; | ||
exports.SLASH = SLASH; | ||
var BACKSLASH = '\\'; | ||
exports.BACKSLASH = BACKSLASH; | ||
var PLACEHOLDER_SPACE_TAB = ' '; | ||
exports.PLACEHOLDER_SPACE_TAB = PLACEHOLDER_SPACE_TAB; | ||
var PLACEHOLDER_SPACE = ' '; // const getChar = String.fromCharCode; | ||
exports.PLACEHOLDER_SPACE = PLACEHOLDER_SPACE; | ||
var PLACEHOLDER_SPACE = ' '; | ||
// const getChar = String.fromCharCode; | ||
export { N, F, R, TAB, EQ, QUOTEMARK, SPACE, OPEN_BRAKET, CLOSE_BRAKET, SLASH, PLACEHOLDER_SPACE_TAB, PLACEHOLDER_SPACE, BACKSLASH }; |
163
es/index.js
@@ -1,33 +0,45 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getUniqAttr = exports.getNodeLength = exports.escapeHTML = exports.appendToNode = exports.attrValue = exports.attrsToString = void 0; | ||
var _char = require("./char"); | ||
var isTagNode = el => typeof el === 'object' && !!el.tag; | ||
exports.isTagNode = isTagNode; | ||
var isStringNode = el => typeof el === 'string'; | ||
exports.isStringNode = isStringNode; | ||
var isEOL = el => el === _char.N; | ||
exports.isEOL = isEOL; | ||
var keysReduce = (obj, reduce, def) => Object.keys(obj).reduce(reduce, def); | ||
var getNodeLength = node => { | ||
if (isTagNode(node)) { | ||
return node.content.reduce((count, contentNode) => count + getNodeLength(contentNode), 0); | ||
} | ||
if (isStringNode(node)) { | ||
return node.length; | ||
} | ||
return 0; | ||
import { N } from './char'; | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for(var i = 0, arr2 = new Array(arr.length); i < arr.length; i++){ | ||
arr2[i] = arr[i]; | ||
} | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
var _typeof = function(obj) { | ||
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
var isTagNode = function(el) { | ||
return typeof el === 'object' && !!el.tag; | ||
}; | ||
var isStringNode = function(el) { | ||
return typeof el === 'string'; | ||
}; | ||
var isEOL = function(el) { | ||
return el === N; | ||
}; | ||
var keysReduce = function(obj, reduce, def) { | ||
return Object.keys(obj).reduce(reduce, def); | ||
}; | ||
var getNodeLength = function(node) { | ||
if (isTagNode(node)) { | ||
return node.content.reduce(function(count, contentNode) { | ||
return count + getNodeLength(contentNode); | ||
}, 0); | ||
} | ||
if (isStringNode(node)) { | ||
return node.length; | ||
} | ||
return 0; | ||
}; | ||
/** | ||
@@ -37,9 +49,4 @@ * Appends value to Tag Node | ||
* @param value | ||
*/ | ||
exports.getNodeLength = getNodeLength; | ||
var appendToNode = (node, value) => { | ||
node.content.push(value); | ||
*/ var appendToNode = function(node, value) { | ||
node.content.push(value); | ||
}; | ||
@@ -49,9 +56,6 @@ /** | ||
* @param {String} value | ||
*/ | ||
exports.appendToNode = appendToNode; | ||
var escapeHTML = value => value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''') // eslint-disable-next-line no-script-url | ||
.replace(/(javascript):/gi, '$1%3A'); | ||
*/ var escapeHTML = function(value) { | ||
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''')// eslint-disable-next-line no-script-url | ||
.replace(/(javascript):/gi, '$1%3A'); | ||
}; | ||
/** | ||
@@ -62,16 +66,19 @@ * Acept name and value and return valid html5 attribute string | ||
* @return {string} | ||
*/ | ||
exports.escapeHTML = escapeHTML; | ||
var attrValue = (name, value) => { | ||
var type = typeof value; | ||
var types = { | ||
boolean: () => value ? "" + name : '', | ||
number: () => name + "=\"" + value + "\"", | ||
string: () => name + "=\"" + escapeHTML(value) + "\"", | ||
object: () => name + "=\"" + escapeHTML(JSON.stringify(value)) + "\"" | ||
}; | ||
return types[type] ? types[type]() : ''; | ||
*/ var attrValue = function(name, value) { | ||
var type = typeof value === "undefined" ? "undefined" : _typeof(value); | ||
var types = { | ||
boolean: function() { | ||
return value ? "".concat(name) : ''; | ||
}, | ||
number: function() { | ||
return "".concat(name, "=\"").concat(value, "\""); | ||
}, | ||
string: function() { | ||
return "".concat(name, "=\"").concat(escapeHTML(value), "\""); | ||
}, | ||
object: function() { | ||
return "".concat(name, "=\"").concat(escapeHTML(JSON.stringify(value)), "\""); | ||
} | ||
}; | ||
return types[type] ? types[type]() : ''; | ||
}; | ||
@@ -81,14 +88,14 @@ /** | ||
* @param values | ||
*/ | ||
exports.attrValue = attrValue; | ||
var attrsToString = values => { | ||
// To avoid some malformed attributes | ||
if (values == null) { | ||
return ''; | ||
} | ||
return keysReduce(values, (arr, key) => [...arr, attrValue(key, values[key])], ['']).join(' '); | ||
*/ var attrsToString = function(values) { | ||
// To avoid some malformed attributes | ||
if (values == null) { | ||
return ''; | ||
} | ||
return keysReduce(values, function(arr, key) { | ||
return _toConsumableArray(arr).concat([ | ||
attrValue(key, values[key]) | ||
]); | ||
}, [ | ||
'' | ||
]).join(' '); | ||
}; | ||
@@ -101,9 +108,7 @@ /** | ||
* @returns {string} | ||
*/ | ||
exports.attrsToString = attrsToString; | ||
var getUniqAttr = attrs => keysReduce(attrs, (res, key) => attrs[key] === key ? attrs[key] : null, null); | ||
exports.getUniqAttr = getUniqAttr; | ||
*/ var getUniqAttr = function(attrs) { | ||
return keysReduce(attrs, function(res, key) { | ||
return attrs[key] === key ? attrs[key] : null; | ||
}, null); | ||
}; | ||
export { attrsToString, attrValue, appendToNode, escapeHTML, getNodeLength, getUniqAttr, isTagNode, isStringNode, isEOL }; |
@@ -1,116 +0,155 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = exports.TagNode = void 0; | ||
var _char = require("./char"); | ||
var _index = require("./index"); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var getTagAttrs = (tag, params) => { | ||
var uniqAattr = (0, _index.getUniqAttr)(params); | ||
if (uniqAattr) { | ||
var tagAttr = (0, _index.attrValue)(tag, uniqAattr); | ||
var attrs = _extends({}, params); | ||
delete attrs[uniqAattr]; | ||
var attrsStr = (0, _index.attrsToString)(attrs); | ||
return "" + tagAttr + attrsStr; | ||
} | ||
return "" + tag + (0, _index.attrsToString)(params); | ||
}; | ||
class TagNode { | ||
constructor(tag, attrs, content) { | ||
this.tag = tag; | ||
this.attrs = attrs; | ||
this.content = Array.isArray(content) ? content : [content]; | ||
} | ||
attr(name, value) { | ||
if (typeof value !== 'undefined') { | ||
this.attrs[name] = value; | ||
import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from './char'; | ||
import { getNodeLength, appendToNode, attrsToString, attrValue, getUniqAttr } from './index'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
return this.attrs[name]; | ||
} | ||
append(value) { | ||
return (0, _index.appendToNode)(this, value); | ||
} | ||
get length() { | ||
return (0, _index.getNodeLength)(this); | ||
} | ||
toTagStart(_temp) { | ||
var { | ||
openTag = _char.OPEN_BRAKET, | ||
closeTag = _char.CLOSE_BRAKET | ||
} = _temp === void 0 ? {} : _temp; | ||
var tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
return "" + openTag + tagAttrs + closeTag; | ||
} | ||
toTagEnd(_temp2) { | ||
var { | ||
openTag = _char.OPEN_BRAKET, | ||
closeTag = _char.CLOSE_BRAKET | ||
} = _temp2 === void 0 ? {} : _temp2; | ||
return "" + openTag + _char.SLASH + this.tag + closeTag; | ||
} | ||
toTagNode() { | ||
return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
} | ||
toString(_temp3) { | ||
var { | ||
openTag = _char.OPEN_BRAKET, | ||
closeTag = _char.CLOSE_BRAKET | ||
} = _temp3 === void 0 ? {} : _temp3; | ||
var isEmpty = this.content.length === 0; | ||
var content = this.content.reduce((r, node) => r + node.toString({ | ||
openTag, | ||
closeTag | ||
}), ''); | ||
var tagStart = this.toTagStart({ | ||
openTag, | ||
closeTag | ||
}); | ||
if (isEmpty) { | ||
return tagStart; | ||
} | ||
function _defineProperties(target, props) { | ||
for(var i = 0; i < props.length; i++){ | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
return "" + tagStart + content + this.toTagEnd({ | ||
openTag, | ||
closeTag | ||
}); | ||
} | ||
} | ||
exports.TagNode = TagNode; | ||
TagNode.create = function (tag, attrs, content) { | ||
if (attrs === void 0) { | ||
attrs = {}; | ||
} | ||
if (content === void 0) { | ||
content = []; | ||
} | ||
return new TagNode(tag, attrs, content); | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectSpread(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i] != null ? arguments[i] : { | ||
}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === "function") { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
} | ||
var getTagAttrs = function(tag, params) { | ||
var uniqAattr = getUniqAttr(params); | ||
if (uniqAattr) { | ||
var tagAttr = attrValue(tag, uniqAattr); | ||
var attrs = _objectSpread({ | ||
}, params); | ||
delete attrs[uniqAattr]; | ||
var attrsStr = attrsToString(attrs); | ||
return "".concat(tagAttr).concat(attrsStr); | ||
} | ||
return "".concat(tag).concat(attrsToString(params)); | ||
}; | ||
TagNode.isOf = (node, type) => node.tag === type; | ||
var _default = TagNode; | ||
exports.default = _default; | ||
var TagNode = /*#__PURE__*/ function() { | ||
"use strict"; | ||
function TagNode(tag, attrs, content) { | ||
_classCallCheck(this, TagNode); | ||
this.tag = tag; | ||
this.attrs = attrs; | ||
this.content = Array.isArray(content) ? content : [ | ||
content | ||
]; | ||
} | ||
_createClass(TagNode, [ | ||
{ | ||
key: "attr", | ||
value: function attr(name, value) { | ||
if (typeof value !== 'undefined') { | ||
this.attrs[name] = value; | ||
} | ||
return this.attrs[name]; | ||
} | ||
}, | ||
{ | ||
key: "append", | ||
value: function append(value) { | ||
return appendToNode(this, value); | ||
} | ||
}, | ||
{ | ||
key: "length", | ||
get: function get() { | ||
return getNodeLength(this); | ||
} | ||
}, | ||
{ | ||
key: "toTagStart", | ||
value: function toTagStart(param) { | ||
var ref = param === void 0 ? { | ||
} : param, _openTag = ref.openTag, openTag = _openTag === void 0 ? OPEN_BRAKET : _openTag, _closeTag = ref.closeTag, closeTag = _closeTag === void 0 ? CLOSE_BRAKET : _closeTag; | ||
var tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
return "".concat(openTag).concat(tagAttrs).concat(closeTag); | ||
} | ||
}, | ||
{ | ||
key: "toTagEnd", | ||
value: function toTagEnd(param) { | ||
var ref = param === void 0 ? { | ||
} : param, _openTag = ref.openTag, openTag = _openTag === void 0 ? OPEN_BRAKET : _openTag, _closeTag = ref.closeTag, closeTag = _closeTag === void 0 ? CLOSE_BRAKET : _closeTag; | ||
return "".concat(openTag).concat(SLASH).concat(this.tag).concat(closeTag); | ||
} | ||
}, | ||
{ | ||
key: "toTagNode", | ||
value: function toTagNode() { | ||
return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
} | ||
}, | ||
{ | ||
key: "toString", | ||
value: function toString(param) { | ||
var ref = param === void 0 ? { | ||
} : param, _openTag = ref.openTag, openTag = _openTag === void 0 ? OPEN_BRAKET : _openTag, _closeTag = ref.closeTag, closeTag = _closeTag === void 0 ? CLOSE_BRAKET : _closeTag; | ||
var isEmpty = this.content.length === 0; | ||
var content = this.content.reduce(function(r, node) { | ||
return r + node.toString({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
}, ''); | ||
var tagStart = this.toTagStart({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
if (isEmpty) { | ||
return tagStart; | ||
} | ||
return "".concat(tagStart).concat(content).concat(this.toTagEnd({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
})); | ||
} | ||
} | ||
]); | ||
return TagNode; | ||
}(); | ||
TagNode.create = function(tag, param, param1) { | ||
var attrs = param === void 0 ? { | ||
} : param, content = param1 === void 0 ? [] : param1; | ||
return new TagNode(tag, attrs, content); | ||
}; | ||
TagNode.isOf = function(node, type) { | ||
return node.tag === type; | ||
}; | ||
export { TagNode }; | ||
export default TagNode; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.BACKSLASH = exports.PLACEHOLDER_SPACE = exports.PLACEHOLDER_SPACE_TAB = exports.SLASH = exports.CLOSE_BRAKET = exports.OPEN_BRAKET = exports.SPACE = exports.QUOTEMARK = exports.EQ = exports.TAB = exports.R = exports.F = exports.N = void 0; | ||
var N = '\n'; | ||
exports.N = N; | ||
var TAB = '\t'; | ||
exports.TAB = TAB; | ||
var F = '\f'; | ||
exports.F = F; | ||
var R = '\r'; | ||
exports.R = R; | ||
var EQ = '='; | ||
exports.EQ = EQ; | ||
var QUOTEMARK = '"'; | ||
exports.QUOTEMARK = QUOTEMARK; | ||
var SPACE = ' '; | ||
exports.SPACE = SPACE; | ||
var OPEN_BRAKET = '['; | ||
exports.OPEN_BRAKET = OPEN_BRAKET; | ||
var CLOSE_BRAKET = ']'; | ||
exports.CLOSE_BRAKET = CLOSE_BRAKET; | ||
var SLASH = '/'; | ||
exports.SLASH = SLASH; | ||
var BACKSLASH = '\\'; | ||
exports.BACKSLASH = BACKSLASH; | ||
var PLACEHOLDER_SPACE_TAB = ' '; | ||
var PLACEHOLDER_SPACE = ' '; | ||
exports.N = N; | ||
exports.F = F; | ||
exports.R = R; | ||
exports.TAB = TAB; | ||
exports.EQ = EQ; | ||
exports.QUOTEMARK = QUOTEMARK; | ||
exports.SPACE = SPACE; | ||
exports.OPEN_BRAKET = OPEN_BRAKET; | ||
exports.CLOSE_BRAKET = CLOSE_BRAKET; | ||
exports.SLASH = SLASH; | ||
exports.PLACEHOLDER_SPACE_TAB = PLACEHOLDER_SPACE_TAB; | ||
var PLACEHOLDER_SPACE = ' '; // const getChar = String.fromCharCode; | ||
exports.PLACEHOLDER_SPACE = PLACEHOLDER_SPACE; | ||
exports.PLACEHOLDER_SPACE = PLACEHOLDER_SPACE; | ||
exports.BACKSLASH = BACKSLASH; |
184
lib/index.js
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getUniqAttr = exports.getNodeLength = exports.escapeHTML = exports.appendToNode = exports.attrValue = exports.attrsToString = void 0; | ||
var _char = require("./char"); | ||
var isTagNode = function isTagNode(el) { | ||
return typeof el === 'object' && !!el.tag; | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for(var i = 0, arr2 = new Array(arr.length); i < arr.length; i++){ | ||
arr2[i] = arr[i]; | ||
} | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
var _typeof = function(obj) { | ||
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
exports.isTagNode = isTagNode; | ||
var isStringNode = function isStringNode(el) { | ||
return typeof el === 'string'; | ||
var isTagNode = function(el) { | ||
return typeof el === 'object' && !!el.tag; | ||
}; | ||
exports.isStringNode = isStringNode; | ||
var isEOL = function isEOL(el) { | ||
return el === _char.N; | ||
var isStringNode = function(el) { | ||
return typeof el === 'string'; | ||
}; | ||
exports.isEOL = isEOL; | ||
var keysReduce = function keysReduce(obj, reduce, def) { | ||
return Object.keys(obj).reduce(reduce, def); | ||
var isEOL = function(el) { | ||
return el === _char.N; | ||
}; | ||
var getNodeLength = function getNodeLength(node) { | ||
if (isTagNode(node)) { | ||
return node.content.reduce(function (count, contentNode) { | ||
return count + getNodeLength(contentNode); | ||
}, 0); | ||
} | ||
if (isStringNode(node)) { | ||
return node.length; | ||
} | ||
return 0; | ||
var keysReduce = function(obj, reduce, def) { | ||
return Object.keys(obj).reduce(reduce, def); | ||
}; | ||
var getNodeLength = function(node) { | ||
if (isTagNode(node)) { | ||
return node.content.reduce(function(count, contentNode) { | ||
return count + getNodeLength(contentNode); | ||
}, 0); | ||
} | ||
if (isStringNode(node)) { | ||
return node.length; | ||
} | ||
return 0; | ||
}; | ||
/** | ||
@@ -47,9 +54,4 @@ * Appends value to Tag Node | ||
* @param value | ||
*/ | ||
exports.getNodeLength = getNodeLength; | ||
var appendToNode = function appendToNode(node, value) { | ||
node.content.push(value); | ||
*/ var appendToNode = function(node, value) { | ||
node.content.push(value); | ||
}; | ||
@@ -59,10 +61,5 @@ /** | ||
* @param {String} value | ||
*/ | ||
exports.appendToNode = appendToNode; | ||
var escapeHTML = function escapeHTML(value) { | ||
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''') // eslint-disable-next-line no-script-url | ||
.replace(/(javascript):/gi, '$1%3A'); | ||
*/ var escapeHTML = function(value) { | ||
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''')// eslint-disable-next-line no-script-url | ||
.replace(/(javascript):/gi, '$1%3A'); | ||
}; | ||
@@ -74,24 +71,19 @@ /** | ||
* @return {string} | ||
*/ | ||
exports.escapeHTML = escapeHTML; | ||
var attrValue = function attrValue(name, value) { | ||
var type = typeof value; | ||
var types = { | ||
"boolean": function boolean() { | ||
return value ? "" + name : ''; | ||
}, | ||
number: function number() { | ||
return name + "=\"" + value + "\""; | ||
}, | ||
string: function string() { | ||
return name + "=\"" + escapeHTML(value) + "\""; | ||
}, | ||
object: function object() { | ||
return name + "=\"" + escapeHTML(JSON.stringify(value)) + "\""; | ||
} | ||
}; | ||
return types[type] ? types[type]() : ''; | ||
*/ var attrValue = function(name, value) { | ||
var type = typeof value === "undefined" ? "undefined" : _typeof(value); | ||
var types = { | ||
boolean: function() { | ||
return value ? "".concat(name) : ''; | ||
}, | ||
number: function() { | ||
return "".concat(name, "=\"").concat(value, "\""); | ||
}, | ||
string: function() { | ||
return "".concat(name, "=\"").concat(escapeHTML(value), "\""); | ||
}, | ||
object: function() { | ||
return "".concat(name, "=\"").concat(escapeHTML(JSON.stringify(value)), "\""); | ||
} | ||
}; | ||
return types[type] ? types[type]() : ''; | ||
}; | ||
@@ -101,16 +93,14 @@ /** | ||
* @param values | ||
*/ | ||
exports.attrValue = attrValue; | ||
var attrsToString = function attrsToString(values) { | ||
// To avoid some malformed attributes | ||
if (values == null) { | ||
return ''; | ||
} | ||
return keysReduce(values, function (arr, key) { | ||
return [].concat(arr, [attrValue(key, values[key])]); | ||
}, ['']).join(' '); | ||
*/ var attrsToString = function(values) { | ||
// To avoid some malformed attributes | ||
if (values == null) { | ||
return ''; | ||
} | ||
return keysReduce(values, function(arr, key) { | ||
return _toConsumableArray(arr).concat([ | ||
attrValue(key, values[key]) | ||
]); | ||
}, [ | ||
'' | ||
]).join(' '); | ||
}; | ||
@@ -123,13 +113,15 @@ /** | ||
* @returns {string} | ||
*/ | ||
*/ var getUniqAttr = function(attrs) { | ||
return keysReduce(attrs, function(res, key) { | ||
return attrs[key] === key ? attrs[key] : null; | ||
}, null); | ||
}; | ||
exports.attrsToString = attrsToString; | ||
var getUniqAttr = function getUniqAttr(attrs) { | ||
return keysReduce(attrs, function (res, key) { | ||
return attrs[key] === key ? attrs[key] : null; | ||
}, null); | ||
}; | ||
exports.getUniqAttr = getUniqAttr; | ||
exports.attrValue = attrValue; | ||
exports.appendToNode = appendToNode; | ||
exports.escapeHTML = escapeHTML; | ||
exports.getNodeLength = getNodeLength; | ||
exports.getUniqAttr = getUniqAttr; | ||
exports.isTagNode = isTagNode; | ||
exports.isStringNode = isStringNode; | ||
exports.isEOL = isEOL; |
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = exports.TagNode = void 0; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.TagNode = void 0; | ||
var _char = require("./char"); | ||
var _index = require("./index"); | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var getTagAttrs = function getTagAttrs(tag, params) { | ||
var uniqAattr = (0, _index.getUniqAttr)(params); | ||
if (uniqAattr) { | ||
var tagAttr = (0, _index.attrValue)(tag, uniqAattr); | ||
var attrs = _extends({}, params); | ||
delete attrs[uniqAattr]; | ||
var attrsStr = (0, _index.attrsToString)(attrs); | ||
return "" + tagAttr + attrsStr; | ||
} | ||
return "" + tag + (0, _index.attrsToString)(params); | ||
}; | ||
var TagNode = | ||
/*#__PURE__*/ | ||
function () { | ||
function TagNode(tag, attrs, content) { | ||
this.tag = tag; | ||
this.attrs = attrs; | ||
this.content = Array.isArray(content) ? content : [content]; | ||
} | ||
var _proto = TagNode.prototype; | ||
_proto.attr = function attr(name, value) { | ||
if (typeof value !== 'undefined') { | ||
this.attrs[name] = value; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
return this.attrs[name]; | ||
}; | ||
_proto.append = function append(value) { | ||
return (0, _index.appendToNode)(this, value); | ||
}; | ||
_proto.toTagStart = function toTagStart(_temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
_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); | ||
return "" + openTag + tagAttrs + closeTag; | ||
}; | ||
_proto.toTagEnd = function toTagEnd(_temp2) { | ||
var _ref2 = _temp2 === void 0 ? {} : _temp2, | ||
_ref2$openTag = _ref2.openTag, | ||
openTag = _ref2$openTag === void 0 ? _char.OPEN_BRAKET : _ref2$openTag, | ||
_ref2$closeTag = _ref2.closeTag, | ||
closeTag = _ref2$closeTag === void 0 ? _char.CLOSE_BRAKET : _ref2$closeTag; | ||
return "" + openTag + _char.SLASH + this.tag + closeTag; | ||
}; | ||
_proto.toTagNode = function toTagNode() { | ||
return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
}; | ||
_proto.toString = function toString(_temp3) { | ||
var _ref3 = _temp3 === void 0 ? {} : _temp3, | ||
_ref3$openTag = _ref3.openTag, | ||
openTag = _ref3$openTag === void 0 ? _char.OPEN_BRAKET : _ref3$openTag, | ||
_ref3$closeTag = _ref3.closeTag, | ||
closeTag = _ref3$closeTag === void 0 ? _char.CLOSE_BRAKET : _ref3$closeTag; | ||
var isEmpty = this.content.length === 0; | ||
var content = this.content.reduce(function (r, node) { | ||
return r + node.toString({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
}, ''); | ||
var tagStart = this.toTagStart({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
if (isEmpty) { | ||
return tagStart; | ||
} | ||
function _defineProperties(target, props) { | ||
for(var i = 0; i < props.length; i++){ | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
return "" + tagStart + content + this.toTagEnd({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
}; | ||
_createClass(TagNode, [{ | ||
key: "length", | ||
get: function get() { | ||
return (0, _index.getNodeLength)(this); | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
}]); | ||
return TagNode; | ||
return obj; | ||
} | ||
function _objectSpread(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i] != null ? arguments[i] : { | ||
}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === "function") { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
} | ||
var getTagAttrs = function(tag, params) { | ||
var uniqAattr = (0, _index).getUniqAttr(params); | ||
if (uniqAattr) { | ||
var tagAttr = (0, _index).attrValue(tag, uniqAattr); | ||
var attrs = _objectSpread({ | ||
}, params); | ||
delete attrs[uniqAattr]; | ||
var attrsStr = (0, _index).attrsToString(attrs); | ||
return "".concat(tagAttr).concat(attrsStr); | ||
} | ||
return "".concat(tag).concat((0, _index).attrsToString(params)); | ||
}; | ||
var TagNode = /*#__PURE__*/ function() { | ||
"use strict"; | ||
function TagNode(tag, attrs, content) { | ||
_classCallCheck(this, TagNode); | ||
this.tag = tag; | ||
this.attrs = attrs; | ||
this.content = Array.isArray(content) ? content : [ | ||
content | ||
]; | ||
} | ||
_createClass(TagNode, [ | ||
{ | ||
key: "attr", | ||
value: function attr(name, value) { | ||
if (typeof value !== 'undefined') { | ||
this.attrs[name] = value; | ||
} | ||
return this.attrs[name]; | ||
} | ||
}, | ||
{ | ||
key: "append", | ||
value: function append(value) { | ||
return (0, _index).appendToNode(this, value); | ||
} | ||
}, | ||
{ | ||
key: "length", | ||
get: function get() { | ||
return (0, _index).getNodeLength(this); | ||
} | ||
}, | ||
{ | ||
key: "toTagStart", | ||
value: function toTagStart(param) { | ||
var ref = param === void 0 ? { | ||
} : param, _openTag = ref.openTag, openTag = _openTag === void 0 ? _char.OPEN_BRAKET : _openTag, _closeTag = ref.closeTag, closeTag = _closeTag === void 0 ? _char.CLOSE_BRAKET : _closeTag; | ||
var tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
return "".concat(openTag).concat(tagAttrs).concat(closeTag); | ||
} | ||
}, | ||
{ | ||
key: "toTagEnd", | ||
value: function toTagEnd(param) { | ||
var ref = param === void 0 ? { | ||
} : param, _openTag = ref.openTag, openTag = _openTag === void 0 ? _char.OPEN_BRAKET : _openTag, _closeTag = ref.closeTag, closeTag = _closeTag === void 0 ? _char.CLOSE_BRAKET : _closeTag; | ||
return "".concat(openTag).concat(_char.SLASH).concat(this.tag).concat(closeTag); | ||
} | ||
}, | ||
{ | ||
key: "toTagNode", | ||
value: function toTagNode() { | ||
return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
} | ||
}, | ||
{ | ||
key: "toString", | ||
value: function toString(param) { | ||
var ref = param === void 0 ? { | ||
} : param, _openTag = ref.openTag, openTag = _openTag === void 0 ? _char.OPEN_BRAKET : _openTag, _closeTag = ref.closeTag, closeTag = _closeTag === void 0 ? _char.CLOSE_BRAKET : _closeTag; | ||
var isEmpty = this.content.length === 0; | ||
var content = this.content.reduce(function(r, node) { | ||
return r + node.toString({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
}, ''); | ||
var tagStart = this.toTagStart({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
if (isEmpty) { | ||
return tagStart; | ||
} | ||
return "".concat(tagStart).concat(content).concat(this.toTagEnd({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
})); | ||
} | ||
} | ||
]); | ||
return TagNode; | ||
}(); | ||
exports.TagNode = TagNode; | ||
TagNode.create = function (tag, attrs, content) { | ||
if (attrs === void 0) { | ||
attrs = {}; | ||
} | ||
if (content === void 0) { | ||
content = []; | ||
} | ||
return new TagNode(tag, attrs, content); | ||
TagNode.create = function(tag, param, param1) { | ||
var attrs = param === void 0 ? { | ||
} : param, content = param1 === void 0 ? [] : param1; | ||
return new TagNode(tag, attrs, content); | ||
}; | ||
TagNode.isOf = function (node, type) { | ||
return node.tag === type; | ||
TagNode.isOf = function(node, type) { | ||
return node.tag === type; | ||
}; | ||
exports.TagNode = TagNode; | ||
var _default = TagNode; | ||
exports["default"] = _default; | ||
exports.default = _default; |
{ | ||
"name": "@bbob/plugin-helper", | ||
"version": "2.7.1", | ||
"version": "2.8.0", | ||
"description": "Set of utils to help write plugins for @bbob/core", | ||
@@ -26,11 +26,11 @@ "keywords": [ | ||
"scripts": { | ||
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs NODE_ENV=production ../../node_modules/.bin/babel src --out-dir lib", | ||
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es NODE_ENV=production ../../node_modules/.bin/babel src --out-dir es", | ||
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=production ../../node_modules/.bin/rollup --config ../../rollup.config.js", | ||
"build:commonjs": "../../scripts/pkg-task build-commonjs", | ||
"build:es": "../../scripts/pkg-task build-es", | ||
"build:umd": "../../scripts/pkg-task build-umd", | ||
"build": "npm run build:commonjs && npm run build:es && npm run build:umd", | ||
"test": "../../node_modules/.bin/jest --", | ||
"cover": "../../node_modules/.bin/jest --coverage", | ||
"lint": "../../node_modules/.bin/eslint .", | ||
"size": "../../node_modules/.bin/cross-env NODE_ENV=production ../../node_modules/.bin/size-limit", | ||
"bundlesize": "../../node_modules/.bin/cross-env NODE_ENV=production ../../node_modules/.bin/bundlesize", | ||
"test": "../../scripts/pkg-task test", | ||
"cover": "../../scripts/pkg-task cover", | ||
"lint": "../../scripts/pkg-task lint", | ||
"size": "../../scripts/pkg-task size", | ||
"bundlesize": "../../scripts/pkg-task bundlesize", | ||
"prepublishOnly": "npm run build" | ||
@@ -46,3 +46,3 @@ }, | ||
"path": "./dist/index.min.js", | ||
"maxSize": "650 B" | ||
"maxSize": "850 B" | ||
} | ||
@@ -59,3 +59,3 @@ ], | ||
], | ||
"gitHead": "90563965c0626834e359a9c81ade8ca872536891" | ||
"gitHead": "4fb4fffbc69ee34cb9d27812b23105e28645d45f" | ||
} |
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
35782
897
15