Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 23, 2021
1 parent 817d6db commit e98723b
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 94 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
mdast-comment-marker.js
mdast-comment-marker.min.js
yarn.lock
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
coverage/
mdast-comment-marker.js
mdast-comment-marker.min.js
*.json
*.md
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
'use strict'

module.exports = marker

var commentExpression = /\s*([a-zA-Z\d-]+)(\s+([\s\S]*))?\s*/

var markerExpression = new RegExp(
'(\\s*<!--' + commentExpression.source + '-->\\s*)'
)

// Parse a comment marker.
function marker(node) {
export function commentMarker(node) {
var match
var offset
var parameters
Expand All @@ -27,8 +23,8 @@ function marker(node) {
return {
name: match[offset],
attributes: match[offset + 2] || '',
parameters: parameters,
node: node
parameters,
node
}
}
}
Expand Down Expand Up @@ -58,7 +54,7 @@ function parseParameters(value) {
value = true
} else if (value === 'false') {
value = false
} else if (!isNaN(value)) {
} else if (!Number.isNaN(Number(value))) {
value = Number(value)
}

Expand Down
31 changes: 10 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,25 @@
"Titus Wormer <[email protected]> (https://wooorm.com)",
"Masayuki Izumi <[email protected]> (http://izumin.info)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js"
],
"devDependencies": {
"browserify": "^17.0.0",
"nyc": "^15.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"xo": "^0.38.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify . -s mdastCommentMarker -o mdast-comment-marker.js",
"build-mangle": "browserify . -s mdastCommentMarker -o mdast-comment-marker.min.js -p tinyify",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run format && npm run build && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand All @@ -61,13 +53,10 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"unicorn/prefer-number-properties": "off"
},
"ignore": [
"mdast-comment-marker.js"
]
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
20 changes: 13 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

## 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 @@ -21,25 +24,25 @@ npm install mdast-comment-marker
## Use

```js
var marker = require('mdast-comment-marker');
import {commentMarker} from 'mdast-comment-marker'

console.log(marker({
console.log(commentMarker({
type: 'html',
value: '<!--foo-->'
}));

console.log(marker({
console.log(commentMarker({
type: 'html',
value: '<!--foo bar baz=12.4 qux="test test" quux=\'false\'-->'
}));

console.log(marker({
console.log(commentMarker({
type: 'html',
value: '<!doctype html>'
}));

// Also supports MDX comment nodes.
console.log(marker({
// Also supports MDX@1 comment nodes.
console.log(commentMarker({
type: 'comment',
value: 'bar'
}));
Expand Down Expand Up @@ -67,7 +70,10 @@ null

## API

### `marker(node)`
This package exports the following identifiers: `commentMarker`.
There is no default export.

### `commentMarker(node)`

Parse a comment marker.

Expand Down
Loading

0 comments on commit e98723b

Please sign in to comment.