mark-to-json
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -0,3 +1,13 @@ | ||
<a name="0.2.0"></a> | ||
# [0.2.0](https://github.com/lbwa/mark-to-json/compare/v0.1.1...v0.2.0) (2018-08-25) | ||
### Features | ||
* support multiple-level directories ([2f0c142](https://github.com/lbwa/mark-to-json/commit/2f0c142)) | ||
<a name="0.1.1"></a> | ||
## [0.1.1](https://github.com/lbw/mark-to-json/compare/v0.1.0...v0.1.1) (2018-08-21) | ||
## [0.1.1](https://github.com/lbwa/mark-to-json/compare/v0.1.0...v0.1.1) (2018-08-21) | ||
@@ -7,3 +17,3 @@ | ||
* remove redundant code ([c4cf69f](https://github.com/lbw/mark-to-json/commit/c4cf69f)) | ||
* remove redundant code ([c4cf69f](https://github.com/lbwa/mark-to-json/commit/c4cf69f)) | ||
@@ -13,3 +23,3 @@ | ||
<a name="0.1.0"></a> | ||
# [0.1.0](https://github.com/lbw/mark-to-json/compare/0713828...v0.1.0) (2018-08-21) | ||
# [0.1.0](https://github.com/lbwa/mark-to-json/compare/0713828...v0.1.0) (2018-08-21) | ||
@@ -19,6 +29,6 @@ | ||
* adjust `md` to `token`, complete prototype ([47e6a5e](https://github.com/lbw/mark-to-json/commit/47e6a5e)) | ||
* core features ([0713828](https://github.com/lbw/mark-to-json/commit/0713828)) | ||
* adjust `md` to `token`, complete prototype ([47e6a5e](https://github.com/lbwa/mark-to-json/commit/47e6a5e)) | ||
* core features ([0713828](https://github.com/lbwa/mark-to-json/commit/0713828)) | ||
@@ -8,2 +8,3 @@ export interface options { | ||
contentKey?: string | ||
filter?: Function | ||
} |
@@ -10,3 +10,3 @@ "use strict"; | ||
class App { | ||
constructor({ token, dest = `${process.cwd()}/default.json`, extraHeader = {}, contentKey = 'content' }) { | ||
constructor({ token, dest = `${process.cwd()}/default.json`, extraHeader = {}, contentKey = 'content', filter }) { | ||
if (!token) { | ||
@@ -22,2 +22,7 @@ logger_1.default.error(`[fatal]`, 'Parser should have a token !'); | ||
}); | ||
if (filter && (typeof filter === 'function')) { | ||
const normalized = filter(this.schema); | ||
if (normalized) | ||
this.schema = normalized; | ||
} | ||
this.writeStream(); | ||
@@ -24,0 +29,0 @@ } |
@@ -10,3 +10,38 @@ const Mtj = require('../lib/index'); | ||
}, | ||
contentKey: 'content' | ||
contentKey: 'content', | ||
filter(schema) { | ||
schema.date = formatDate(schema.date); | ||
} | ||
}); | ||
function formatDate(date) { | ||
const convert = [ | ||
null, | ||
'JAN', | ||
'FEB', | ||
'MAR', | ||
'APR', | ||
'MAY', | ||
'JUN', | ||
'JUL', | ||
'AUG', | ||
'SEP', | ||
'OCT', | ||
'NOV', | ||
'DEC' | ||
]; | ||
if (date instanceof Date) { | ||
const year = date.getFullYear(); | ||
const month = date.getMonth() + 1; | ||
const day = date.getDate().toLocaleString('zh', { minimumIntegerDigits: 2, useGrouping: false }); | ||
return `${year} ${convert[month]} ${day}`; | ||
} | ||
const reg = /^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/; | ||
const format = reg.exec(date); | ||
if (format[0]) { | ||
return format[0]; | ||
} | ||
else { | ||
console.warn('[Format date]: Formatting failed !'); | ||
return date; | ||
} | ||
} |
@@ -19,3 +19,4 @@ import reader = require('gray-matter') | ||
extraHeader = {}, | ||
contentKey = 'content' | ||
contentKey = 'content', | ||
filter | ||
}: types.options) { | ||
@@ -33,2 +34,11 @@ if (!token) { | ||
}) | ||
if (filter && (typeof filter === 'function')) { | ||
const normalized = filter(this.schema) | ||
// 若 filter 存在返回值,那么使用该返回值,否则因为是传入的引用类型值,那么将使用原 | ||
// this.schema | ||
if (normalized) this.schema = normalized | ||
} | ||
this.writeStream() | ||
@@ -35,0 +45,0 @@ } |
{ | ||
"name": "mark-to-json", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "parse markdown to json", | ||
@@ -5,0 +5,0 @@ "main": "dist/lib/index.js", |
@@ -22,4 +22,7 @@ # mark-to-json [![NpmVersion](https://img.shields.io/npm/v/mark-to-json.svg?style=flat-square)](https://www.npmjs.com/package/mark-to-json) [![NodeVersion](https://img.shields.io/node/v/mark-to-json.svg?style=flat-square)](https://www.npmjs.com/package/mark-to-json) | ||
| extraHeader | false | `{}` | It will be mix in JSON file if you want to add some extra data to JSON static file | | ||
| contentKey | false | `content` | It will be the key of markdown content part in JSON static file| | ||
| contentKey | false | `content` | It will be the key of markdown content part in JSON static file | | ||
| filter | false || It can be used to change output schema ([sample][filter-sample]). | | ||
[filter-sample]:./samples/index.ts | ||
## Sample | ||
@@ -36,3 +39,9 @@ | ||
}, | ||
contentKey: 'content' | ||
contentKey: 'content', | ||
// Only work with one parameter: schema | ||
filter (schema) { | ||
// do something | ||
// `return` is optional | ||
} | ||
}) | ||
@@ -45,3 +54,3 @@ | ||
[here]:https://github.com/lbwa/mark-to-json/tree/master/samples | ||
[here]:https://github.com/lbwa/mark-to-json/tree/master/samples/nested | ||
@@ -48,0 +57,0 @@ ## Changelog |
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
9488
201
57