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 🙏

© 2024 – Pkg Stats / Ryan Hefner

work-utils

v1.1.7

Published

工作中常见的组件的组件实现,方便以后自己调用,避免重复工作

Downloads

6

Readme

Work utils

工作中常见的组件的组件实现,方便以后自己调用,避免重复工作

Useragent 相关

// UA里面展示了常见的useragent
import { UA } from 'work-utils'

UA.isDebug          // 是否处于debug模式,url中参数__debug为真
UA.isWeiXinDebug    // 是否是微信JSSDK的debug模式,url中参数__wxDebug为真
UA.isIos            // 是否是IOS系统
UA.isAndroid        // 是否是安卓系统
UA.isXmly           // 是否是喜马拉雅APP
UA.isWeiXin         // 是否在微信的webview内
UA.isMobile         // 是否是手机浏览器
UA.isSafari         // 是否是safari

URL 相关

import { getQuery, createUrlParam } from 'work-utils'

/**
 * @name getQuery
 * @description 从url参数中获取具体参数值
 * @param key, 字符串
 * @return key对应的参数值
 */

let query = getQuery('name')
console.log(query)  // null | 'Rick'

/**
 * @name createUrlParam
 * @description 从简单对象中创建url参数
 * @param obj, 简单对象
 * @param url?, 可选参数:url
 * @return url参数字符串
 */

let param = createUrlParam({ a: 1, b: 2 })
console.log(param)      // a=1&b=2

let param2 = createUrlParam({ a: 1, b: 2 }, 'http://www.ok.com')
console.log(param2)     // http://www.ok.com?a=1&b=2

Share

import { ShareSDK } from 'work-utils'

ShareSDK.WxShare
// 在使用微信分享之前,你想要先使用ShareSDK.initWxFetch注册请求微信签名相关的数据
// 具体使用步骤如下

ShareSDK.initWxFetch({
  type?: 'GET',
  url: '/get/wx/config',
  data?: { url: encodeURIComponent(window.location.href) }
  headers?: {}
  dataStruct: 'data.data' 
  // dataStruct 接口返回的数据结构
  // 如 { code: 200, res: { 签名信息所在数据结构 }, msg: 'ok' } 此时dataStruct为 'data.res'
  // 如直接返回包含数据的对象,如 { 签名信息所在数据结构 } 配置dataStruct为 'data'
  dataKeys?: {
    appId: string
    timestamp: string
    nonceStr: string
    signature: string
  }
  // dataKeys 接口返回的微信签名信息key值 默认与微信配置的config保持一致
  // 如接口返回: { id: 'id', time: 'time', non: 'nonceStr', signature: 'signature' }
  // 其中 id的值对应config中的appId,time对应timestamp,non对应nonceStr,signature对应signature
  // 此时dataKeys配置为:{ appId: 'id', timestamp: 'time', nonceStr: 'non', signature: 'signature' }
})

// 上述微信分享的接口配置完毕,现在可以直接调用ShareSDK.WxShare
ShareSDK.WxShare({
  shareTitle: '微信分享标题',
  shareUrl: '微信分享链接',
  shareImage: '微信分享图片',
  shareDesc: '微信分享描述',
})

// 最佳实践(具名引用)
export const WxShare = ShareSDK.WxShare

import { WxShare } from 'xxx'

WxShare({
  shareTitle: '微信分享标题',
  shareUrl: '微信分享链接',
  shareImage: '微信分享图片',
  shareDesc: '微信分享描述',
})