Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json2md

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json2md - npm Package Compare versions

Comparing version 1.5.3 to 1.5.4

80

dist/json2md.min.js

@@ -1,1 +0,79 @@

"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol?"symbol":typeof n};!function(n){if("object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.json2md=n()}}(function(){return function n(e,r,t){function o(u,f){if(!r[u]){if(!e[u]){var c="function"==typeof require&&require;if(!f&&c)return c(u,!0);if(i)return i(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var s=r[u]={exports:{}};e[u][0].call(s.exports,function(n){var r=e[u][1][n];return o(r?r:n)},s,s.exports,n,e,r,t)}return r[u].exports}for(var i="function"==typeof require&&require,u=0;u<t.length;u++)o(t[u]);return o}({1:[function(n,e){var r=e.exports={},t=function(n){return function(e,r){return"#".repeat(n)+" "+r(e)}},o=function u(n,e,r){var t=n;return"string"==typeof n&&(t=n.split("\n")),r?t.length<=1?t.join("\n"):t[0]+"\n"+u(t.slice(1),e,!1):t.map(function(n){return" ".repeat(e)+n}).join("\n")},i=function(n){var e={strong:"**",italic:"*"};return n.replace(/\<\/?strong\>/gi,e.strong).replace(/\<\/?bold\>/gi,e.strong).replace(/\<\/?em\>/gi,e.italic).replace(/\<\/?italic\>/gi,e.italic)};r.h1=t(1),r.h2=t(2),r.h3=t(3),r.h4=t(4),r.h5=t(5),r.h6=t(6),r.blockquote=function(n,e){return e(n,"> ")+"\n"},r.img=function(n,e){return Array.isArray(n)?e(n,"","img"):"string"==typeof n?r.img({source:n,title:""}):(n.title=n.title||"","!["+n.title+"]("+n.source+")\n")},r.ul=function(n,e){for(var r="",t=0;t<n.length;++t)r+="\n - "+i(o(e(n[t]),4,!0));return r+"\n"},r.ol=function(n,e){for(var r="",t=0;t<n.length;++t)r+="\n "+(t+1)+". "+i(o(e(n[t]),4,!0));return r+"\n"},r.code=function(n){var e="```"+(n.language||"")+"\n";return e+=Array.isArray(n.content)?n.content.join("\n"):n.content,e+="\n```"},r.p=function(n,e){return i(e(n,"\n"))+"\n"},r.table=function(n,e){if("object"!=("undefined"==typeof n?"undefined":_typeof(n))||!n.hasOwnProperty("headers")||!n.hasOwnProperty("rows"))return"";var r=n.headers.join(" | "),t=n.headers.map(function(){return"---"}).join(" | "),o=n.rows.map(function(r){return Array.isArray(r)?r.map(function(n){return i(e(n))}).join(" | "):n.headers.map(function(n){return i(e(r[n]))}).join(" | ")}).join("\n");return[r,t,o].join("\n")}},{}],2:[function(n,e){function r(n,e,o){if(e=e||"","string"==typeof n||"number"==typeof n)return e+n;var i=[];if(Array.isArray(n)){for(var u=0;u<n.length;++u)i.push(e+r(n[u],"",o));return i.join("\n")}var f=Object.keys(n)[0],c=t[o||f];if("function"==typeof c)return c(o?n:n[f],r);throw new Error("There is no such converter: "+f)}var t=n("./converters");r.converters=t,e.exports=r},{"./converters":1}]},{},[2])(2)});
"use strict";
var _typeof2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = "function" == typeof Symbol && "symbol" == _typeof2(Symbol.iterator) ? function (n) {
return typeof n === "undefined" ? "undefined" : _typeof2(n);
} : function (n) {
return n && "function" == typeof Symbol && n.constructor === Symbol ? "symbol" : typeof n === "undefined" ? "undefined" : _typeof2(n);
};!function (n) {
if ("object" === ("undefined" == typeof exports ? "undefined" : _typeof(exports)) && "undefined" != typeof module) module.exports = n();else if ("function" == typeof define && define.amd) define([], n);else {
var e;e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this, e.json2md = n();
}
}(function () {
return function n(e, r, t) {
function o(u, f) {
if (!r[u]) {
if (!e[u]) {
var c = "function" == typeof require && require;if (!f && c) return c(u, !0);if (i) return i(u, !0);var a = new Error("Cannot find module '" + u + "'");throw a.code = "MODULE_NOT_FOUND", a;
}var s = r[u] = { exports: {} };e[u][0].call(s.exports, function (n) {
var r = e[u][1][n];return o(r ? r : n);
}, s, s.exports, n, e, r, t);
}return r[u].exports;
}for (var i = "function" == typeof require && require, u = 0; u < t.length; u++) {
o(t[u]);
}return o;
}({ 1: [function (n, e) {
var r = e.exports = {},
t = function t(n) {
return function (e, r) {
return "#".repeat(n) + " " + r(e);
};
},
o = function u(n, e, r) {
var t = n;return "string" == typeof n && (t = n.split("\n")), r ? t.length <= 1 ? t.join("\n") : t[0] + "\n" + u(t.slice(1), e, !1) : t.map(function (n) {
return " ".repeat(e) + n;
}).join("\n");
},
i = function i(n) {
var e = { strong: "**", italic: "*" };return n.replace(/\<\/?strong\>/gi, e.strong).replace(/\<\/?bold\>/gi, e.strong).replace(/\<\/?em\>/gi, e.italic).replace(/\<\/?italic\>/gi, e.italic);
};r.h1 = t(1), r.h2 = t(2), r.h3 = t(3), r.h4 = t(4), r.h5 = t(5), r.h6 = t(6), r.blockquote = function (n, e) {
return e(n, "> ") + "\n";
}, r.img = function (n, e) {
return Array.isArray(n) ? e(n, "", "img") : "string" == typeof n ? r.img({ source: n, title: "" }) : (n.title = n.title || "", "![" + n.title + "](" + n.source + ")\n");
}, r.ul = function (n, e) {
for (var r = "", t = 0; t < n.length; ++t) {
r += "\n - " + i(o(e(n[t]), 4, !0));
}return r + "\n";
}, r.ol = function (n, e) {
for (var r = "", t = 0; t < n.length; ++t) {
r += "\n " + (t + 1) + ". " + i(o(e(n[t]), 4, !0));
}return r + "\n";
}, r.code = function (n) {
var e = "```" + (n.language || "") + "\n";return e += Array.isArray(n.content) ? n.content.join("\n") : n.content, e += "\n```";
}, r.p = function (n, e) {
return i(e(n, "\n")) + "\n";
}, r.table = function (n, e) {
if ("object" != ("undefined" == typeof n ? "undefined" : _typeof(n)) || !n.hasOwnProperty("headers") || !n.hasOwnProperty("rows")) return "";var r = n.headers.join(" | "),
t = n.headers.map(function () {
return "---";
}).join(" | "),
o = n.rows.map(function (r) {
return Array.isArray(r) ? r.map(function (n) {
return i(e(n));
}).join(" | ") : n.headers.map(function (n) {
return i(e(r[n]));
}).join(" | ");
}).join("\n");return [r, t, o].join("\n");
};
}, {}], 2: [function (n, e) {
function r(n, e, o) {
if (e = e || "", "string" == typeof n || "number" == typeof n) return e + n;var i = [];if (Array.isArray(n)) {
for (var u = 0; u < n.length; ++u) {
i.push(e + r(n[u], "", o));
}return i.join("\n");
}var f = Object.keys(n)[0],
c = t[o || f];if ("function" == typeof c) return c(o ? n : n[f], r);throw new Error("There is no such converter: " + f);
}var t = n("./converters");r.converters = t, e.exports = r;
}, { "./converters": 1 }] }, {}, [2])(2);
});

84

lib/converters.js
"use strict";
const converters = module.exports = {};
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
let generateHeader = repeat => {
return (input, json2md) => {
var converters = module.exports = {};
var generateHeader = function generateHeader(repeat) {
return function (input, json2md) {
return "#".repeat(repeat) + " " + json2md(input);

@@ -11,4 +13,4 @@ };

let indent = (content, spaces, ignoreFirst) => {
let lines = content;
var indent = function indent(content, spaces, ignoreFirst) {
var lines = content;

@@ -26,19 +28,16 @@ if (typeof content === "string") {

return lines.map(c => " ".repeat(spaces) + c).join("\n");
}
return lines.map(function (c) {
return " ".repeat(spaces) + c;
}).join("\n");
};
let parseTextFormat = text => {
var parseTextFormat = function parseTextFormat(text) {
let formats = {
strong: "**"
, italic: "*"
var formats = {
strong: "**",
italic: "*"
};
return text
.replace(/\<\/?strong\>/gi, formats.strong)
.replace(/\<\/?bold\>/gi, formats.strong)
.replace(/\<\/?em\>/gi, formats.italic)
.replace(/\<\/?italic\>/gi, formats.italic)
;
}
return text.replace(/\<\/?strong\>/gi, formats.strong).replace(/\<\/?bold\>/gi, formats.strong).replace(/\<\/?em\>/gi, formats.italic).replace(/\<\/?italic\>/gi, formats.italic);
};

@@ -53,7 +52,7 @@ // Headings

converters.blockquote = (input, json2md) => {
converters.blockquote = function (input, json2md) {
return json2md(input, "> ") + "\n";
};
converters.img = (input, json2md) => {
converters.img = function (input, json2md) {
if (Array.isArray(input)) {

@@ -69,5 +68,5 @@ return json2md(input, "", "img");

converters.ul = (input, json2md) => {
let c = "";
for (let i = 0; i < input.length; ++i) {
converters.ul = function (input, json2md) {
var c = "";
for (var i = 0; i < input.length; ++i) {
c += "\n - " + parseTextFormat(indent(json2md(input[i]), 4, true));

@@ -78,5 +77,5 @@ }

converters.ol = (input, json2md) => {
let c = "";
for (let i = 0; i < input.length; ++i) {
converters.ol = function (input, json2md) {
var c = "";
for (var i = 0; i < input.length; ++i) {
c += "\n " + (i + 1) + ". " + parseTextFormat(indent(json2md(input[i]), 4, true));

@@ -87,4 +86,4 @@ }

converters.code = (input, json2md) => {
let c = "```" + (input.language || "") + "\n";
converters.code = function (input, json2md) {
var c = "```" + (input.language || "") + "\n";
if (Array.isArray(input.content)) {

@@ -99,24 +98,25 @@ c += input.content.join("\n");

converters.p = (input, json2md) => {
converters.p = function (input, json2md) {
return parseTextFormat(json2md(input, "\n")) + "\n";
};
converters.table = (input, json2md) => {
converters.table = function (input, json2md) {
if (typeof input != "object"
|| !input.hasOwnProperty("headers")
|| !input.hasOwnProperty("rows")) {
if ((typeof input === "undefined" ? "undefined" : _typeof(input)) != "object" || !input.hasOwnProperty("headers") || !input.hasOwnProperty("rows")) {
return "";
}
let header = input.headers.join(" | ")
, spaces = input.headers.map(() => "---").join(" | ")
, data = input.rows.map(r =>
Array.isArray(r)
? r.map(el => parseTextFormat(json2md(el))).join(" | ")
: input.headers.map(h => parseTextFormat(json2md(r[h]))).join(" | ")
).join("\n")
;
var header = input.headers.join(" | "),
spaces = input.headers.map(function () {
return "---";
}).join(" | "),
data = input.rows.map(function (r) {
return Array.isArray(r) ? r.map(function (el) {
return parseTextFormat(json2md(el));
}).join(" | ") : input.headers.map(function (h) {
return parseTextFormat(json2md(r[h]));
}).join(" | ");
}).join("\n");
return [header, spaces, data].join("\n");
};
};
"use strict";
const converters = require("./converters");
var converters = require("./converters");

@@ -55,7 +55,7 @@ /**

let content = [];
var content = [];
// Handle arrays
if (Array.isArray(data)) {
for (let i = 0; i < data.length; ++i) {
for (var i = 0; i < data.length; ++i) {
content.push(prefix + json2md(data[i], "", _type));

@@ -65,5 +65,4 @@ }

} else {
let type = Object.keys(data)[0]
, func = converters[_type || type]
;
var type = Object.keys(data)[0],
func = converters[_type || type];

@@ -79,2 +78,2 @@ if (typeof func === "function") {

module.exports = json2md;
module.exports = json2md;
{
"name": "json2md",
"version": "1.5.3",
"version": "1.5.4",
"description": "A JSON to Markdown converter.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -6,3 +6,3 @@

[![PayPal](https://img.shields.io/badge/%24-paypal-f39c12.svg)][paypal-donations] [![AMA](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/json2md.svg)](https://www.npmjs.com/package/json2md) [![Downloads](https://img.shields.io/npm/dt/json2md.svg)](https://www.npmjs.com/package/json2md) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
[![Patreon](https://img.shields.io/badge/Support%20me%20on-Patreon-%23e6461a.svg)][paypal-donations] [![PayPal](https://img.shields.io/badge/%24-paypal-f39c12.svg)][paypal-donations] [![AMA](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/json2md.svg)](https://www.npmjs.com/package/json2md) [![Downloads](https://img.shields.io/npm/dt/json2md.svg)](https://www.npmjs.com/package/json2md) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)

@@ -149,2 +149,11 @@ > A JSON to Markdown converter.

## :moneybag: Donations
Another way to support the development of my open-source modules is
to [set up a recurring donation, via Patreon][patreon]. :rocket:
[PayPal donations][paypal-donations] are appreciated too! Each dollar helps.
Thanks! :heart:
## :dizzy: Where is this library used?

@@ -162,2 +171,3 @@ If you are using this library in one of your projects, add it in this list. :sparkles:

[patreon]: https://www.patreon.com/ionicabizau
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW

@@ -164,0 +174,0 @@ [donate-now]: http://i.imgur.com/6cMbHOC.png

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc