Skip to content

Commit 6b14a9d

Browse files
committed
1.0.2 removed typings
1 parent 3b08ca3 commit 6b14a9d

File tree

13 files changed

+993
-87
lines changed

13 files changed

+993
-87
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ node_js:
1111
- "iojs"
1212

1313
install:
14-
- npm install typings -g
1514
- npm install blue-tape
1615
- npm install rimraf
1716
- npm install tap-diff
1817
- npm install ts-node
1918
- npm install tslint
20-
- npm install typescript
21-
- typings install
19+
- npm install typescript
2220

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# nodeify-ts
22
Create functions that both return promises and accept node-style callbacks
33

4-
[![NPM](https://nodei.co/npm/nodeify-ts.png?downloads=true&downloadRank=true)](https://nodei.co/npm/nodeify-ts/)
5-
[![NPM](https://nodei.co/npm-dl/nodeify-ts.png?months=6&height=3)](https://nodei.co/npm/nodeify-ts/)
6-
74
[![NPM version][npm-image]][npm-url]
85
[![NPM downloads][downloads-image]][downloads-url]
96
[![Build status][travis-image]][travis-url]

lib/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function (promise: Promise<any>, callback?: (err: any, data: any) => void): Promise<any>;

lib/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
function default_1(promise, callback) {
4+
if (typeof callback !== 'function') {
5+
return promise;
6+
}
7+
return promise.then((result) => {
8+
callback(null, result);
9+
}, (error) => {
10+
callback(error || new Error, null);
11+
});
12+
}
13+
exports.default = default_1;

lib/index.spec.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

lib/index.spec.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
/* tslint:disable:no-shadowed-variable */
4+
const test = require("blue-tape");
5+
const index_1 = require("./index");
6+
const command = function (command, callback) {
7+
const promise = Promise.resolve().then(function () {
8+
return Promise.resolve('do some work and return result ' + command);
9+
}).then(function (data) {
10+
//console.log(data);
11+
return data;
12+
});
13+
return index_1.default(promise, callback);
14+
};
15+
const commandWillFail = function (command, callback) {
16+
const promise = Promise.resolve().then(function () {
17+
return Promise.reject('do some work and reject ' + command);
18+
}).then(function (data) {
19+
//console.log(data);
20+
return data;
21+
});
22+
return index_1.default(promise, callback);
23+
};
24+
test('nodeify', t => {
25+
t.test('promise', t => {
26+
return command('with promise').then(function (data) {
27+
t.equal(data, 'do some work and return result with promise');
28+
});
29+
});
30+
t.test('callback', t => {
31+
command('with callback', function (err, data) {
32+
t.equal(data, 'do some work and return result with callback');
33+
t.end();
34+
});
35+
});
36+
});
37+
test('nodeify should fail', t => {
38+
t.test('promise', t => {
39+
return commandWillFail('with promise').then(function (data) {
40+
console.log('data', data);
41+
}).catch((e) => {
42+
t.equal(e, 'do some work and reject with promise');
43+
});
44+
});
45+
t.test('callback', t => {
46+
commandWillFail('with callback', function (err, data) {
47+
t.equal(err, 'do some work and reject with callback');
48+
t.equal(null, data);
49+
t.end();
50+
});
51+
});
52+
});

0 commit comments

Comments
 (0)