Socket
Socket
Sign inDemoInstall

editorjs-viewer

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.0.3

57

index.js
"use strict";
exports.__esModule = true;
/**
* 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;
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;

@@ -11,3 +11,2 @@ import { Block, Elements } from './type';

declare class Parser {
protected result: string[];
protected conf: Elements;

@@ -14,0 +13,0 @@ constructor(conf: Elements);

7

lib/parser.js

@@ -13,3 +13,2 @@ "use strict";

constructor(conf) {
this.result = [];
this.conf = {};

@@ -38,2 +37,4 @@ this.conf = conf;

toHTML(blocks, config) {
// define result variable
let result = [];
// if user send argument config then update the existing config with the new one

@@ -45,8 +46,8 @@ if (config !== undefined) {

blocks.forEach((items) => {
this.result.push(this.conf[items.type].onReturn(items));
result.push(this.conf[items.type].onReturn(items));
});
// return parsed html to the user
return this.result.join("");
return result.join("");
}
}
exports.default = Parser;
{
"name": "editorjs-viewer",
"version": "2.0.2",
"version": "2.0.3",
"description": "Extremly easy turn JSON data to HTML from editor.js dynamicly",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "tsc test.ts && node test",
"build" : "tsc && tsc index.ts"

@@ -9,0 +9,0 @@ },

@@ -13,3 +13,2 @@ "use strict";

function Parser(conf) {
this.result = [];
this.conf = {};

@@ -40,2 +39,4 @@ this.conf = conf;

var _this = this;
// define result variable
var result = [];
// if user send argument config then update the existing config with the new one

@@ -47,6 +48,6 @@ if (config !== undefined) {

blocks.forEach(function (items) {
_this.result.push(_this.conf[items.type].onReturn(items));
result.push(_this.conf[items.type].onReturn(items));
});
// return parsed html to the user
return this.result.join("");
return result.join("");
};

@@ -53,0 +54,0 @@ return Parser;

@@ -43,3 +43,3 @@ // data types

*/
toHTML(blocks : Block[], config?: Elements) : string{
public toHTML(blocks : Block[], config?: Elements) : string{

@@ -46,0 +46,0 @@ // define result variable

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