editorjs-viewer
Advanced tools
Comparing version 2.0.1 to 2.0.2
57
index.js
"use strict"; | ||
exports.__esModule = true; | ||
exports.parser = void 0; | ||
// load default configuration | ||
var default_1 = require("./lib/default"); | ||
// | ||
var parser_1 = require("./src/parser"); | ||
var parser = new parser_1["default"](default_1.configuration); | ||
exports.parser = parser; | ||
/** | ||
* This class used to turn json data to HTML data with the following steps | ||
* 1. take the block data that returned from editorjs value | ||
* 2. take the configuration ( criteria how should we turn your json data to HTML ) -> optional | ||
* 3. if configuration sent then update the existing configuration with the new one check user method `checkConfig` | ||
* 4. loop to all of the item block | ||
* 5. parse to html using `toHTML()` method then return it to the user | ||
*/ | ||
var Parser = /** @class */ (function () { | ||
function Parser(conf) { | ||
this.result = []; | ||
this.conf = {}; | ||
this.conf = conf; | ||
} | ||
/** | ||
* Check if user sending the configuration for the elements | ||
* if user send it then update the existing configuration with the new one | ||
* but if user doens't send it just let it as what it is | ||
* @param {Elements} conf -> configuration for parsing data from json to HTML tag | ||
*/ | ||
Parser.prototype.checkConfig = function (conf) { | ||
var _this = this; | ||
// loop to all of the configuration that user send | ||
Object.keys(conf).forEach(function (key) { | ||
// if user send new configuration then save it to conf variable | ||
// if user send configuration but already exists then update it with the new one | ||
_this.conf[key] = conf[key]; | ||
}); | ||
}; | ||
/** | ||
* parsing json data to HTML tag | ||
* @param {Block[]} blocks -> array of block from return value editor.js | ||
* @param {Elements} config -> tag configuration see the docummentation | ||
*/ | ||
Parser.prototype.toHTML = function (blocks, config) { | ||
var _this = this; | ||
// if user send argument config then update the existing config with the new one | ||
if (config !== undefined) { | ||
this.checkConfig(config); | ||
} | ||
// loop to all of the editor block | ||
blocks.forEach(function (items) { | ||
_this.result.push(_this.conf[items.type].onReturn(items)); | ||
}); | ||
// return parsed html to the user | ||
return this.result.join(""); | ||
}; | ||
return Parser; | ||
}()); | ||
exports["default"] = Parser; |
{ | ||
"name": "editorjs-viewer", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Extremly easy turn JSON data to HTML from editor.js dynamicly", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,3 +15,2 @@ // data types | ||
protected result : string[] = [] | ||
protected conf : Elements = {} | ||
@@ -45,4 +44,7 @@ | ||
*/ | ||
public toHTML(blocks : Block[], config?: Elements) : string{ | ||
toHTML(blocks : Block[], config?: Elements) : string{ | ||
// define result variable | ||
let result : string[] = [] | ||
// if user send argument config then update the existing config with the new one | ||
@@ -55,3 +57,3 @@ if(config !== undefined){ | ||
blocks.forEach((items : Block) => { | ||
this.result.push(this.conf[items.type].onReturn(items)) | ||
result.push(this.conf[items.type].onReturn(items)) | ||
}) | ||
@@ -61,3 +63,3 @@ | ||
return this.result.join("") | ||
return result.join("") | ||
@@ -64,0 +66,0 @@ } |
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
38394
21
537