Skip to content

Commit ca3cb04

Browse files
author
颜海镜
committedMar 22, 2018
init
0 parents  commit ca3cb04

24 files changed

+5318
-0
lines changed
 

‎.babelrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
["env",
4+
{
5+
"targets": {
6+
"browsers": "last 2 versions, > 1%, ie >= 6",
7+
"node": "0.10"
8+
},
9+
"modules": false
10+
}]
11+
]
12+
}

‎.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[{*.js,*.css,*.html}]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
insert_final_newline = true
9+
10+
[{package.json,.*rc,*.yml}]
11+
indent_style = space
12+
indent_size = 2

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

‎.npmignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
config
3+
demo
4+
src
5+
test
6+
.babelrc
7+
.editorconfig
8+
.travis.yml
9+
CHANGELOG.md
10+
package-lock.json
11+
TODO.md

‎.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- "8"
4+
- "6"
5+
- "4"

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 变更日志

‎LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (C) 2018 yanhaijing
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

‎README.md

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# [is.js](https://github.com/yanhaijing/is.js) [![](https://img.shields.io/badge/Powered%20by-jslib%20base-brightgreen.svg)](https://github.com/yanhaijing/is.js) [![npm](https://img.shields.io/badge/npm-0.1.1-orange.svg)](https://www.npmjs.com/package/@yanhaijing/is_js) [![Build Status](https://travis-ci.org/yanhaijing/is.js.svg?branch=master)](https://travis-ci.org/yanhaijing/is.js) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/yanhaijing/is.js/blob/master/LICENSE)
2+
js判断函数,解决80%类型判断问题
3+
4+
## 兼容性
5+
单元测试保证支持如下环境:
6+
7+
- Node 4+
8+
- Safari 6+ (Mac)
9+
- iOS 5+ Safari
10+
- Chrome 23+ (Windows, Mac, Android, iOS, Linux, Chrome OS)
11+
- Firefox 4+ (Windows, Mac, Android, Linux)
12+
- Internet Explorer 6+ (Windows, Windows Phone)
13+
- Opera 10+ (Windows, linux, Android)
14+
15+
## 目录介绍
16+
17+
```
18+
.
19+
├── demo 使用demo
20+
├── dist 编译产出代码
21+
├── doc 项目文档
22+
├── src 源代码目录
23+
├── test 单元测试
24+
├── CHANGELOG.md 变更日志
25+
└── TODO.md 计划功能
26+
```
27+
28+
## 如何使用
29+
通过npm下载安装代码
30+
31+
```bash
32+
$ npm install --save @yanhaijing/is_js
33+
```
34+
35+
如果你是node环境
36+
37+
```js
38+
var isNumber = require('@yanhaijing/is_js').isNumber;
39+
40+
isNumber(1) // true
41+
```
42+
43+
如果你是webpack等环境
44+
45+
```js
46+
import { isNumber } from '@yanhaijing/is_js';
47+
48+
isNumber(1) // true
49+
```
50+
51+
如果你是requirejs环境
52+
53+
```js
54+
requirejs(['node_modules/@yanhaijing/is_js/dist/index.aio.js'], function (is_js) {
55+
var isNumber = is_js.isNumber;
56+
57+
isNumber(1) // true
58+
})
59+
```
60+
61+
如果你是浏览器环境
62+
63+
```html
64+
<script src="node_modules/@yanhaijing/is_js/dist/index.aio.js"></script>
65+
66+
<script>
67+
var isNumber = is_js.isNumber;
68+
69+
isNumber(1) // true
70+
</script>
71+
```
72+
73+
## 文档
74+
[API](./doc/api.md)
75+
76+
## 贡献指南
77+
首次运行需要先安装依赖
78+
79+
```bash
80+
$ npm install
81+
```
82+
83+
一键打包生成生产代码
84+
85+
```bash
86+
$ npm run build
87+
```
88+
89+
运行单元测试,浏览器环境需要手动测试,位于`test/browser`
90+
91+
```bash
92+
$ npm test
93+
```
94+
95+
修改package.json中的版本号,修改README.md中的版本号,修改CHANGELOG.md,然后发布新版
96+
97+
```bash
98+
$ npm run release
99+
```
100+
101+
将新版本发布到npm
102+
103+
```bash
104+
$ npm publish
105+
```
106+
107+
可能需要你自己修改的地方如下:
108+
109+
- README.md 中的信息
110+
- package.json 中的信息
111+
- config/rollup.js 中的信息
112+
- test/browser/index.html 中的仓库名称
113+
114+
## 更新日志
115+
[CHANGELOG.md](./CHANGELOG.md)
116+
117+
## 计划列表
118+
[TODO.md](./TODO.md)
119+
120+
## 谁在使用

‎TODO.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TODO

‎config/.eslintrc.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"es6": true,
5+
"node": true
6+
},
7+
"extends": "eslint:recommended",
8+
"parserOptions": {
9+
"sourceType": "module"
10+
},
11+
"rules": {
12+
"indent": [
13+
"error",
14+
4
15+
],
16+
"linebreak-style": [
17+
"error",
18+
"unix"
19+
],
20+
"quotes": [
21+
"error",
22+
"single"
23+
],
24+
"semi": [
25+
"error",
26+
"always"
27+
],
28+
"no-console": 0
29+
}
30+
};

‎config/rollup.config.aio.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// rollup.config.js
2+
3+
var babel = require("rollup-plugin-babel");
4+
var nodeResolve = require('rollup-plugin-node-resolve');
5+
var commonjs = require('rollup-plugin-commonjs');
6+
7+
var common = require('./rollup.js');
8+
9+
export default {
10+
input: 'src/index.js',
11+
output: {
12+
file: 'dist/index.aio.js',
13+
format: 'umd',
14+
name: common.name
15+
},
16+
banner: common.banner,
17+
plugins: [
18+
nodeResolve({
19+
main: true
20+
}),
21+
commonjs({
22+
include: 'node_modules/**',
23+
}),
24+
babel({
25+
exclude: 'node_modules/**'
26+
})
27+
]
28+
};

‎config/rollup.config.esm.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import config from './rollup.config';
2+
3+
// ES output
4+
config.output.format = 'es';
5+
config.output.file = 'dist/index.esm.js';
6+
7+
export default config;

‎config/rollup.config.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// rollup.config.js
2+
3+
var babel = require('rollup-plugin-babel');
4+
var common = require('./rollup.js');
5+
6+
export default {
7+
input: 'src/index.js',
8+
output: {
9+
file: 'dist/index.js',
10+
format: 'cjs',
11+
},
12+
banner: common.banner,
13+
plugins: [
14+
babel({
15+
exclude: 'node_modules/**'
16+
})
17+
]
18+
};

‎config/rollup.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var pkg = require('../package.json');
2+
3+
// 兼容 is.js 和 @yanhaijing/is.js
4+
var name = pkg.name.split('/').pop();
5+
var version = pkg.version;
6+
7+
var banner =
8+
`/*!
9+
* is.js ${version} (https://github.com/yanhaijing/is.js)
10+
* API https://github.com/yanhaijing/is.js/blob/master/doc/api.md
11+
* Copyright 2017-${(new Date).getFullYear()} yanhaijing. All Rights Reserved
12+
* Licensed under MIT (https://github.com/yanhaijing/is.js/blob/master/LICENSE)
13+
*/
14+
`;
15+
16+
exports.name = name;
17+
exports.banner = banner;

‎demo/demo-amd.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<script src='./js/require.js'></script>
9+
<script>
10+
requirejs(['../dist/index.aio.js'], function (base) {
11+
console.log(base.name)
12+
})
13+
</script>
14+
</body>
15+
</html>

‎demo/demo-global.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<script src="../dist/index.aio.js"></script>
9+
<script>
10+
console.log(jslib_base.name);
11+
</script>
12+
</body>
13+
</html>

‎demo/demo-node.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var base = require('../dist/index.js');
2+
console.log(base.name);

‎demo/js/require.js

+2,145
Large diffs are not rendered by default.

‎doc/api.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 文档
2+
一组类型判断函数,解决80%类型判断问题
3+
4+
## isNumber
5+
判断是否为数字,参数和返回值如下:
6+
7+
- @param x {任意类型} 要判断的参数
8+
- @return {Boolean} 是否为数字类型
9+
10+
## isBoolean
11+
判断是否为布尔类型,参数和返回值同上
12+
13+
## isString
14+
判断是否为字符串类型,参数和返回值同上
15+
16+
## isNull
17+
判断是否为null类型,参数和返回值同上
18+
19+
## isUndefined
20+
判断是否为undefined类型,参数和返回值同上
21+
22+
## isObject
23+
判断是否为对象类型,参数和返回值同上
24+
25+
## isFunction
26+
判断是否为函数类型,参数和返回值同上
27+
28+
## isArray
29+
判断是否为数组类型,参数和返回值同上

‎package-lock.json

+2,715
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "@yanhaijing/is_js",
3+
"version": "0.1.0",
4+
"description": "js判断函数,解决80%类型判断问题",
5+
"main": "dist/index.js",
6+
"jsnext:main": "dist/index.esm.js",
7+
"module": "dist/index.esm.js",
8+
"scripts": {
9+
"clean": "rm -rf ./dist",
10+
"lint": "./node_modules/.bin/eslint -c ./config/.eslintrc.js src",
11+
"build:self": "./node_modules/rollup/bin/rollup -c config/rollup.config.js",
12+
"build:esm": "./node_modules/rollup/bin/rollup -c config/rollup.config.esm.js",
13+
"build:aio": "./node_modules/rollup/bin/rollup -c config/rollup.config.aio.js",
14+
"build": "npm run clean && npm run build:self && npm run build:esm && npm run build:aio",
15+
"test": "npm run lint && npm run build && mocha",
16+
"release": "npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags"
17+
},
18+
"author": "yanhaijing",
19+
"license": "MIT",
20+
"repository": {
21+
"type": "git",
22+
"url": "git://github.com/yanhaijing/jslib-base.git"
23+
},
24+
"bugs": {
25+
"url": "https://github.com/yanhaijing/jslib-base/issues"
26+
},
27+
"devDependencies": {
28+
"babel-core": "6.26.0",
29+
"babel-preset-env": "1.6.1",
30+
"eslint": "4.18.2",
31+
"expect.js": "0.3.1",
32+
"mocha": "3.5.3",
33+
"rollup": "0.56.4",
34+
"rollup-plugin-babel": "3.0.3",
35+
"rollup-plugin-commonjs": "8.3.0",
36+
"rollup-plugin-node-resolve": "3.0.3"
37+
},
38+
"dependencies": {
39+
"@yanhaijing/type_js": "0.1.0"
40+
}
41+
}

‎src/index.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { type } from '@yanhaijing/type_js';
2+
3+
export function isNumber(x) {
4+
return type(x) === 'number';
5+
}
6+
7+
export function isBoolean(x) {
8+
return type(x) === 'boolean';
9+
}
10+
11+
export function isString(x) {
12+
return type(x) === 'string';
13+
}
14+
15+
export function isNull(x) {
16+
return type(x) === 'null';
17+
}
18+
19+
export function isUndefined(x) {
20+
return type(x) === 'undefined';
21+
}
22+
23+
export function isObject(x) {
24+
return type(x) === 'object';
25+
}
26+
27+
export function isFunction(x) {
28+
return type(x) === 'function';
29+
}
30+
31+
export const isArray = isFunction(Array.isArray) ? Array.isArray : function isArray(x) {
32+
return type(x) === 'array';
33+
};

‎test/browser/index.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>Mocha</title>
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
9+
</head>
10+
11+
<body>
12+
<div id="mocha"></div>
13+
<script src="../../node_modules/mocha/mocha.js"></script>
14+
<script src="../../node_modules/expect.js/index.js"></script>
15+
<script>
16+
mocha.setup('bdd');
17+
</script>
18+
<script src="../../dist/index.aio.js"></script>
19+
<script>
20+
var libs = {
21+
'expect.js': expect,
22+
'../dist/index.js': is_js
23+
};
24+
var require = function(path) {
25+
return libs[path];
26+
}
27+
</script>
28+
<script src="../test.js"></script>
29+
<script>
30+
mocha.run();
31+
</script>
32+
</body>
33+
34+
</html>

‎test/test.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var expect = require('expect.js');
2+
3+
var is = require('../dist/index.js');
4+
5+
describe('单元测试', function() {
6+
this.timeout(1000);
7+
8+
describe('功能', function() {
9+
it('相等', function() {
10+
expect(is.isNumber(1)).to.equal(true);
11+
expect(is.isBoolean(true)).to.equal(true);
12+
expect(is.isString('')).to.equal(true);
13+
expect(is.isNull(null)).to.equal(true);
14+
expect(is.isUndefined()).to.equal(true);
15+
expect(is.isObject({})).to.equal(true);
16+
expect(is.isArray([])).to.equal(true);
17+
expect(is.isFunction(function () {})).to.equal(true);
18+
});
19+
});
20+
});

0 commit comments

Comments
 (0)
Please sign in to comment.