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

wxbase

v0.0.2

Published

封装微信小程序常用的基础功能

Readme

wxbase

封装微信小程序常用的基础功能

安装

$ npm i -D wxbase

使用说明

将安装好的wxbase从 node_modules 拷贝到 utils 目录使用

若需要完整的wxbase,则引用wxbase.js

在app.js页面引入wxbase.js

import wxbase from './utils/wxbase/wxbase'
// 并添加wxbase到App object参数中
App({
  wxbase
})

文件说明

wxbase.js 是包含微信基础功能、处理日期的常用功能和解决js浮点计算问题的计算功能。后续可能会继续增加新的类型。

允许按需引入

各个功能的使用说明

微信通用功能介绍

appUpdate

用于检测小程序是否有新版本,仅在 app.js 的 onLaunch 内调用,且仅调用一次。

wxbase.appUpdate()

sceneParam

用来获取二维码携带的参数。 该函数仅可在 onLoad 内调用,只在可扫码到达的页面内调用。

/**
 * 假设 scene = { id: 1 }
 */
onLoad({scene=null}) {
  if (scene) {
    let { id } = app.wxbase.sceneParam(scene)
  }
}

isShare

判断当前页面是否从分享方式进入 该函数只在app.js调用,且在进入的页面设置还原状态。

/**
 * app.js
 */
onShow({ scene }) {
  this.globalData.isShare = wxbase.isShare(scene)
}
/**
 * 具体进入的页面
 * 离开该页面时,分享状态还原
 */
onHide() {
  app.globalData.isShare = false
}

日期

format

日期格式化

第一个参数传 date,第二个参数传入格式化的要求 支持用以下支持的字符串组成任意格式 格式化支持:

  • y、m、d、h、i、s,是实际值
  • yy、mm、dd、hh、ii、ss,是补零后的值
  • z周几、xq星期几
format(new Date(), 'y-m-d h:i')
// 2019-7-4 9:4
format(new Date(), 'yy-mm-dd hh:ii:ss')
// 2019-07-04 09:04:08
format(new Date(), 'd日 hh:ii')
// 4日 09:04
format(new Date(), 'yymmdd z')
// 20190704 周四
format(new Date(), 'xq yy-mm-dd')
// 星期四 2019-07-04

countdownDate

距离date过去了多久,当大于天时,则仅计算天

let now = new Date()
let date1 = now.setSeconds(now.getSeconds() - 16)
countdownDate(date1)
// 16秒
let date2 = now.setMinutes(now.getMinutes() - 10)
countdownDate(date2)
// 10分钟
let date3 = now.setDate(now.getDate() - 1)
countdownDate(date3)
// 1天

计算

// 加法
console.log(2.2 + 2.1) // 4.300000000000001
addFn(2.2, 2.1) // 4.3
// 减法
console.log(1.4 - 1.1) // 0.2999999999999998
subFn(1.4, 1.1) // 0.3
// 乘法
console.log(2.2 * 2.2) // 4.840000000000001
multiFn(2.2, 2.2) // 4.84
// 除法
console.log(2.1 / 0.3) // 7.000000000000001
divideFn(2.1, 0.3) // 7