Comparing version 1.5.11 to 1.6.0
@@ -75,4 +75,48 @@ "use strict"; | ||
/** | ||
* @param {Array|Object|String} data The input JSON data. | ||
* @param {String} prefix A snippet to add before each line. | ||
* @return {Promise.<String, Error>} The generated markdown result. | ||
*/ | ||
json2md.async = function (data, prefix, _type) { | ||
return Promise.resolve().then(function () { | ||
prefix = prefix || ""; | ||
if (typeof data === "string" || typeof data === "number") { | ||
return indento(data, 1, prefix); | ||
} | ||
var content = []; | ||
// Handle arrays | ||
if (Array.isArray(data)) { | ||
var promises = data.map(function (d, index) { | ||
return Promise.resolve().then(function () { | ||
return json2md.async(d, "", _type); | ||
}).then(function (result) { | ||
return indento(result, 1, prefix); | ||
}).then(function (result) { | ||
content[index] = result; | ||
}); | ||
}); | ||
return Promise.all(promises).then(function () { | ||
return content.join("\n"); | ||
}); | ||
} else { | ||
var type = Object.keys(data)[0], | ||
func = converters[_type || type]; | ||
if (typeof func === "function") { | ||
return Promise.resolve().then(function () { | ||
return func(_type ? data : data[type], json2md); | ||
}).then(function (result) { | ||
return indento(result, 1, prefix) + "\n"; | ||
}); | ||
} | ||
throw new Error("There is no such converter: " + type); | ||
} | ||
}); | ||
}; | ||
json2md.converters = converters; | ||
module.exports = json2md; |
{ | ||
"name": "json2md", | ||
"version": "1.5.11", | ||
"version": "1.6.0", | ||
"description": "A JSON to Markdown converter.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. --> | ||
readmeTitle += ` [![Version](https://img.shields.io/npm/v/${_.pack.name}.svg)](https://www.npmjs.com/package/${_.pack.name})` | ||
readmeTitle += ` [![Downloads](https://img.shields.io/npm/dt/${_.pack.name}.svg)](https://www.npmjs.com/package/${_.pack.name})` | ||
[![json2md](http://i.imgur.com/uj64JFw.png)](#) | ||
@@ -8,3 +11,3 @@ | ||
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](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) | ||
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) | ||
@@ -163,4 +166,14 @@ > A JSON to Markdown converter. | ||
### async | ||
#### Params | ||
- **Array|Object|String** `data`: The input JSON data. | ||
- **String** `prefix`: A snippet to add before each line. | ||
#### Return | ||
- **Promise.\<String, Error>** The generated markdown result. | ||
## :yum: How to contribute | ||
@@ -177,2 +190,3 @@ Have an idea? Found a bug? See [how to contribute][contributing]. | ||
- Starring and sharing the projects you like :rocket: | ||
@@ -186,2 +200,3 @@ - [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book: | ||
Thanks! :heart: | ||
@@ -209,10 +224,11 @@ | ||
[badge_patreon]: http://ionicabizau.github.io/badges/patreon.svg | ||
[badge_amazon]: http://ionicabizau.github.io/badges/amazon.svg | ||
[badge_paypal]: http://ionicabizau.github.io/badges/paypal.svg | ||
[badge_paypal_donate]: http://ionicabizau.github.io/badges/paypal_donate.svg | ||
[badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg | ||
[badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg | ||
[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg | ||
[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg | ||
[patreon]: https://www.patreon.com/ionicabizau | ||
[amazon]: http://amzn.eu/hRo9sIZ | ||
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW | ||
[donate-now]: http://i.imgur.com/6cMbHOC.png | ||
@@ -219,0 +235,0 @@ [license]: http://showalicense.com/?fullname=Ionic%C4%83%20Biz%C4%83u%20%3Cbizauionica%40gmail.com%3E%20(https%3A%2F%2Fionicabizau.net)&year=2015#license-mit |
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
30763
292
234