Socket
Socket
Sign inDemoInstall

shortcode-tree

Package Overview
Dependencies
0
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.11 to 1.4.12

package-lock.json

0

dist/shortcode-extractor.js

@@ -0,0 +0,0 @@ 'use strict';

10

dist/shortcode-formatter.js

@@ -42,3 +42,8 @@ "use strict";

var value = valueRaw ? valueRaw.toString().trim() : null;
var hasValue = value && value.length;
if (!hasValue && !options.blankProperties) {
continue;
}
// Add property key

@@ -48,3 +53,3 @@ buffer += ShortcodeFormatter.T_TAG_PROPERTY_SEPARATOR;

if (value && value.length) {
if (hasValue) {
// Value is non empty

@@ -133,5 +138,6 @@ buffer += ShortcodeFormatter.T_TAG_PROPERTY_ASSIGN;

tagName: null,
tagNameMap: {}
tagNameMap: {},
blankProperties: true
};
module.exports = ShortcodeFormatter;

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ 'use strict';

@@ -14,180 +14,180 @@ "use strict";

var Shortcode = function () {
function Shortcode(name, content, properties, isSelfClosing, codeText, offset) {
_classCallCheck(this, Shortcode);
function Shortcode(name, content, properties, isSelfClosing, codeText, offset) {
_classCallCheck(this, Shortcode);
/**
* The tag name.
*
* @type {null|string}
*/
this.name = name || null;
/**
* The tag name.
*
* @type {null|string}
*/
this.name = name || null;
/**
* Raw content contained within this shortcode.
* Will be NULL for self-closing tags.
*
* @type {null|string}
*/
this.content = typeof content === "undefined" ? null : content;
/**
* Raw content contained within this shortcode.
* Will be NULL for self-closing tags.
*
* @type {null|string}
*/
this.content = typeof content === "undefined" ? null : content;
/**
* Key/value object that holds all properties for this shortcode.
*
* @type {object}
*/
this.properties = properties || {};
/**
* Key/value object that holds all properties for this shortcode.
*
* @type {object}
*/
this.properties = properties || {};
/**
* Indicates whether this is a self-closing tag or not.
*
* @type {boolean}
*/
this.isSelfClosing = !!isSelfClosing;
/**
* Indicates whether this is a self-closing tag or not.
*
* @type {boolean}
*/
this.isSelfClosing = !!isSelfClosing;
/**
* Raw text block that was parsed for this shortcode.
*
* @type {string|null}
*/
this.codeText = codeText || null;
/**
* Raw text block that was parsed for this shortcode.
*
* @type {string|null}
*/
this.codeText = codeText || null;
/**
* Offset, relative to the extractor input string.
*
* @type {number}
*/
this.offset = offset || 0;
}
/**
* Internal helper function: Get the end offset of this shortcode, relative to the extractor input string.
* Offset, relative to the extractor input string.
*
* @returns {*}
* @type {number}
*/
this.offset = offset || 0;
}
/**
* Internal helper function: Get the end offset of this shortcode, relative to the extractor input string.
*
* @returns {*}
*/
_createClass(Shortcode, [{
key: "getEndOffset",
value: function getEndOffset() {
return this.offset + this.codeText.length;
}
/**
* Gets whether this shortcode has a set property with a given `key`.
*
* @param {string} key
* @returns {boolean}
*/
_createClass(Shortcode, [{
key: "getEndOffset",
value: function getEndOffset() {
return this.offset + this.codeText.length;
}
}, {
key: "hasProperty",
value: function hasProperty(key) {
return this.properties && typeof this.properties[key] !== "undefined";
}
/**
* Gets whether this shortcode has a set property with a given `key`.
*
* @param {string} key
* @returns {boolean}
*/
/**
* Get the value of a property.
*
* @param key
* @returns {string|null}
*/
}, {
key: "hasProperty",
value: function hasProperty(key) {
return this.properties && typeof this.properties[key] !== "undefined";
}
}, {
key: "getProperty",
value: function getProperty(key) {
return this.hasProperty(key) ? this.properties[key] : null;
}
/**
* Get the value of a property.
*
* @param key
* @returns {string|null}
*/
/**
* Add or update a property.
*
* @param {string} key
* @param value
*/
}, {
key: "getProperty",
value: function getProperty(key) {
return this.hasProperty(key) ? this.properties[key] : null;
}
}, {
key: "setProperty",
value: function setProperty(key, value) {
this.properties[key] = value;
}
/**
* Add or update a property.
*
* @param {string} key
* @param value
*/
/**
* Appends a given `shortcode` to this shortcode's content, by rendering the input as a string.
*
* @param {Shortcode} shortcode
*/
}, {
key: "setProperty",
value: function setProperty(key, value) {
this.properties[key] = value;
}
}, {
key: "addChild",
value: function addChild(shortcode) {
this.appendContent(shortcode.stringify());
}
/**
* Appends a given `shortcode` to this shortcode's content, by rendering the input as a string.
*
* @param {Shortcode} shortcode
*/
/**
* Appends given `content` to the end of this shortcode's content.
*
* @param {string} content
*/
}, {
key: "addChild",
value: function addChild(shortcode) {
this.appendContent(shortcode.stringify());
}
}, {
key: "appendContent",
value: function appendContent(content) {
if (!this.content) {
this.content = "";
}
/**
* Appends given `content` to the end of this shortcode's content.
*
* @param {string} content
*/
this.content += content;
}
}, {
key: "appendContent",
value: function appendContent(content) {
if (!this.content) {
this.content = "";
}
/**
* Renders this Shortcode as formatted code, in shortcode style.
*
* @returns {string}
*/
this.content += content;
}
}, {
key: "stringify",
value: function stringify() {
return ShortcodeFormatter.stringify(this);
}
/**
* Renders this Shortcode as formatted code, in shortcode style.
*
* @returns {string}
*/
/**
* Renders this Shortcode as formatted code, in HTML style.
*
* @param {string|null} tagName Optional HTML tag name override.
* @param {object} options Formatter options
* @return {*}
*/
}, {
key: "stringify",
value: function stringify() {
return ShortcodeFormatter.stringify(this);
}
}, {
key: "stringifyAsHtml",
value: function stringifyAsHtml(tagName, options) {
var optionsMerged = {
asHtml: true,
tagName: tagName ? tagName : null
};
/**
* Renders this Shortcode as formatted code, in HTML style.
*
* @param {string|null} tagName Optional HTML tag name override.
* @param {object} options Formatter options
* @return {*}
*/
if (options) {
optionsMerged = Object.assign({}, options, optionsMerged);
}
}, {
key: "stringifyAsHtml",
value: function stringifyAsHtml(tagName, options) {
var optionsMerged = {
asHtml: true,
tagName: tagName ? tagName : null
};
return ShortcodeFormatter.stringify(this, optionsMerged);
}
if (options) {
optionsMerged = Object.assign({}, options, optionsMerged);
}
/**
* Converts this item to string.
*
* @returns {string}
*/
return ShortcodeFormatter.stringify(this, optionsMerged);
}
}, {
key: "toString",
value: function toString() {
return this.stringify();
}
}]);
/**
* Converts this item to string.
*
* @returns {string}
*/
return Shortcode;
}, {
key: "toString",
value: function toString() {
return this.stringify();
}
}]);
return Shortcode;
}();
module.exports = Shortcode;
{
"name": "shortcode-tree",
"version": "1.4.11",
"version": "1.4.12",
"description": "Parser library for reading short codes (BB codes) into a tree structure",

@@ -14,7 +14,8 @@ "main": "dist/index.js",

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"chai": "^4.1.2",
"mocha": "^4.0.1"
},
"dependencies": {
},
"dependencies": {},
"repository": {

@@ -21,0 +22,0 @@ "type": "git",

@@ -0,0 +0,0 @@ # shortcode-tree

@@ -0,0 +0,0 @@ let ShortcodeExtractor = require('../src').ShortcodeExtractor;

@@ -31,2 +31,10 @@ let Shortcode = require('../src').Shortcode;

it('stringifies a simple shortcode, but leaves out value-less properties with `blankProperties` config set to false', function () {
let testInput = new Shortcode("b", "Bold text", {"checked": null});
let expectedOutput = "[b]Bold text[/b]";
let actualOutput = ShortcodeFormatter.stringify(testInput, { blankProperties: false });
expect(actualOutput).to.equal(expectedOutput);
});
it('stringifies a self-closing shortcode', function () {

@@ -33,0 +41,0 @@ let testInput = new Shortcode("img", null, {}, true);

@@ -0,0 +0,0 @@ let ShortcodeParser = require('../src').ShortcodeParser;

@@ -0,0 +0,0 @@ let ShortcodeTree = require('../src').ShortcodeTree;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc