[Pkg-javascript-commits] [node-p-finally] 01/04: Import Upstream version 1.0.0

Shirish Togarla shirish12-guest at moszumanska.debian.org
Tue Feb 7 18:08:22 UTC 2017


This is an automated email from the git hooks/post-receive script.

shirish12-guest pushed a commit to branch master
in repository node-p-finally.

commit d7917eed48eaa5f038a0363c9244568e732f7087
Author: Shirish Togarla <shirishtogarla533 at gmail.com>
Date:   Sat Feb 4 19:26:28 2017 +0000

    Import Upstream version 1.0.0
---
 .editorconfig  | 12 ++++++++++++
 .gitattributes |  2 ++
 .gitignore     |  1 +
 .travis.yml    |  4 ++++
 index.js       | 15 +++++++++++++++
 license        | 21 +++++++++++++++++++++
 package.json   | 42 ++++++++++++++++++++++++++++++++++++++++++
 readme.md      | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 test.js        | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 190 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..98a761d
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{package.json,*.yml}]
+indent_style = space
+indent_size = 2
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..391f0a4
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+* text=auto
+*.js text eol=lf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..97519af
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - '6'
+  - '4'
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..52b7b49
--- /dev/null
+++ b/index.js
@@ -0,0 +1,15 @@
+'use strict';
+module.exports = (promise, onFinally) => {
+	onFinally = onFinally || (() => {});
+
+	return promise.then(
+		val => new Promise(resolve => {
+			resolve(onFinally());
+		}).then(() => val),
+		err => new Promise(resolve => {
+			resolve(onFinally());
+		}).then(() => {
+			throw err;
+		})
+	);
+};
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
+
+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:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..b26ab51
--- /dev/null
+++ b/package.json
@@ -0,0 +1,42 @@
+{
+  "name": "p-finally",
+  "version": "1.0.0",
+  "description": "`Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome",
+  "license": "MIT",
+  "repository": "sindresorhus/p-finally",
+  "author": {
+    "name": "Sindre Sorhus",
+    "email": "sindresorhus at gmail.com",
+    "url": "sindresorhus.com"
+  },
+  "engines": {
+    "node": ">=4"
+  },
+  "scripts": {
+    "test": "xo && ava"
+  },
+  "files": [
+    "index.js"
+  ],
+  "keywords": [
+    "promise",
+    "finally",
+    "handler",
+    "function",
+    "async",
+    "await",
+    "promises",
+    "settled",
+    "ponyfill",
+    "polyfill",
+    "shim",
+    "bluebird"
+  ],
+  "devDependencies": {
+    "ava": "*",
+    "xo": "*"
+  },
+  "xo": {
+    "esnext": true
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..09ef364
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,47 @@
+# p-finally [![Build Status](https://travis-ci.org/sindresorhus/p-finally.svg?branch=master)](https://travis-ci.org/sindresorhus/p-finally)
+
+> [`Promise#finally()`](https://github.com/tc39/proposal-promise-finally) [ponyfill](https://ponyfill.com) - Invoked when the promise is settled regardless of outcome
+
+Useful for cleanup.
+
+
+## Install
+
+```
+$ npm install --save p-finally
+```
+
+
+## Usage
+
+```js
+const pFinally = require('p-finally');
+
+const dir = createTempDir();
+
+pFinally(write(dir), () => cleanup(dir));
+```
+
+
+## API
+
+### pFinally(promise, [onFinally])
+
+Returns a `Promise`.
+
+#### onFinally
+
+Type: `Function`
+
+Note: Throwing or returning a rejected promise will reject `promise` with the rejection reason.
+
+
+## Related
+
+- [p-try](https://github.com/sindresorhus/p-try) - `Promise#try()` ponyfill - Starts a promise chain
+- [More…](https://github.com/sindresorhus/promise-fun)
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..613b0a4
--- /dev/null
+++ b/test.js
@@ -0,0 +1,46 @@
+import test from 'ava';
+import m from './';
+
+const fixture = Symbol('fixture');
+const fixtureErr = new Error('err');
+
+test('does nothing when nothing is passed', async t => {
+	t.is(await m(Promise.resolve(fixture)), fixture);
+});
+
+test('callback is called when promise is fulfilled', async t => {
+	let called = false;
+
+	const val = await m(Promise.resolve(fixture), () => {
+		called = true;
+	});
+
+	t.is(val, fixture);
+	t.true(called);
+});
+
+test('callback is called when promise is rejected', async t => {
+	let called = false;
+
+	await m(Promise.reject(fixtureErr), () => {
+		called = true;
+	}).catch(err => {
+		t.is(err, fixtureErr);
+	});
+
+	t.true(called);
+});
+
+test('returning a rejected promise in the callback rejects the promise', async t => {
+	await m(Promise.resolve(fixture), () => Promise.reject(fixtureErr)).then(() => {
+		t.fail();
+	}, err => {
+		t.is(err, fixtureErr);
+	});
+});
+
+test('returning a rejected promise in the callback for an already rejected promise changes the rejection reason', async t => {
+	await m(Promise.reject(new Error('orig err')), () => Promise.reject(fixtureErr)).catch(err => {
+		t.is(err, fixtureErr);
+	});
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-p-finally.git



More information about the Pkg-javascript-commits mailing list