Skip to content

Commit

Permalink
add: intail
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Jun 18, 2019
0 parents commit f91a14d
Show file tree
Hide file tree
Showing 19 changed files with 367 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
bower_components
coverage
npm-debug.log
yarn.lock
package-lock.json
.DS_Store
.idea
.vscode
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.idea
.DS_Store
**/npm-debug.log
**/node_modules
test
src
build
gulpfile.js
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
package-lock=false
36 changes: 36 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"trailingComma": "none",
"arrowParens": "always",
"printWidth": 80,
"bracketSpacing": true,
"jsxBracketSameLine": true,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"overrides": [
{
"files": "*.scss",
"options": {
"trailingComma": "none",
"tabWidth": 2,
"parser": "scss"
}
},
{
"files": "*.json",
"options": {
"trailingComma": "none",
"tabWidth": 2,
"parser": "json"
}
},
{
"files": "*.md",
"options": {
"trailingComma": "none",
"tabWidth": 2,
"parser": "json"
}
}
]
}
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 afei <1290657123@qq.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.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# next-is-promise
> Test whether an object looks like a promisesA+ promise
## installation
```bash
npm install -S afeiship/next-is-promise --registry=https://registry.npm.taobao.org
```

## usage
```js
//DOCS here!
```

## resources
- https://github.com/then/is-promise
28 changes: 28 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "next-is-promise",
"version": "0.0.1",
"description": "Test whether an object looks like a promisesA+ promise",
"main": "dist/next-is-promise.js",
"authors": [
"afei"
],
"license": "MIT",
"keywords": [
"next"
],
"homepage": "https://github.com/afeiship/next-is-promise",
"moduleType": [
"amd"
],
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests",
"build",
"src",
"gulp",
"gulpfile.js"
]
}
17 changes: 17 additions & 0 deletions build/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(function() {
'use strict';

const gulp = require('gulp');
const config = require('./config');
const $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'del']
});

//clean
gulp.task(
'clean',
gulp.parallel(function() {
return $.del('dist');
})
);
})();
29 changes: 29 additions & 0 deletions build/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(function() {
'use strict';

const rootPath = process.cwd();
const gulp = require('gulp');
const saveLicense = require('uglify-save-license');

module.exports = {
path: {
root: rootPath,
src: rootPath + '/src',
dist: rootPath + '/dist',
gulp: rootPath + '/gulp'
},
sassOptions: {
normal: {
outputStyle: 'expanded' /* nested | expanded | compact | compressed */
},
minify: {
outputStyle: 'compressed'
}
},
uglifyOptions: {
output: {
comments: saveLicense
}
}
};
})();
38 changes: 38 additions & 0 deletions build/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function() {
'use strict';

const gulp = require('gulp');
const config = require('./config');
const pkg = require('../package.json');
const saveLicense = require('uglify-save-license');
const $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'del']
});

require('next-nice-comments');

const niceComments = nx.niceComments(
[
'name: <%= pkg.name %>',
'url: <%= pkg.homepage %>',
'version: <%= pkg.version %>',
'license: <%= pkg.license %>'
],
'js'
);

gulp.task(
'scripts',
gulp.parallel(function() {
return gulp
.src('src/*.js')
.pipe($.header(niceComments, { pkg: pkg }))
.pipe(gulp.dest('dist'))
.pipe($.size({ title: '[ default size ]:' }))
.pipe($.uglify(config.uglifyOptions))
.pipe($.rename({ extname: '.min.js' }))
.pipe(gulp.dest('dist'))
.pipe($.size({ title: '[ minimize size ]:' }));
})
);
})();
23 changes: 23 additions & 0 deletions build/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function() {
'use strict';

var gulp = require('gulp');
var $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'del']
});

/**
* @thanks to:
* http://www.jianshu.com/p/d616d3bf391f
*/

gulp.task(
'bump',
gulp.parallel(function() {
gulp
.src(['./*.json'])
.pipe($.bump())
.pipe(gulp.dest('./'));
})
);
})();
25 changes: 25 additions & 0 deletions dist/next-is-promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*!
* name: next-is-promise
* url: https://github.com/afeiship/next-is-promise
* version: 1.0.0
* license: MIT
*/

(function() {
var global = global || this || window || Function('return this')();
var nx = global.nx || require('next-js-core2');
var OBJ = 'object';
var FUNC = 'function';

nx.isPromise = function(inObj) {
return (
!!inObj &&
(typeof inObj === OBJ || typeof inObj === FUNC) &&
typeof obj.then === FUNC
);
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = nx.isPromise;
}
})();
7 changes: 7 additions & 0 deletions dist/next-is-promise.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*!
* name: next-is-promise
* url: https://github.com/afeiship/next-is-promise
* version: 1.0.0
* license: MIT
*/
!function(){var e=e||this||window||Function("return this")(),o=e.nx||require("next-js-core2");o.isPromise=function(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof obj.then},"undefined"!=typeof module&&module.exports&&(module.exports=o.isPromise)}();
13 changes: 13 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function() {
'use strict';

const gulp = require('gulp');
const fs = require('fs');

//import
fs.readdirSync('./build').map(function(file) {
require('./build/' + file);
});

gulp.task('default', gulp.series(['clean', 'scripts']));
})();
36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "next-is-promise",
"version": "1.0.0",
"description": "Test whether an object looks like a promisesA+ promise",
"homepage": "https://github.com/afeiship/next-is-promise",
"author": {
"name": "afei",
"email": "1290657123@qq.com"
},
"scripts": {
"build": "gulp",
"test": "jest",
"version": "gulp bump"
},
"main": "dist/next-is-promise.js",
"license": "MIT",
"devDependencies": {
"del": "^2.2.1",
"gulp": "^4.0.2",
"gulp-bump": "^3.1.3",
"gulp-concat": "^2.6.0",
"gulp-header": "^2.0.7",
"gulp-load-plugins": "^1.2.0",
"gulp-rename": "^1.2.2",
"gulp-size": "^2.1.0",
"gulp-uglify": "^2.1.2",
"jest": "^23.6.0",
"yargs": "^4.7.1",
"uglify-save-license": "^0.4.1",
"prettier": "^1.14.3",
"next-nice-comments": "github:afeiship/next-nice-comments"
},
"dependencies": {
"next-js-core2": "github:afeiship/next-js-core2"
}
}
18 changes: 18 additions & 0 deletions src/next-is-promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function() {
var global = global || this || window || Function('return this')();
var nx = global.nx || require('next-js-core2');
var OBJ = 'object';
var FUNC = 'function';

nx.isPromise = function(inObj) {
return (
!!inObj &&
(typeof inObj === OBJ || typeof inObj === FUNC) &&
typeof obj.then === FUNC
);
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = nx.isPromise;
}
})();
16 changes: 16 additions & 0 deletions test/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="../node_modules/next-js-core2/dist/next-js-core2.js"></script>
<script src="../src/next-is-promise.js"></script>
</head>
<body>
<script>
//YOUR CODES
</script>
</body>
</html>
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var nx = require('next-js-core2');
require('../src/next-is-promise');


test('nx.isPromise', function () {
var obj1 = {name: 'fei'};
var obj2 = {email: '1290657123@qq.com'};

var result = {};

nx.isPromise(result, obj1, obj2);

expect(result.name, obj1.name).toBe(null);
});

0 comments on commit f91a14d

Please sign in to comment.