npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

turbo_miniapp_util

v1.1.8

Published

集成微信小程序常用功能

Readme

微信小程序常用工具

import Util from 'turbo_miniapp_util'

formatTime

let now = Uitl.formatTime()
// 2020/11/01 12:15:35

formatNumber

Uitl.formatNumber(1)
// 01

Uitl.formatNumber(10)
// 10

hasOwn

let obj = {
  a:1,
  c:2
}
Uitl.hasOwn(obj,'a')
// true
Uitl.hasOwn(obj,'b')
// false

isArray

let arr = [1,2]
Uitl.isArray(arr)
// true

isDefined

Uitl.isDefined(b)
// false

isUndefined

Uitl.isUndefined(b)
// true

isEmail

Uitl.isEmail('[email protected]')
// true

isEmpty

Uitl.isEmpty('')
// true

isFunction

Uitl.isFunction('')
// false

isNumber

Uitl.isNumber('')
// false
Uitl.isNumber('234')
// false
Uitl.isNumber(12.5)
// true
Uitl.isNumber(12)
// true
Uitl.isNumber(NaN)
// false

isObject

isPhone

isString

isUrl

isWechat

getArray

getObject

getNumber

getString

getFunction

json

parse

strToObject

rtrim

删除右边的空格

ltrim

删除左边的空格

trim

删除两边的空格

strim

删除所有的空格

strlen

字符串计算字符长度(英文一个字符,中文为2个字符)

leavetime

let time_end = '2020/12/12 12:12:59'
let str = Util.leavetime(time_end, 'D天H时M分S秒')
// 5天6时35分9秒

timeformat

let nowtime = Util.timeformat()
let timestr = Util.timeformat(1581223453, 'y-m-d h:i:s')
let timestamp = Util.timeformat("2020-01-02", 'timestamp')

calcDistance

let distance = Util.calcDistance(lat1, lng1, lat2, lng2)

isWxMiniapp

page

let page = Util.page()
// {
//   pages: [...],
//   current: {},
//   url: '/pages/...',
//   options: {}
// }

toast

Util.toast("thanks")

confirm

Util.confirm({
  title: "提示",
  content: "确定要关闭吗",
  confirm: () => {

  },
  cancel: () => {

  }
})

loading

Util.loading({
  title: '加载中...',
  mask: true
})
// or
Util.loading('加载中...')

closeToast

Util.closeToast()
// 等同于执行
// wx.hideLoading()
// wx.hideToast()

navigator

// 接受tab/普通页面路径
Util.navigator(url)

saveImage

Util.saveImage(imageUrl).then().catch(e)

getLocation

Util.getLocation({
  tip: "我们需要您授权位置信息"
}).then(res => {
  // code
}).catch(e)

upload

    // 支持多图上传 已经内置文件选择,页面直接调用函数即可(默认为上传图片)

    // 上传图片
    Util.upload({
      url: 'http://www.bookbag.com/api/common/upload',
      name: "file",
      count: 1,
      formData: {},
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      process: (res) => {
        console.log("上传进度",res)
      }
    }).then(res=>{
      console.log("上传结果", res)
    }).catch(e=>{
      console.log("err", e)
    })

    // 上传视频
    Util.upload({
      type: 'video',
      url: 'http://www.bookbag.com/api/common/upload',
      maxDuration: 60,
      formData: {},
      compressed: true,
      process: (res) => {
        console.log("上传进度", res)
      }
    }).then(res => {
      console.log("上传结果", res)
    }).catch(e => {
      console.log("err", e)
    })

getWxcode

// 获取微信小程序登录的code码
Util.getWxcode().then(code=>{
  // code
}).catch(e=>{

})

setToken

setUinfo

setUid

getToken

getUinfo

getUid