front-uitls
Install
[npm][]:
$ npm install front-uitls
front-uitls 是一个简单的前端工具库, 提供各种前端常用而且便捷的方法 可以快速使用 主旨在提供一套逻辑判断的全面js方法库
Use
API
-
hasProto
[type Boolcan] ( 判断是否存在隐形原型'proto' ) -
inBrowser
[type Boolean] ( 判断是否是存在window对象 ) -
isIE
[type Boolean] ( 判断是否是IE浏览器 ) -
isIE9
[type Boolean] -
isEdge
[type Boolean] -
isAndroid
[type Boolean] -
isIOS
[type Boolean] -
isChrome
[type Boolean] -
isFF
[type Boolean] ( 是否是火狐浏览器 ) -
isUndef
[type Function => return Boolean] ( 判断是否是未定义 ) -
isDef
[type Function => return Boolean] ( 判断是否是已定义 ) -
isTrue
[type Function => return Boolean] -
isFalse
[type Function => return Boolean] -
isObject
[type Function => return Boolean] ( 判断是否为对象 如 Array Object Number String等js内部对象 ) -
isPlainObject
[type Function => return Boolean] ( 判断是否是{}对象 如 )
//=> true
-
isRegExp
[type Function => return Boolean] ( 判断是否是正则对象 ) -
isPromise
[type Function => return Boolean] ( 判断是否是Promise对象 ) -
toString
[type Function => return String] ( 转为字符串 如 )
//=> '{a: 3}' //=> '[3]' //=> '3'
-
toNumber
[type Function => return Number] ( 转为数字 ) -
toArray
[type Function => return Number] ( 把字符串转为字符串数组 )
//=> ['s', '3', '4', '3', '4']
extend
[type Function => return Object] ( 合并属性到目标对象 )
// to 目标对象 _from 源对象 //=> {a: 2, b: 4, c: 5}
toObject
[type Function => return Object] ( 数组对象转为简单对象 )
//=> {a:2, b: 5, c:4, e: 6}
identity
[type Function] ( 返回同样值 )
//=> 3 //=> {} //=> [3]
-
no
[type Function => return false] ( 返回false值 ) -
merge
[type Function => return Object] ( 合并对象到目标对象 默认第一个参数为目标对象并返回对象 )
//=> {a: 3, b: 4, c: 5, d: 5, e: 6}
randomn
[type Function => return Number] ( 获取n位随机数,n小于22 )
//=> 13560//=> 124406475752653050000
formatThousand
[type Function => return String]( 数字金额千分位格式化 )
//=> "5,435,345.45"//=> "564,565,465.5645646" // 同样的,你也可以在vue框架中使用, 如下实例demo. <template> <div> number1 | formatThousand </div></template> { return number1: 2342343434 } filters: formatThousand <style lang="less"></style>
formatDate
[type Function => return String]( 时间戳转为日期格式 )
// date 时间戳(单位毫秒) fmt 日期格式 (默认值 'yyyy-MM-dd hh:mm')//=> "2012-12-12 01:34"//=> "2012/12/12 01:34" // 同样的,你也可以在vue框架中使用, 如下实例demo. <template> <div> date1 | </div></template> { return date1: 1355247273000 } filters: formatDate <style lang="less"></style>
getType
[type Function => return String]( 获取数据的类型描述 )
// 数值类型描述 => "number" "string" "array" "object" "null" "undefined"//=> "number"//=> "string"//=> "array"//=> "object"//=> "null"//=> "undefined"
clone
[type Function(U) => return U]( 数据克隆 )
//=> 3//=> "test"//=> {a: 3, b: 34}//=> [343, 434]