Skip to content

Commit 4b8da28

Browse files
committed
Use ESM
1 parent e2e47ee commit 4b8da28

File tree

7 files changed

+26
-41
lines changed

7 files changed

+26
-41
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717
strategy:
1818
matrix:
1919
node:
20-
- lts/dubnium
20+
- lts/erbium
2121
- node

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
.DS_Store
22
*.log
3-
.nyc_output/
43
coverage/
54
node_modules/
6-
plain-text-data-to-json.js
7-
plain-text-data-to-json.min.js
85
yarn.lock

.prettierignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
coverage/
2-
plain-text-data-to-json.js
3-
plain-text-data-to-json.min.js
4-
*.json
52
*.md

index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
'use strict'
2-
3-
var trim = require('trim')
4-
5-
module.exports = toJson
6-
71
var own = {}.hasOwnProperty
82

93
// Transform a string into an array or object of values.
10-
function toJson(value, options) {
4+
export function toJson(value, options) {
115
var propertyOrValues = {}
126
var lines
137
var isPropertyValuePair
@@ -39,7 +33,7 @@ function toJson(value, options) {
3933
lines = lines.map(stripComments(comment))
4034
})
4135

42-
lines = lines.map(trim).filter(Boolean)
36+
lines = lines.map((d) => d.trim()).filter(Boolean)
4337

4438
pairs = lines.map(toPropertyValuePairs(options.delimiter || ':'))
4539

@@ -134,10 +128,10 @@ function toPropertyValuePairs(token) {
134128
// Transform `value` to a property--value tuple.
135129
function toPropValuePairs(value) {
136130
var values = value.split(token)
137-
var result = [trim(values.shift())]
131+
var result = [values.shift().trim()]
138132

139133
if (values.length > 0) {
140-
result.push(trim(values.join(token)))
134+
result.push(values.join(token).trim())
141135
}
142136

143137
return result

package.json

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,26 @@
1818
"contributors": [
1919
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
2020
],
21+
"sideEffects": false,
22+
"type": "module",
23+
"main": "index.js",
2124
"files": [
2225
"index.js"
2326
],
24-
"dependencies": {
25-
"trim": "^1.0.0"
26-
},
2727
"devDependencies": {
28-
"browserify": "^17.0.0",
29-
"cept": "^1.0.0",
30-
"nyc": "^15.0.0",
28+
"c8": "^7.0.0",
29+
"cept": "^2.0.0",
3130
"prettier": "^2.0.0",
3231
"remark-cli": "^9.0.0",
3332
"remark-preset-wooorm": "^8.0.0",
3433
"tape": "^5.0.0",
35-
"tinyify": "^3.0.0",
3634
"xo": "^0.38.0"
3735
},
3836
"scripts": {
3937
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
40-
"build-bundle": "browserify . -s plain-text-data-to-json -o plain-text-data-to-json.js",
41-
"build-mangle": "browserify . -s plain-text-data-to-json -p tinyify -o plain-text-data-to-json.min.js",
42-
"build": "npm run build-bundle && npm run build-mangle",
43-
"test-api": "node test",
44-
"test-coverage": "nyc --reporter lcov tape test.js",
45-
"test": "npm run format && npm run build && npm run test-coverage"
38+
"test-api": "node test.js",
39+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
40+
"test": "npm run format && npm run test-coverage"
4641
},
4742
"prettier": {
4843
"tabWidth": 2,
@@ -54,15 +49,13 @@
5449
},
5550
"xo": {
5651
"prettier": true,
57-
"esnext": false,
5852
"rules": {
53+
"no-var": "off",
54+
"prefer-arrow-callback": "off",
5955
"complexity": "off",
6056
"unicorn/no-array-callback-reference": "off",
6157
"unicorn/no-array-for-each": "off"
62-
},
63-
"ignores": [
64-
"plain-text-data-to-json.js"
65-
]
58+
}
6659
},
6760
"remarkConfig": {
6861
"plugins": [

readme.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Transform a “database” / basic (word, phrase) list from plain text to JSON.
99

1010
## Install
1111

12+
This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
13+
instead of `require`d.
14+
1215
[npm][]:
1316

1417
```sh
@@ -30,7 +33,10 @@ fs.writeFileSync('output.json', JSON.stringify(data, null, 2) + '\n')
3033

3134
## API
3235

33-
### `toJSON(value[, options])`
36+
This package exports the following identifiers: `toJson`.
37+
There is no default export.
38+
39+
### `toJson(value[, options])`
3440

3541
Transforms the given value (string) to JSON.
3642
Don’t like the default comment and property-value pair delimiters?

test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var cept = require('cept')
5-
var toJson = require('.')
1+
import test from 'tape'
2+
import {cept} from 'cept'
3+
import {toJson} from './index.js'
64

75
test('toJson', function (t) {
86
t.equal(typeof toJson, 'function', 'should be a `function`')

0 commit comments

Comments
 (0)