1.0.7 • Published 4 years ago

@webtanzhi/utils v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

utils

  • 支持 node 环境

开发规则

  • 必须ts开发
  • 必须写测试脚本,必须测试通过方可发布
  • 尽可能少的调用外部仓库

构建

根据 webpack 优先加载 module 和 browser

https://github.com/SunshowerC/blog/issues/8

使用

npm i @webtanzhi/utils

功能列表

  • isFunction (value) => boolean value是不是一个方法
  • isObject (value) => boolean value是不是一个对象
  • isNullOrUndefined (value) => boolean value是否已经定义
  • isPromise (value) => boolean 简单判断是否是Promise(通过.then)
  • isBrowser boolean 是否为浏览器环境
  • isNumber (value) => boolean 判断类型是否数字
  • getDocumentHeight () => number document的高度
  • unShownHeight () => number document没有展示出的高度
  • getTopDomain (domainStr) => string 获取顶级域名
  • (node)sha1 (string|Buffer) => string sha1加密计算
  • (browser)sha1 (string) => string sha1字符加密计算
  • formatUrl (string) => FormatedUrl 把url转换为location
  • setSession (key: string, value: any, options:{maxAge?: number;,expire?: number;}) => void 存放数据到sessionStorage中,并设置存储时长(node环境之下不生效,不报错)
  • getSession (key: string) => any | null 获取存入的数据,不存在的话返回null
  • setLocalStorage (key: string, value: any, options:{maxAge?: number;,expire?: number;}) => void 存放数据到localStorage中,并设置存储时长(node环境之下不生效,不报错)
  • getLocalStorage (key: string) => any | null 获取存入的数据,不存在的话返回null
  • centPrice (value: number|string, multiple = 100) => number
  • formatAmount (price,{sectionSize: number 位数 = 3,separator: string 分割符号 = ','}) => string
  • formatPrice formatPrice(originPrice:sting|number,opt?:FormatPriceOption) 根据配置项返回格式化后的价格结果
  • generateFormatPrice 返回一个带自定义配置项的customFormatPrice方法,返回的customFormatPrice与formatPrice用法完全相同
  • generateCentPrice 返回一个带自定义配置项的customCentPrice方法,返回的customCentPrice与centPrice用法完全相同