Skip to content

Commit 2ac0a2f

Browse files
committed
Use ESM
1 parent 9c6a61b commit 2ac0a2f

File tree

6 files changed

+30
-43
lines changed

6 files changed

+30
-43
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
.nyc_output/
1+
*.log
22
coverage/
33
node_modules/
4-
*.log
54
.DS_Store
6-
array-iterate.js
7-
array-iterate.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-
*.json
32
*.md
4-
array-iterate.js
5-
array-iterate.min.js

index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
'use strict'
2-
3-
module.exports = iterate
4-
51
var own = {}.hasOwnProperty
62

7-
function iterate(values, callback, context) {
3+
export function arrayIterate(values, callback, context) {
84
var index = -1
95
var result
106

package.json

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,25 @@
1919
"contributors": [
2020
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
2121
],
22+
"sideEffects": false,
23+
"type": "module",
24+
"main": "index.js",
2225
"files": [
2326
"index.js"
2427
],
2528
"devDependencies": {
26-
"browserify": "^17.0.0",
27-
"nyc": "^15.0.0",
29+
"c8": "^7.0.0",
2830
"prettier": "^2.0.0",
2931
"remark-cli": "^9.0.0",
3032
"remark-preset-wooorm": "^8.0.0",
3133
"tape": "^5.0.0",
32-
"tinyify": "^3.0.0",
3334
"xo": "^0.38.0"
3435
},
3536
"scripts": {
3637
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
37-
"build-bundle": "browserify . -s arrayIterate -o array-iterate.js",
38-
"build-mangle": "browserify . -s arrayIterate -p tinyify -o array-iterate.min.js",
39-
"build": "npm run build-bundle && npm run build-mangle",
4038
"test-api": "node test",
41-
"test-coverage": "nyc --reporter lcov tape test.js",
42-
"test": "npm run format && npm run build && npm run test-coverage"
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"
4341
},
4442
"prettier": {
4543
"tabWidth": 2,
@@ -51,8 +49,9 @@
5149
},
5250
"xo": {
5351
"prettier": true,
54-
"esnext": false,
5552
"rules": {
53+
"no-var": "off",
54+
"prefer-arrow-callback": "off",
5655
"unicorn/no-this-assignment": "off",
5756
"unicorn/prefer-type-error": "off"
5857
}
@@ -61,11 +60,5 @@
6160
"plugins": [
6261
"preset-wooorm"
6362
]
64-
},
65-
"nyc": {
66-
"check-coverage": true,
67-
"lines": 100,
68-
"functions": 100,
69-
"branches": 100
7063
}
7164
}

readme.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
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
@@ -18,12 +21,12 @@ npm install array-iterate
1821
## Use
1922

2023
```js
21-
var iterate = require('array-iterate')
24+
import {arrayIterate} from 'array-iterate'
2225

2326
var isFirst = true
2427
var context = {hello: 'world'}
2528

26-
iterate([1, 2, 3, 4], callback, context)
29+
arrayIterate([1, 2, 3, 4], callback, context)
2730

2831
function callback(value, index, values) {
2932
console.log(this, value, index, values)
@@ -50,7 +53,10 @@ Yields:
5053

5154
## API
5255

53-
### `iterate(values, callback[, context])`
56+
This package exports the following identifiers: `arrayIterate`.
57+
There is no default export.
58+
59+
### `arrayIterate(values, callback[, context])`
5460

5561
Works just like [`Array#forEach()`][foreach], but when `callback` returns a
5662
`number`, iterates over the item at `number` next.

test.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
'use strict'
1+
import test from 'tape'
2+
import {arrayIterate} from './index.js'
23

3-
var test = require('tape')
4-
var iterate = require('.')
5-
6-
test('iterate()', function (t) {
4+
test('arrayIterate()', function (t) {
75
t.throws(
86
function () {
9-
iterate()
7+
arrayIterate()
108
},
119
/^Error: Iterate requires that \|this\| not be undefined$/,
1210
'should throw without `values`'
1311
)
1412

1513
t.throws(
1614
function () {
17-
iterate({})
15+
arrayIterate({})
1816
},
1917
/Error: Iterate requires that \|this\| has a `length`/,
2018
'should throw without `values.length`'
2119
)
2220

2321
t.throws(
2422
function () {
25-
iterate([])
23+
arrayIterate([])
2624
},
2725
/^Error: `callback` must be a function$/,
2826
'should throw without `callback`'
@@ -32,7 +30,7 @@ test('iterate()', function (t) {
3230
var list = [0, 1, 2]
3331
var n = 0
3432

35-
iterate(list, function (value, index, values) {
33+
arrayIterate(list, function (value, index, values) {
3634
st.equal(value, n)
3735
st.equal(index, n)
3836
st.equal(values, list)
@@ -49,7 +47,7 @@ test('iterate()', function (t) {
4947
var self = this
5048
var n = 0
5149

52-
iterate(
50+
arrayIterate(
5351
[1, 2, 3],
5452
function () {
5553
st.equal(this, self)
@@ -65,7 +63,7 @@ test('iterate()', function (t) {
6563
t.test('should use the given return value', function (st) {
6664
var n = 0
6765

68-
iterate([0, 1, 2], function (value, index) {
66+
arrayIterate([0, 1, 2], function (value, index) {
6967
n++
7068

7169
st.equal(value, index)
@@ -89,7 +87,7 @@ test('iterate()', function (t) {
8987

9088
list.push(magicNumber + 1)
9189

92-
iterate(list, function (value, index) {
90+
arrayIterate(list, function (value, index) {
9391
st.equal(value, magicNumber + 1)
9492
st.equal(index, magicNumber)
9593
n = index
@@ -104,7 +102,7 @@ test('iterate()', function (t) {
104102
var n = 0
105103
var results = ['a', 'b', 'a', 'b', 'c', 'd']
106104

107-
iterate(['a', 'b', 'c', 'd'], function (value) {
105+
arrayIterate(['a', 'b', 'c', 'd'], function (value) {
108106
st.equal(value, results[n])
109107
n++
110108

0 commit comments

Comments
 (0)