Skip to content

Commit 7a36b81

Browse files
authored
feat: convert to typescript (#16)
- Only named exports - No more CJS, only ESM - Adds auto-publish - Adds dependabot - Adds tests for abortable sink/source/duplex - Removes support for multiple abort signals - just use `any-signal` BREAKING CHANGE: switch to named exports, ESM only
1 parent 8fd144b commit 7a36b81

17 files changed

+680
-11569
lines changed

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "11:00"
8+
open-pull-requests-limit: 10
+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
name: test & maybe release
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
10+
jobs:
11+
12+
check:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v2
17+
with:
18+
node-version: lts/*
19+
- uses: ipfs/aegir/actions/cache-node-modules@master
20+
- run: npm run --if-present lint
21+
- run: npm run --if-present dep-check
22+
23+
test-node:
24+
needs: check
25+
runs-on: ${{ matrix.os }}
26+
strategy:
27+
matrix:
28+
os: [windows-latest, ubuntu-latest, macos-latest]
29+
node: [16]
30+
fail-fast: true
31+
steps:
32+
- uses: actions/checkout@v2
33+
- uses: actions/setup-node@v2
34+
with:
35+
node-version: ${{ matrix.node }}
36+
- uses: ipfs/aegir/actions/cache-node-modules@master
37+
- run: npm run --if-present test:node
38+
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
39+
with:
40+
directory: ./.nyc_output
41+
flags: node
42+
43+
test-chrome:
44+
needs: check
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v2
48+
- uses: actions/setup-node@v2
49+
with:
50+
node-version: lts/*
51+
- uses: ipfs/aegir/actions/cache-node-modules@master
52+
- run: npm run --if-present test:chrome
53+
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
54+
with:
55+
directory: ./.nyc_output
56+
flags: chrome
57+
58+
test-chrome-webworker:
59+
needs: check
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v2
63+
- uses: actions/setup-node@v2
64+
with:
65+
node-version: lts/*
66+
- uses: ipfs/aegir/actions/cache-node-modules@master
67+
- run: npm run --if-present test:chrome-webworker
68+
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
69+
with:
70+
directory: ./.nyc_output
71+
flags: chrome-webworker
72+
73+
test-firefox:
74+
needs: check
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v2
78+
- uses: actions/setup-node@v2
79+
with:
80+
node-version: lts/*
81+
- uses: ipfs/aegir/actions/cache-node-modules@master
82+
- run: npm run --if-present test:firefox
83+
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
84+
with:
85+
directory: ./.nyc_output
86+
flags: firefox
87+
88+
test-firefox-webworker:
89+
needs: check
90+
runs-on: ubuntu-latest
91+
steps:
92+
- uses: actions/checkout@v2
93+
- uses: actions/setup-node@v2
94+
with:
95+
node-version: lts/*
96+
- uses: ipfs/aegir/actions/cache-node-modules@master
97+
- run: npm run --if-present test:firefox-webworker
98+
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
99+
with:
100+
directory: ./.nyc_output
101+
flags: firefox-webworker
102+
103+
test-electron-main:
104+
needs: check
105+
runs-on: ubuntu-latest
106+
steps:
107+
- uses: actions/checkout@v2
108+
- uses: actions/setup-node@v2
109+
with:
110+
node-version: lts/*
111+
- uses: ipfs/aegir/actions/cache-node-modules@master
112+
- run: npx xvfb-maybe npm run --if-present test:electron-main
113+
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
114+
with:
115+
directory: ./.nyc_output
116+
flags: electron-main
117+
118+
test-electron-renderer:
119+
needs: check
120+
runs-on: ubuntu-latest
121+
steps:
122+
- uses: actions/checkout@v2
123+
- uses: actions/setup-node@v2
124+
with:
125+
node-version: lts/*
126+
- uses: ipfs/aegir/actions/cache-node-modules@master
127+
- run: npx xvfb-maybe npm run --if-present test:electron-renderer
128+
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
129+
with:
130+
directory: ./.nyc_output
131+
flags: electron-renderer
132+
133+
release:
134+
needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer]
135+
runs-on: ubuntu-latest
136+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
137+
steps:
138+
- uses: actions/[email protected]
139+
with:
140+
fetch-depth: 0
141+
- uses: actions/setup-node@v2
142+
with:
143+
node-version: lts/*
144+
- uses: ipfs/aegir/actions/cache-node-modules@master
145+
- uses: ipfs/aegir/actions/docker-login@master
146+
with:
147+
docker-token: ${{ secrets.DOCKER_TOKEN }}
148+
docker-username: ${{ secrets.DOCKER_USERNAME }}
149+
- run: npm run --if-present release
150+
env:
151+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
152+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
2-
.nyc_output
32
coverage
3+
.nyc_output
4+
package-lock.json
5+
dist

.npmignore

-4
This file was deleted.

.travis.yml

-3
This file was deleted.

AbortError.js

-7
This file was deleted.

README.md

+20-54
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# abortable-iterator
22

3-
[![Build Status](https://travis-ci.org/alanshaw/abortable-iterator.svg?branch=master)](https://travis-ci.org/alanshaw/abortable-iterator) [![dependencies Status](https://david-dm.org/alanshaw/abortable-iterator/status.svg)](https://david-dm.org/alanshaw/abortable-iterator) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
3+
[![Build Status](https://github.com/alanshaw/abortable-iterator/actions/workflows/js-test-and-release.yml/badge.svg?branch=master)](https://github.com/alanshaw/abortable-iterator/actions/workflows/js-test-and-release.yml)
4+
[![Dependencies Status](https://status.david-dm.org/gh/alanshaw/abortable-iterator.svg)](https://david-dm.org/alanshaw/abortable-iterator)
5+
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
46

57
> Make any iterator or iterable abortable via an AbortSignal
68
@@ -15,8 +17,7 @@ npm install abortable-iterator
1517
## Usage
1618

1719
```js
18-
const abortable = require('abortable-iterator')
19-
const AbortController = require('abort-controller')
20+
import { abortableSource } from 'abortable-iterator'
2021

2122
// An example function that creates an async iterator that yields an increasing
2223
// number every x milliseconds and NEVER ENDS!
@@ -32,7 +33,7 @@ const everySecond = asyncCounter(0, 1000)
3233

3334
// Make everySecond abortable!
3435
const controller = new AbortController()
35-
const abortableEverySecond = abortable(everySecond, controller.signal)
36+
const abortableEverySecond = abortableSource(everySecond, controller.signal)
3637

3738
// Abort after 5 seconds
3839
setTimeout(() => controller.abort(), 5000)
@@ -54,21 +55,20 @@ try {
5455
## API
5556

5657
```js
57-
const abortable = require('abortable-iterator')
58+
import {
59+
abortableSource,
60+
abortableSink,
61+
abortableTransform,
62+
abortableDuplex
63+
} from 'abortable-iterator'
5864
```
5965

60-
* [`abortable(source, signal, [options])`](#abortablesource-signal-options)
61-
* [`abortable(source, signals)`](#abortablesource-signals)
62-
* [`abortable.source(source, signal, [options])`](#abortablesource-signal-options)
63-
* [`abortable.source(source, signals)`](#abortablesource-signals)
64-
* [`abortable.sink(sink, signal, [options])`](#abortablesinksink-signal-options)
65-
* [`abortable.sink(sink, signals)`](#abortablesinksink-signals)
66-
* [`abortable.transform(transform, signal, [options])`](#abortabletransformtransform-signal-options)
67-
* [`abortable.transform(transform, signals)`](#abortabletransformtransform-signals)
68-
* [`abortable.duplex(duplex, signal, [options])`](#abortableduplexduplex-signal-options)
69-
* [`abortable.duplex(duplex, signals)`](#abortableduplex-signals)
70-
71-
### `abortable(source, signal, [options])`
66+
* [`abortableSource(source, signal, [options])`](#abortablesource-signal-options)
67+
* [`abortableSink(sink, signal, [options])`](#abortablesinksink-signal-options)
68+
* [`abortableTransform(transform, signal, [options])`](#abortabletransformtransform-signal-options)
69+
* [`abortableDuplex(duplex, signal, [options])`](#abortableduplexduplex-signal-options)
70+
71+
### `abortableSource(source, signal, [options])`
7272
**(alias for `abortable.source(source, signal, [options])`)**
7373

7474
Make any iterator or iterable abortable via an `AbortSignal`.
@@ -94,54 +94,20 @@ Make any iterator or iterable abortable via an `AbortSignal`.
9494

9595
The returned iterator will `throw` an `AbortError` when it is aborted that has a `type` with the value `aborted` and `code` property with the value `ABORT_ERR` by default.
9696

97-
### `abortable(source, signals)`
98-
**(alias for `abortable.source(source, signals)`)**
99-
100-
Make any iterator or iterable abortable via any one of the passed `AbortSignal`'s.
101-
102-
#### Parameters
103-
104-
| Name | Type | Description |
105-
|------|------|-------------|
106-
| source | [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol)\|[`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol) | The iterator or iterable object to make abortable |
107-
| signals | `Array<{ signal, [options] }>` | An array of objects with `signal` and optional `options` properties. See above docs for expected values for these two properties. |
108-
109-
#### Returns
110-
111-
| Type | Description |
112-
|------|-------------|
113-
| [`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol) | An iterator that wraps the passed `source` parameter that makes it abortable via the passed `signal` parameters. |
114-
115-
The returned iterator will `throw` an `AbortError` when it is aborted on _any_ one of the passed abort signals. The error object has a `type` with the value `aborted` and `code` property with the value `ABORT_ERR` by default.
116-
117-
### `abortable.sink(sink, signal, [options])`
97+
### `abortableSink(sink, signal, [options])`
11898

11999
The same as [`abortable.source`](#abortablesource-signal-options) except this makes the passed [`sink`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#sink-it) abortable. Returns a new sink that wraps the passed `sink` and makes it abortable via the passed `signal` parameter.
120100

121-
### `abortable.sink(sink, signals)`
122-
123-
The same as [`abortable.source`](#abortablesource-signals) except this makes the passed [`sink`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#sink-it) abortable via any one of the passed `AbortSignal`'s. Returns a new sink that wraps the passed `sink` and makes it abortable via the passed `signal` parameters.
124-
125-
### `abortable.transform(transform, signal, [options])`
101+
### `abortableTransform(transform, signal, [options])`
126102

127103
The same as [`abortable.source`](#abortablesource-signal-options) except this makes the passed [`transform`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#transform-it) abortable. Returns a new transform that wraps the passed `transform` and makes it abortable via the passed `signal` parameter.
128104

129-
### `abortable.transform(transform, signals)`
130-
131-
The same as [`abortable.source`](#abortablesource-signals) except this makes the passed [`transform`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#transform-it) abortable via any one of the passed `AbortSignal`'s. Returns a new transform that wraps the passed `transform` and makes it abortable via the passed `signal` parameters.
132-
133-
### `abortable.duplex(duplex, signal, [options])`
105+
### `abortableDuplex(duplex, signal, [options])`
134106

135107
The same as [`abortable.source`](#abortablesource-signal-options) except this makes the passed [`duplex`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it) abortable. Returns a new duplex that wraps the passed `duplex` and makes it abortable via the passed `signal` parameter.
136108

137109
Note that this will abort _both_ sides of the duplex. Use `duplex.sink = abortable.sink(duplex.sink)` or `duplex.source = abortable.source(duplex.source)` to abort just the sink or the source.
138110

139-
### `abortable.duplex(duplex, signals)`
140-
141-
The same as [`abortable.source`](#abortablesource-signals) except this makes the passed [`duplex`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it) abortable via any one of the passed `AbortSignal`'s. Returns a new duplex that wraps the passed `duplex` and makes it abortable via the passed `signal` parameters.
142-
143-
Note that this will abort _both_ sides of the duplex. Use `duplex.sink = abortable.sink(duplex.sink)` or `duplex.source = abortable.source(duplex.source)` to abort just the sink or the source.
144-
145111
## Related
146112

147113
* [`it-pipe`](https://www.npmjs.com/package/it-pipe) Utility to "pipe" async iterables together

example.js renamed to examples/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const abortable = require('./')
2-
const AbortController = require('abort-controller')
1+
import { abortableSource } from 'abortable-iterator'
32

43
async function main () {
54
// An example function that creates an async iterator that yields an increasing
@@ -16,7 +15,7 @@ async function main () {
1615

1716
// Make everySecond abortable!
1817
const controller = new AbortController()
19-
const abortableEverySecond = abortable(everySecond, controller.signal)
18+
const abortableEverySecond = abortableSource(everySecond, controller.signal)
2019

2120
// Abort after 5 seconds
2221
setTimeout(() => controller.abort(), 5000)

index.d.ts

-70
This file was deleted.

0 commit comments

Comments
 (0)