Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 26, 2021
1 parent 2756cca commit 3f4e104
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 37 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/
hast-util-parse-selector.js
hast-util-parse-selector.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/
hast-util-parse-selector.js
hast-util-parse-selector.min.js
*.json
*.md
7 changes: 1 addition & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
'use strict'

module.exports = parse

var search = /[#.]/g

// Create a hast element from a simple CSS selector.
function parse(selector, defaultTagName) {
export function parseSelector(selector, name = 'div') {
var value = selector || ''
var name = defaultTagName || 'div'
var props = {}
var start = 0
var subvalue
Expand Down
32 changes: 12 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,25 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"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"
"xo": "^0.39.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify . -s hastUtilParseSelector -o hast-util-parse-selector.js",
"build-mangle": "browserify . -s hastUtilParseSelector -o hast-util-parse-selector.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"
"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 @@ -56,16 +54,10 @@
},
"xo": {
"prettier": true,
"esnext": false,
"ignores": [
"hast-util-parse-selector.js"
]
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ selector.

## 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 @@ -22,7 +25,7 @@ npm install hast-util-parse-selector
## Use

```js
var parseSelector = require('hast-util-parse-selector')
import {parseSelector} from 'hast-util-parse-selector'

console.log(parseSelector('.quux#bar.baz.qux'))
```
Expand All @@ -38,6 +41,9 @@ Yields:

## API

This package exports the following identifiers: `parseSelector`.
There is no default export.

### `parseSelector([selector][, defaultTagName])`

Create an [*element*][element] [*node*][node] from a simple CSS selector.
Expand Down
6 changes: 2 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

var test = require('tape')
var parseSelector = require('.')
import test from 'tape'
import {parseSelector} from './index.js'

test('parseSelector()', function (t) {
t.deepEqual(
Expand Down

0 comments on commit 3f4e104

Please sign in to comment.