front-uitls

1.2.3 • Public • Published

front-uitls

Install

[npm][]:

$ npm install front-uitls

front-uitls 是一个简单的前端工具库, 提供各种前端常用而且便捷的方法 可以快速使用 主旨在提供一套逻辑判断的全面js方法库

Use

import {isIE, inBrowser, isIE, isIE9, isEdge, isAndroid, isIOS, ...} from 'front-uitls'

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] ( 判断是否是{}对象 如 )

isPlainObject({})
//=> true
  • isRegExp [type Function => return Boolean] ( 判断是否是正则对象 )

  • isPromise [type Function => return Boolean] ( 判断是否是Promise对象 )

  • toString [type Function => return String] ( 转为字符串 如 )

toString({a: 3}) 
//=> '{a: 3}' 
toString([3]) 
//=> '[3]' 
toString(3) 
//=> '3'
  • toNumber [type Function => return Number] ( 转为数字 )

  • toArray [type Function => return Number] ( 把字符串转为字符串数组 )

toArray('ass3434', 2)
//=> ['s', '3', '4', '3', '4']
  • extend [type Function => return Object] ( 合并属性到目标对象 )
extend(to, _from) // to 目标对象 _from 源对象 
 
extend({a: 2, b: 3}, {b: 4, c: 5})
//=> {a: 2, b: 4, c: 5}
  • toObject [type Function => return Object] ( 数组对象转为简单对象 )
toObject([{a:2, b: 3}, {c: 4}, {b: 5, e: 6}])
//=> {a:2, b: 5, c:4, e: 6}
  • identity [type Function] ( 返回同样值 )
identity(3)
//=> 3 
identity({}) 
//=> {} 
identity([3]) 
//=> [3]
  • no [type Function => return false] ( 返回false值 )

  • merge [type Function => return Object] ( 合并对象到目标对象 默认第一个参数为目标对象并返回对象 )

merge(obj2, obj3, obj4, ...)
 
merge({a: 2, b: 4}, {a: 3, c: 5}, {d: 5, e: 6})
//=> {a: 3, b: 4, c: 5, d: 5, e: 6}
  • randomn [type Function => return Number] ( 获取n位随机数,n小于22 )
randomn(5)
//=> 13560
randomn(21)
//=> 124406475752653050000
  • formatThousand [type Function => return String]( 数字金额千分位格式化 )
formatThousand(5435345.45)
//=> "5,435,345.45"
formatThousand(564565465.56456456)
//=> "564,565,465.5645646"
 
// 同样的,你也可以在vue框架中使用, 如下实例demo.
 
<template>
    <div>{{ number1 | formatThousand }}</div>
</template>
 
import { formatThousand } from 'front-uitls'
export default {
  data () {
    return {
      number1: 234234.3434
    }
  },
  filters: {
    formatThousand
  }
}
 
<style lang="less">
</style>
  • formatDate [type Function => return String]( 时间戳转为日期格式 )
formatDate(date, fmt) // date 时间戳(单位毫秒) fmt 日期格式 (默认值 'yyyy-MM-dd hh:mm')
formatDate(1355247273000)
//=> "2012-12-12 01:34"
formatDate(1355247273000, 'yyyy/MM/dd hh:mm')
//=> "2012/12/12 01:34"
 
// 同样的,你也可以在vue框架中使用, 如下实例demo.
 
<template>
    <div>{{ date1 | formatDate('yyyy/MM/dd') }}</div>
</template>
 
import { formatDate } from 'front-uitls'
export default {
  data () {
    return {
      date1: 1355247273000
    }
  },
  filters: {
    formatDate
  }
}
 
<style lang="less">
</style>
  • getType [type Function => return String]( 获取数据的类型描述 )
// 数值类型描述 => "number" "string" "array" "object" "null" "undefined"
getType(3)
//=> "number"
getType('adf')
//=> "string"
getType([{a: 3}, 3])
//=> "array"
getType({d: 4})
//=> "object"
getType(null)
//=> "null"
getType(undefined)
//=> "undefined"
  • clone [type Function(U) => return U]( 数据克隆 )
clone(3)
//=> 3
clone('test')
//=> "test"
clone({a: 3, b: 34})
//=> {a: 3, b: 34}
clone([343, 434])
//=> [343, 434]

Package Sidebar

Install

npm i front-uitls

Weekly Downloads

2

Version

1.2.3

License

ISC

Unpacked Size

15.6 kB

Total Files

6

Last publish

Collaborators

  • lixueshiaa