Skip to content

shusiwei/tiny

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tiny.js一个现代JavaScript实用程序库,可以运行在NodeJS和现代浏览器中。 该项目代码托管在GitHub

##注释说明

// 参数a, b 为必要参数,c, d为可选参数
function(a, b[, c, d]) {

}
* a = String ['default value'] // 参数a的数据类型为 string , 默认参数为'default value',* 代表必填参数, [] 代表参数默认值

##安装 ####git

git clone https://github.com/shusiwei/tiny.git

####npm

npm install --save shusiwei/tiny

####bower

bower install --save shusiwei/tiny

##使用

####CommonJS

const tiny = require('tiny');

####ES2015

import tiny form 'tiny';

// 或是方法名,例如:
import {isArray} form 'tiny';

##方法

####isUndefined 判断一个值的数据类型是否为undefined

isUndefined(undefined)
// -> true

isUndefined(null)
// -> false

####isNull 判断一个值的数据类型是否为null

isNull(undefined)
// -> false

isNull(null)
// -> true

####isBoolean 判断一个值的数据类型是否为Boolean

isBoolean(undefined)
// -> false

isBoolean(1)
// -> false

isBoolean(false)
// -> true

####isNumber 判断一个值的数据类型是否为Number

isNumber(1)
// -> true

isNumber(0.98)
// -> true

isNumber('1.6')
// -> false

####isFinite 判断一个值是否为有穷数

isFinite(15)
// -> true

isFinite(Number.MIN_VALUE)
// -> false

isFinite(Infinity)
// -> false

isFinite(NaN)
// -> false

isFinite('8')
// -> false

####isInteger 判断一个值是否为整数

isInteger(15)
// -> true

isInteger(0)
// -> true

isInteger(1.8)
// -> false

####isFloat 判断一个值是否为浮点数

isFloat(15)
// -> false

isFloat(0)
// -> false

isFloat(1.8)
// -> false

####isSafeInteger 判断一个值是否为浮点数

isSafeInteger(15)
// -> true

isSafeInteger(0)
// -> true

isSafeInteger(1.8)
// -> false

####isPositive 判断一个值是否为正数

isPositive(15)
// -> true

isPositive(0)
// -> false

isPositive(-1.5)
// -> false

####isNegative 判断一个值是否为负数

isNegative(15)
// -> false

isNegative(0)
// -> false

isNegative(-1.5)
// -> true

####isPosiInteger 判断一个值是否为正整数

isPosiInteger(15)
// -> true

isPosiInteger(1.8)
// -> false

isPosiInteger(-5)
// -> false

isPosiInteger(0)
// -> false

####isNegaInteger 判断一个值是否为负整数

isNegaInteger(15)
// -> false

isNegaInteger(1.8)
// -> false

isNegaInteger(-5)
// -> true

isNegaInteger(0)
// -> false

####isPosiFloat 判断一个值是否为正浮点数

isPosiFloat(15)
// -> false

isPosiFloat(1.8)
// -> true

isPosiFloat(-5)
// -> false

isPosiFloat(-5.8)
// -> false

isPosiFloat(0)
// -> false

####isNegaFloat 判断一个值是否为负浮点数

isNegaFloat(15)
// -> false

isNegaFloat(1.8)
// -> false

isNegaFloat(-5)
// -> false

isNegaFloat(-5.8)
// -> true

isNegaFloat(0)
// -> false

####isString 判断一个值的数据类型是否为String

isString(1.6)
// -> false

isString('1.6')
// -> true

isString('hello world')
// -> true

isString('')
// -> true

####isFunction 判断一个值的数据类型是否为Boolean

isFunction(() => {});
// -> true

isFunction(parseInt);
// -> true

isFunction({key: value})
// -> false

####isObject 判断一个值的数据类型是否为Object

isObject({key: value});
// -> false

isObject(new Foo);
// -> true

isObject(null);

isObject([1, 2, 3]);
// -> false
// -> flase

####isArray 判断一个值的数据类型是否为Boolean

isArray([1, 2, 3]);
// -> true

isArray({0: 1, 1: 2, length: 2});
// -> flase

####isObjectLike 判断一个值的数据类型是否为类似于Object的对象

isObjectLike([1, 2, 3]);
// -> true

isObjectLike({key: value});
// -> true

isObjectLike(arguments);
// -> true

isObjectLike(new Foo);
// -> true

isObjectLike(null);
// -> flase

####indexOf

indexOf(object, value) // 得到一个值在某个集合中的索引位置,如果不存在则返回-1
* object = array/object/string // 集合
* value = * // 值

####includes

includes(object, value) // 得到一个集合中是否包含某个值
* object = array/object/string // 集合
* value = * // 值

##方法集合

####getTimeStamp

tiny.getTimeStamp() // 得到当前时间戳

####getRandom

tiny.getRandom() // 得到一个随机数

####getRandomStamp

tiny.getRandomStamp(length, repeat) // 得到一个随机戳
length = number [16] // 长度
repeat = boolean [false] // 字符是否允许重复

About

A modern JavaScript utility library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published