Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 8, 2021
1 parent 755406b commit bc627a3
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 45 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
yarn.lock
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
coverage/
*.json
*.md
1 change: 0 additions & 1 deletion html.js

This file was deleted.

3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require('./lib/syntax.js')
export {frontmatterHtml} from './lib/html.js'
export {frontmatter} from './lib/syntax.js'
19 changes: 8 additions & 11 deletions lib/html.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
module.exports = create
import {matters} from './matters.js'

var matters = require('./matters.js')

function create(options) {
export function frontmatterHtml(options) {
var settings = matters(options)
var length = settings.length
var index = -1
var matter
var enter = {}
var exit = {}
var type

while (++index < length) {
matter = settings[index]
enter[matter.type] = start
exit[matter.type] = end
while (++index < settings.length) {
type = settings[index].type
enter[type] = start
exit[type] = end
}

return {enter: enter, exit: exit}
return {enter, exit}

function start() {
this.buffer()
Expand Down
6 changes: 2 additions & 4 deletions lib/matters.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module.exports = matters

var fault = require('fault')
import {fault} from 'fault'

var own = {}.hasOwnProperty

var markers = {yaml: '-', toml: '+'}

function matters(options = 'yaml') {
export function matters(options = 'yaml') {
var results = []
var index = -1

Expand Down
8 changes: 3 additions & 5 deletions lib/syntax.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module.exports = create
import {matters} from './matters.js'

var matters = require('./matters.js')

function create(options) {
export function frontmatter(options) {
var settings = matters(options)
var length = settings.length
var index = -1
Expand All @@ -20,7 +18,7 @@ function create(options) {
}
}

return {flow: flow}
return {flow}
}

function parse(matter) {
Expand Down
27 changes: 12 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,31 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"lib/",
"index.js",
"html.js"
"index.js"
],
"dependencies": {
"fault": "^1.0.0"
"fault": "^2.0.0"
},
"devDependencies": {
"micromark": "~2.11.0",
"nyc": "^15.0.0",
"c8": "^7.0.0",
"micromark": "^3.0.0-alpha.2",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"xo": "^0.38.0"
"xo": "^0.39.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test/index.js",
"test": "npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
Expand All @@ -62,8 +58,9 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off",
"unicorn/no-this-assignment": "off"
}
},
Expand Down
11 changes: 9 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ You probably shouldn’t use this package directly, but instead use

## Install

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.

[npm][]:

```sh
Expand All @@ -33,9 +36,13 @@ npm install micromark-extension-frontmatter

## API

### `html(options)`
This package exports the following identifiers: `frontmatter`,
`frontmatterHtml`.
There is no default export.

### `frontmatterHtml(options?)`

### `syntax(options)`
### `frontmatter(options?)`

> Note: `syntax` is the default export of this module, `html` is available at
> `micromark-extension-frontmatter/html`.
Expand Down
7 changes: 3 additions & 4 deletions test.js → test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var test = require('tape')
var micromark = require('micromark')
var syntax = require('./index.js')
var html = require('./html.js')
import test from 'tape'
import {micromark} from 'micromark'
import {frontmatter as syntax, frontmatterHtml as html} from '../index.js'

var custom = {type: 'custom', marker: {open: '<', close: '>'}}
var json = {type: 'json', fence: {open: '{', close: '}'}}
Expand Down

0 comments on commit bc627a3

Please sign in to comment.