Skip to content

Commit b751f63

Browse files
committed
Require Node.js 14 and move to ESM
1 parent 9e0540f commit b751f63

File tree

7 files changed

+41
-46
lines changed

7 files changed

+41
-46
lines changed

.github/funding.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 18
14+
- 16
1315
- 14
14-
- 12
15-
- 10
16-
- 8
1716
steps:
18-
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-node@v3
2019
with:
2120
node-version: ${{ matrix.node-version }}
2221
- run: npm install

index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
'use strict';
2-
const isObservable = require('is-observable');
3-
const symbolObservable = require('symbol-observable').default;
1+
import isObservable from 'is-observable';
2+
import symbolObservable from 'symbol-observable';
43

5-
module.exports = async value => {
4+
export default async function observableToPromise(value) {
65
if (!isObservable(value)) {
76
throw new TypeError(`Expected an \`Observable\`, got \`${typeof value}\``);
87
}
98

109
const values = [];
1110

1211
return new Promise((resolve, reject) => {
13-
value[symbolObservable]().subscribe({
14-
next: value => {
12+
value[symbolObservable.default]().subscribe({
13+
next(value) {
1514
values.push(value);
1615
},
1716
error: reject,
18-
complete: () => {
17+
complete() {
1918
resolve(values);
20-
}
19+
},
2120
});
2221
});
23-
};
22+
}

license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

package.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Convert an Observable to a Promise",
55
"license": "MIT",
66
"repository": "sindresorhus/observable-to-promise",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=8"
16+
"node": ">=14.16"
1417
},
1518
"scripts": {
1619
"test": "xo && ava"
@@ -27,16 +30,16 @@
2730
"subscribe"
2831
],
2932
"dependencies": {
30-
"is-observable": "^2.0.0",
31-
"symbol-observable": "^1.0.4"
33+
"is-observable": "^3.0.0",
34+
"symbol-observable": "^4.0.0"
3235
},
3336
"devDependencies": {
34-
"ava": "^1.4.1",
35-
"most": "^1.2.2",
36-
"p-is-promise": "^2.1.0",
37-
"rxjs": "^6.5.2",
38-
"xo": "^0.24.0",
39-
"xstream": "^11.11.0",
40-
"zen-observable": "^0.8.14"
37+
"ava": "^4.3.0",
38+
"most": "^1.9.0",
39+
"p-is-promise": "^4.0.0",
40+
"rxjs": "^7.5.5",
41+
"xo": "^0.49.0",
42+
"xstream": "^11.14.0",
43+
"zen-observable": "^0.8.15"
4144
}
4245
}

readme.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,23 @@
22

33
> Convert an [Observable](https://github.com/tc39/proposal-observable) to a Promise
44
5-
65
## Install
76

8-
```
9-
$ npm install observable-to-promise
7+
```sh
8+
npm install observable-to-promise
109
```
1110

12-
1311
## Usage
1412

1513
```js
16-
const observableToPromise = require('observable-to-promise');
14+
import observableToPromise from 'observable-to-promise';
1715

18-
(async () => {
19-
const promise = observableToPromise(Observable.of(1, 2));
16+
const promise = observableToPromise(Observable.of(1, 2));
2017

21-
console.log(await promise);
22-
//=> [1, 2]
23-
})();
18+
console.log(await promise);
19+
//=> [1, 2]
2420
```
2521

26-
2722
## Related
2823

2924
- [is-observable](https://github.com/sindresorhus/is-observable) - Check if a value is an Observable

test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ZenObservable from 'zen-observable';
44
import xs from 'xstream';
55
import {from as rxFrom} from 'rxjs';
66
import * as most from 'most';
7-
import toPromise from '.';
7+
import toPromise from './index.js';
88

99
// Run tests for a given observable library
1010
function testWithALib([libraryName, fromArray, failed]) {
@@ -25,13 +25,15 @@ function testWithALib([libraryName, fromArray, failed]) {
2525

2626
// Run tests for the list of libraries
2727
function testWithLibs(libraries) {
28-
libraries.forEach(testWithALib);
28+
for (const library of libraries) {
29+
testWithALib(library);
30+
}
2931
}
3032

3133
// Run tests not using any observables
3234
function commonTests() {
3335
test('throw an error when an non-observable is given', async t => {
34-
await t.throwsAsync(toPromise(2), TypeError);
36+
await t.throwsAsync(toPromise(2), {instanceOf: TypeError});
3537
});
3638
}
3739

@@ -47,8 +49,8 @@ const rejected = async () => {
4749
const zenFrom = array => ZenObservable.from(array);
4850
const zenFailed = () => new ZenObservable(observer => observer.error(reason));
4951

50-
const xsFrom = array => xs.from(array);
51-
const xsFailed = () => xs.fromPromise(rejected());
52+
const xsFrom = array => xs.default.from(array);
53+
const xsFailed = () => xs.default.fromPromise(rejected());
5254

5355
const rxFailed = () => rxFrom(rejected());
5456

@@ -60,5 +62,5 @@ testWithLibs([
6062
['zen-observable', zenFrom, zenFailed],
6163
['xstream', xsFrom, xsFailed],
6264
['RxJS 5', rxFrom, rxFailed],
63-
['most', mostFrom, mostFailed]
65+
['most', mostFrom, mostFailed],
6466
]);

0 commit comments

Comments
 (0)