init source

This commit is contained in:
Le Viet
2022-03-07 22:07:57 +07:00
parent e4376f3777
commit 8aba590a8d
11240 changed files with 1012977 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2016 Overlook Motel (theoverlookmotel@gmail.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.
+86
View File
@@ -0,0 +1,86 @@
# is-bluebird.js
# Is this a bluebird promise I see before me?
[![NPM version](https://img.shields.io/npm/v/is-bluebird.svg)](https://www.npmjs.com/package/is-bluebird)
[![Build Status](https://img.shields.io/travis/overlookmotel/is-bluebird/master.svg)](http://travis-ci.org/overlookmotel/is-bluebird)
[![Dependency Status](https://img.shields.io/david/overlookmotel/is-bluebird.svg)](https://david-dm.org/overlookmotel/is-bluebird)
[![Dev dependency Status](https://img.shields.io/david/dev/overlookmotel/is-bluebird.svg)](https://david-dm.org/overlookmotel/is-bluebird)
[![Coverage Status](https://img.shields.io/coveralls/overlookmotel/is-bluebird/master.svg)](https://coveralls.io/r/overlookmotel/is-bluebird)
## Usage
Tools to check whether some input is a [bluebird](http://bluebirdjs.com/) promise, a bluebird promise constructor, or determining the version of bluebird from a promise or constructor.
#### `isBluebird( promise )`
Returns true if is a bluebird promise, false if not.
```js
var isBluebird = require('is-bluebird');
var Bluebird = require('bluebird');
console.log( isBluebird( Bluebird.resolve() ) ); // true
console.log( isBluebird( Promise.resolve() ) ); // false (native JS promise)
```
#### `isBluebird.ctor( Promise )`
Returns true if is bluebird promise constructor, false if not.
```js
var isBluebird = require('is-bluebird');
var Bluebird = require('bluebird');
console.log( isBluebird.ctor( Bluebird ) ); // true
console.log( isBluebird.ctor( Promise ) ); // false (native JS promise)
```
#### `isBluebird.v2( promise )` / `isBluebird.v3( promise )`
Returns true if is a bluebird promise of the specified version.
```js
var isBluebird = require('is-bluebird');
var Bluebird2 = require('bluebird2');
var Bluebird3 = require('bluebird3');
console.log( isBluebird.v2( Bluebird2.resolve() ) ); // true
console.log( isBluebird.v2( Bluebird3.resolve() ) ); // false
console.log( isBluebird.v2( Promise.resolve() ) ); // false (native JS promise)
```
#### `isBluebird.v2.ctor( Promise )` / `isBluebird.v3.ctor( Promise )`
Returns true if is bluebird promise constructor of the specified version.
```js
var isBluebird = require('is-bluebird');
var Bluebird2 = require('bluebird2');
var Bluebird3 = require('bluebird3');
console.log( isBluebird.v2.ctor( Bluebird2 ) ); // true
console.log( isBluebird.v2.ctor( Bluebird3 ) ); // false
console.log( isBluebird.v2.ctor( Promise ) ); // false (native JS promise)
```
## Tests
Use `npm test` to run the tests. Use `npm run cover` to check coverage.
## Changelog
See [changelog.md](https://github.com/overlookmotel/is-bluebird/blob/master/changelog.md)
## Issues
If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/is-bluebird/issues
## Contribution
Pull requests are very welcome. Please:
* ensure all tests pass before submitting PR
* add an entry to changelog
* add tests for new features
* document new functionality/API additions in README
+16
View File
@@ -0,0 +1,16 @@
# Changelog
## 1.0.0
* Initial release
## 1.0.1
* Fix README typo
## 1.0.2
* Update `bluebird` dev dependencies
* Update dev dependencies
* Additional tests
* Travis CI tests all branches (to enable `greenskeeper.io`)
+79
View File
@@ -0,0 +1,79 @@
// --------------------
// is-bluebird module
// --------------------
// exports
/**
* Identifies whether input is a bluebird promise.
* @param {*} promise - Input to be tested
* @returns {boolean} - true if is a bluebird promise, false if not
*/
var isBluebird = function(promise) {
return isObject(promise) && isBluebird.ctor(promise.constructor);
};
/**
* Identifies whether input is a bluebird promise constructor.
* @param {*} Promise - Input to be tested
* @returns {boolean} - true if is bluebird promise constructor, false if not
*/
isBluebird.ctor = function(Promise) {
return typeof Promise == 'function' && !!Promise.prototype && typeof Promise.prototype._addCallbacks == 'function';
};
/**
* Identifies whether input is a bluebird v2 promise.
* @param {*} promise - Input to be tested
* @returns {boolean} - true if is a bluebird v2 promise, false if not
*/
isBluebird.v2 = function(promise) {
return isObject(promise) && isBluebird.v2.ctor(promise.constructor);
};
/**
* Identifies whether input is bluebird v2 promise constructor.
* @alias isBluebird.ctor.v2
*
* @param {*} promise - Input to be tested
* @returns {boolean} - true if is a bluebird v2 promise, false if not
*/
isBluebird.v2.ctor = function(Promise) {
return isBluebird.ctor(Promise) && Promise.prototype._addCallbacks.length == 6;
};
isBluebird.ctor.v2 = isBluebird.v2.ctor;
/**
* Identifies whether input is a bluebird v3 promise.
* @param {*} promise - Input to be tested
* @returns {boolean} - true if is a bluebird v3 promise, false if not
*/
isBluebird.v3 = function(promise) {
return isObject(promise) && isBluebird.v3.ctor(promise.constructor);
};
/**
* Identifies whether input is bluebird v3 promise constructor.
* @alias isBluebird.ctor.v3
*
* @param {*} promise - Input to be tested
* @returns {boolean} - true if is a bluebird v3 promise, false if not
*/
isBluebird.v3.ctor = function(Promise) {
return isBluebird.ctor(Promise) && Promise.prototype._addCallbacks.length == 5;
};
isBluebird.ctor.v3 = isBluebird.v3.ctor;
/**
* Check if input is an object.
* @param {*} obj - Input to be tested
* @returns {boolean} - true if is an object, false if not
*/
function isObject(obj) {
return !!obj && typeof obj == 'object';
}
// export isBluebird
module.exports = isBluebird;
+78
View File
@@ -0,0 +1,78 @@
{
"_args": [
[
"is-bluebird@1.0.2",
"/home/app"
]
],
"_from": "is-bluebird@1.0.2",
"_id": "is-bluebird@1.0.2",
"_inBundle": false,
"_integrity": "sha1-CWQ5Bg9KpBGr7hkUOoTWpVNG1uI=",
"_location": "/is-bluebird",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "is-bluebird@1.0.2",
"name": "is-bluebird",
"escapedName": "is-bluebird",
"rawSpec": "1.0.2",
"saveSpec": null,
"fetchSpec": "1.0.2"
},
"_requiredBy": [
"/cls-bluebird"
],
"_resolved": "https://registry.npmjs.org/is-bluebird/-/is-bluebird-1.0.2.tgz",
"_spec": "1.0.2",
"_where": "/home/app",
"author": {
"name": "Overlook Motel"
},
"bugs": {
"url": "https://github.com/overlookmotel/is-bluebird/issues"
},
"dependencies": {},
"description": "Is this a bluebird promise I see before me?",
"devDependencies": {
"bluebird2": "^3.0.0",
"bluebird3": "^3.0.6",
"chai": "^3.5.0",
"coveralls": "^2.11.12",
"istanbul": "^0.4.5",
"jshint": "^2.9.3",
"mocha": "^3.0.2"
},
"engines": {
"node": ">=0.10.0"
},
"homepage": "https://github.com/overlookmotel/is-bluebird#readme",
"keywords": [
"bluebird",
"promise",
"is",
"instance",
"constructor",
"version",
"then",
"check",
"test"
],
"license": "MIT",
"main": "./lib/",
"name": "is-bluebird",
"repository": {
"type": "git",
"url": "git+https://github.com/overlookmotel/is-bluebird.git"
},
"scripts": {
"cover": "npm run cover-main && rm -rf coverage",
"cover-main": "COVERAGE=true ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec 'test/**/*.test.js'",
"coveralls": "npm run cover-main && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"jshint": "jshint lib test",
"test": "if [ $COVERAGE ]; then npm run coveralls; else npm run jshint && npm run test-main; fi",
"test-main": "./node_modules/mocha/bin/mocha --check-leaks --colors -t 10000 --reporter spec 'test/**/*.test.js'"
},
"version": "1.0.2"
}