remark-frontmatter
Advanced tools
Comparing version 1.2.0 to 1.2.1
66
index.js
@@ -1,21 +0,21 @@ | ||
'use strict'; | ||
'use strict' | ||
var xtend = require('xtend'); | ||
var matters = require('./lib/matters'); | ||
var parse = require('./lib/parse'); | ||
var compile = require('./lib/compile'); | ||
var xtend = require('xtend') | ||
var matters = require('./lib/matters') | ||
var parse = require('./lib/parse') | ||
var compile = require('./lib/compile') | ||
module.exports = frontmatter; | ||
module.exports = frontmatter | ||
function frontmatter(options) { | ||
var parser = this.Parser; | ||
var compiler = this.Compiler; | ||
var config = matters(options || ['yaml']); | ||
var parser = this.Parser | ||
var compiler = this.Compiler | ||
var config = matters(options || ['yaml']) | ||
if (isRemarkParser(parser)) { | ||
attachParser(parser, config); | ||
attachParser(parser, config) | ||
} | ||
if (isRemarkCompiler(compiler)) { | ||
attachCompiler(compiler, config); | ||
attachCompiler(compiler, config) | ||
} | ||
@@ -25,48 +25,40 @@ } | ||
function attachParser(parser, matters) { | ||
var proto = parser.prototype; | ||
var tokenizers = wrap(parse, matters); | ||
var names = []; | ||
var key; | ||
var proto = parser.prototype | ||
var tokenizers = wrap(parse, matters) | ||
var names = [] | ||
var key | ||
for (key in tokenizers) { | ||
names.push(key); | ||
names.push(key) | ||
} | ||
proto.blockMethods = names.concat(proto.blockMethods); | ||
proto.blockTokenizers = xtend(tokenizers, proto.blockTokenizers); | ||
proto.blockMethods = names.concat(proto.blockMethods) | ||
proto.blockTokenizers = xtend(tokenizers, proto.blockTokenizers) | ||
} | ||
function attachCompiler(compiler, matters) { | ||
var proto = compiler.prototype; | ||
proto.visitors = xtend(wrap(compile, matters), proto.visitors); | ||
var proto = compiler.prototype | ||
proto.visitors = xtend(wrap(compile, matters), proto.visitors) | ||
} | ||
function wrap(func, matters) { | ||
var result = {}; | ||
var length = matters.length; | ||
var index = -1; | ||
var tuple; | ||
var result = {} | ||
var length = matters.length | ||
var index = -1 | ||
var tuple | ||
while (++index < length) { | ||
tuple = func(matters[index]); | ||
result[tuple[0]] = tuple[1]; | ||
tuple = func(matters[index]) | ||
result[tuple[0]] = tuple[1] | ||
} | ||
return result; | ||
return result | ||
} | ||
function isRemarkParser(parser) { | ||
return Boolean( | ||
parser && | ||
parser.prototype && | ||
parser.prototype.blockTokenizers | ||
); | ||
return Boolean(parser && parser.prototype && parser.prototype.blockTokenizers) | ||
} | ||
function isRemarkCompiler(compiler) { | ||
return Boolean( | ||
compiler && | ||
compiler.prototype && | ||
compiler.prototype.visitors | ||
); | ||
return Boolean(compiler && compiler.prototype && compiler.prototype.visitors) | ||
} |
@@ -1,19 +0,19 @@ | ||
'use strict'; | ||
'use strict' | ||
var fence = require('./fence'); | ||
var fence = require('./fence') | ||
module.exports = create; | ||
module.exports = create | ||
function create(matter) { | ||
var type = matter.type; | ||
var open = fence(matter, 'open'); | ||
var close = fence(matter, 'close'); | ||
var type = matter.type | ||
var open = fence(matter, 'open') | ||
var close = fence(matter, 'close') | ||
frontmatter.displayName = type + 'FrontMatter'; | ||
frontmatter.displayName = type + 'FrontMatter' | ||
return [type, frontmatter]; | ||
return [type, frontmatter] | ||
function frontmatter(node) { | ||
return open + (node.value ? '\n' + node.value : '') + '\n' + close; | ||
return open + (node.value ? '\n' + node.value : '') + '\n' + close | ||
} | ||
} |
@@ -1,18 +0,18 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = fence; | ||
module.exports = fence | ||
function fence(matter, prop) { | ||
var marker; | ||
var marker | ||
if (matter.marker) { | ||
marker = pick(matter.marker, prop); | ||
return marker + marker + marker; | ||
marker = pick(matter.marker, prop) | ||
return marker + marker + marker | ||
} | ||
return pick(matter.fence, prop); | ||
return pick(matter.fence, prop) | ||
} | ||
function pick(schema, prop) { | ||
return typeof schema === 'string' ? schema : schema[prop]; | ||
return typeof schema === 'string' ? schema : schema[prop] | ||
} |
@@ -1,8 +0,8 @@ | ||
'use strict'; | ||
'use strict' | ||
var fault = require('fault'); | ||
var fault = require('fault') | ||
module.exports = matters; | ||
module.exports = matters | ||
var own = {}.hasOwnProperty; | ||
var own = {}.hasOwnProperty | ||
@@ -12,45 +12,45 @@ var markers = { | ||
toml: '+' | ||
}; | ||
} | ||
function matters(options) { | ||
var results = []; | ||
var index = -1; | ||
var length; | ||
var results = [] | ||
var index = -1 | ||
var length | ||
/* One preset or matter. */ | ||
if (typeof options === 'string' || !('length' in options)) { | ||
options = [options]; | ||
options = [options] | ||
} | ||
length = options.length; | ||
length = options.length | ||
while (++index < length) { | ||
results[index] = matter(options[index]); | ||
results[index] = matter(options[index]) | ||
} | ||
return results; | ||
return results | ||
} | ||
function matter(option) { | ||
var result = option; | ||
var result = option | ||
if (typeof result === 'string') { | ||
if (!own.call(markers, result)) { | ||
throw fault('Missing matter definition for `%s`', result); | ||
throw fault('Missing matter definition for `%s`', result) | ||
} | ||
result = {type: result, marker: markers[result]}; | ||
result = {type: result, marker: markers[result]} | ||
} else if (typeof result !== 'object') { | ||
throw fault('Expected matter to be an object, not `%j`', result); | ||
throw fault('Expected matter to be an object, not `%j`', result) | ||
} | ||
if (!own.call(result, 'type')) { | ||
throw fault('Missing `type` in matter `%j`', result); | ||
throw fault('Missing `type` in matter `%j`', result) | ||
} | ||
if (!own.call(result, 'fence') && !own.call(result, 'marker')) { | ||
throw fault('Missing `marker` or `fence` in matter `%j`', result); | ||
throw fault('Missing `marker` or `fence` in matter `%j`', result) | ||
} | ||
return result; | ||
return result | ||
} |
@@ -1,31 +0,31 @@ | ||
'use strict'; | ||
'use strict' | ||
var fence = require('./fence'); | ||
var fence = require('./fence') | ||
module.exports = create; | ||
module.exports = create | ||
function create(matter) { | ||
var name = matter.type + 'FrontMatter'; | ||
var open = fence(matter, 'open'); | ||
var close = fence(matter, 'close'); | ||
var newline = '\n'; | ||
var name = matter.type + 'FrontMatter' | ||
var open = fence(matter, 'open') | ||
var close = fence(matter, 'close') | ||
var newline = '\n' | ||
frontmatter.displayName = name; | ||
frontmatter.onlyAtStart = true; | ||
frontmatter.displayName = name | ||
frontmatter.onlyAtStart = true | ||
return [name, frontmatter]; | ||
return [name, frontmatter] | ||
function frontmatter(eat, value, silent) { | ||
var index = open.length; | ||
var offset; | ||
var index = open.length | ||
var offset | ||
if (value.slice(0, index) !== open || value.charAt(index) !== newline) { | ||
return; | ||
return | ||
} | ||
offset = value.indexOf(close, index); | ||
offset = value.indexOf(close, index) | ||
while (offset !== -1 && value.charAt(offset - 1) !== newline) { | ||
index = offset + close.length; | ||
offset = value.indexOf(close, index); | ||
index = offset + close.length | ||
offset = value.indexOf(close, index) | ||
} | ||
@@ -36,3 +36,3 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
@@ -43,5 +43,5 @@ | ||
value: value.slice(open.length + 1, offset - 1) | ||
}); | ||
}) | ||
} | ||
} | ||
} |
{ | ||
"name": "remark-frontmatter", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Frontmatter (yaml, toml, and more) support for remark", | ||
@@ -13,4 +13,4 @@ "license": "MIT", | ||
], | ||
"repository": "wooorm/remark-frontmatter", | ||
"bugs": "https://github.com/wooorm/remark-frontmatter/issues", | ||
"repository": "remarkjs/remark-frontmatter", | ||
"bugs": "https://github.com/remarkjs/remark-frontmatter/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
@@ -30,24 +30,24 @@ "contributors": [ | ||
"devDependencies": { | ||
"browserify": "^14.0.0", | ||
"esmangle": "^1.0.0", | ||
"browserify": "^16.0.0", | ||
"is-hidden": "^1.1.0", | ||
"not": "^0.1.0", | ||
"nyc": "^11.0.2", | ||
"remark": "^8.0.0", | ||
"remark-cli": "^4.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"nyc": "^12.0.0", | ||
"prettier": "^1.14.2", | ||
"remark": "^9.0.0", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.4.0", | ||
"to-vfile": "^2.1.2", | ||
"unified": "^6.1.5", | ||
"xo": "^0.18.0" | ||
"tinyify": "^2.4.3", | ||
"to-vfile": "^5.0.0", | ||
"unified": "^7.0.0", | ||
"xo": "^0.22.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark *.md -qfo", | ||
"build-bundle": "browserify index.js -s remarkFrontmatter > remark-frontmatter.js", | ||
"build-mangle": "esmangle remark-frontmatter.js > remark-frontmatter.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"format": "remark *.md -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s remarkFrontmatter > remark-frontmatter.js", | ||
"build-mangle": "browserify . -s remarkFrontmatter -p tinyify > remark-frontmatter.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test/index.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
}, | ||
@@ -60,4 +60,12 @@ "nyc": { | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"prettier": true, | ||
"esnext": false, | ||
@@ -64,0 +72,0 @@ "rules": { |
@@ -28,8 +28,8 @@ # remark-frontmatter [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat] | ||
```javascript | ||
var vfile = require('to-vfile'); | ||
var report = require('vfile-reporter'); | ||
var unified = require('unified'); | ||
var parse = require('remark-parse'); | ||
var stringify = require('remark-stringify'); | ||
var frontmatter = require('remark-frontmatter'); | ||
var vfile = require('to-vfile') | ||
var report = require('vfile-reporter') | ||
var unified = require('unified') | ||
var parse = require('remark-parse') | ||
var stringify = require('remark-stringify') | ||
var frontmatter = require('remark-frontmatter') | ||
@@ -41,9 +41,9 @@ unified() | ||
.use(logger) | ||
.process(vfile.readSync('example.md'), function (err, file) { | ||
console.log(String(file)); | ||
console.error(report(err || file)); | ||
}); | ||
.process(vfile.readSync('example.md'), function(err, file) { | ||
console.log(String(file)) | ||
console.error(report(err || file)) | ||
}) | ||
function logger() { | ||
return console.dir; | ||
return console.dir | ||
} | ||
@@ -191,9 +191,17 @@ ``` | ||
* [`remark-github`](https://github.com/wooorm/remark-github) | ||
* [`remark-github`](https://github.com/remarkjs/remark-github) | ||
— Auto-link references like in GitHub issues, PRs, and comments | ||
* [`remark-math`](https://github.com/rokt33r/remark-math) | ||
— Math support | ||
* [`remark-yaml-config`](https://github.com/wooorm/remark-yaml-config) | ||
* [`remark-yaml-config`](https://github.com/remarkjs/remark-yaml-config) | ||
— Configure remark from YAML configuration | ||
## Contribute | ||
See [`contributing.md` in `remarkjs/remark`][contributing] for ways to get | ||
started. | ||
This organisation has a [Code of Conduct][coc]. By interacting with this | ||
repository, organisation, or community you agree to abide by its terms. | ||
## License | ||
@@ -205,13 +213,13 @@ | ||
[build-badge]: https://img.shields.io/travis/wooorm/remark-frontmatter.svg | ||
[build-badge]: https://img.shields.io/travis/remarkjs/remark-frontmatter.svg | ||
[build-status]: https://travis-ci.org/wooorm/remark-frontmatter | ||
[build-status]: https://travis-ci.org/remarkjs/remark-frontmatter | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/remark-frontmatter.svg | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-frontmatter.svg | ||
[coverage-status]: https://codecov.io/github/wooorm/remark-frontmatter | ||
[coverage-status]: https://codecov.io/github/remarkjs/remark-frontmatter | ||
[chat-badge]: https://img.shields.io/gitter/room/wooorm/remark.svg | ||
[chat-badge]: https://img.shields.io/gitter/room/remarkjs/Lobby.svg | ||
[chat]: https://gitter.im/wooorm/remark | ||
[chat]: https://gitter.im/remarkjs/Lobby | ||
@@ -224,11 +232,11 @@ [license]: LICENSE | ||
[remark]: https://github.com/wooorm/remark | ||
[remark]: https://github.com/remarkjs/remark | ||
[parse]: https://github.com/wooorm/remark/tree/master/packages/remark-parse | ||
[parse]: https://github.com/remarkjs/remark/tree/master/packages/remark-parse | ||
[tokenizers]: https://github.com/wooorm/remark/tree/master/packages/remark-parse#parserblocktokenizers | ||
[tokenizers]: https://github.com/remarkjs/remark/tree/master/packages/remark-parse#parserblocktokenizers | ||
[stringify]: https://github.com/wooorm/remark/tree/master/packages/remark-stringify | ||
[stringify]: https://github.com/remarkjs/remark/tree/master/packages/remark-stringify | ||
[visitors]: https://github.com/wooorm/remark/tree/master/packages/remark-stringify#compilervisitors | ||
[visitors]: https://github.com/remarkjs/remark/tree/master/packages/remark-stringify#compilervisitors | ||
@@ -243,2 +251,6 @@ [processor]: https://github.com/unifiedjs/unified#processor | ||
[man]: https://github.com/wooorm/remark-man | ||
[man]: https://github.com/remarkjs/remark-man | ||
[contributing]: https://github.com/remarkjs/remark/blob/master/contributing.md | ||
[coc]: https://github.com/remarkjs/remark/blob/master/code-of-conduct.md |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
12839
251
13
149
1