Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

front-uitls

lixueshiaa125ISC1.2.3

this is a simple front-end tool for opening source development

front-tool, js, tool, simple-tool, formatDate, formatThousand, randomn, merge, toArray, isPlainObject, isPromise, toNumber, extend

readme

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] ( 合并属性到目标对象 ) `js 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] ( 数组对象转为简单对象 )
```js
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] ( 合并对象到目标对象 默认第一个参数为目标对象并返回对象 ) `js
    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```js
randomn(5)
//=> 13560
randomn(21)
//=> 124406475752653050000
  • formatThousand [type Function => return String]( 数字金额千分位格式化 ) `js formatThousand(5435345.45) //=> "5,435,345.45" formatThousand(564565465.56456456) //=> "564,565,465.5645646"

// 同样的,你也可以在vue框架中使用, 如下实例demo.

<template>
{{ number1 | formatThousand }}
</template>

import { formatThousand } from 'front-uitls' export default { data () { return { number1: 234234.3434 } }, filters: { formatThousand } }

<style lang="less"> </style>

- `formatDate` [type Function => return String]( 时间戳转为日期格式 )
```js
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]