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

nemoni-js-utils

v2.1.2

Published

common utils for js

Downloads

345

Readme

目录

JS Utils 工具函数库

基础工具函数 (base.js)

getTypeOf(params)

获取数据类型

  • 参数: 任意类型的值
  • 返回: 返回数据类型字符串,如 'String','Number'等
  • 示例: getTypeOf([1,2,3]) // 'Array'

unique(params)

数组或字符串去重

  • 参数: Array或String
  • 返回: 去重后的数组或字符串
  • 示例: unique([1,1,2,3]) // [1,2,3]

deepCopy(obj)

深拷贝对象或数组

  • 参数: 需要深拷贝的对象或数组
  • 返回: 深拷贝后的新对象或数组
  • 示例: deepCopy({a:1, b:{c:2}}) // 返回全新对象

getWHForVideoOrImg(file)

获取图片或视频的宽高

  • 参数: 单个文件对象(图片或视频)
  • 返回: Promise对象,resolve时返回包含width和height的对象
  • 示例: await getWHForVideoOrImg(file) // {width: 1920, height: 1080}

getUserNameByteLength(str, nameStrLimit, maxByteLength, returnByteLength)

计算字符串字节长度,可选择截断

  • 参数:
    • str: 目标字符串
    • nameStrLimit: 字符长度限制(默认7)
    • maxByteLength: 字节长度限制(默认21)
    • returnByteLength: 是否返回字节长度(默认false)
  • 返回: 截断后的字符串或字节长度
  • 示例: getUserNameByteLength("你好世界", 3) // "你好世..."

guid(short)

生成唯一标识符

  • 参数: short - 是否生成短格式(默认false)
  • 返回: 唯一标识字符串
  • 示例: guid() // "a1b2c3d4-e5f6-g7h8-i9j0"

executeFunctions(call, token, tokenName)

执行函数或函数数组,支持token验证和延迟执行

  • 参数:
    • call: 需要执行的函数或函数数组
    • token: 可选的token参数
    • tokenName: token的名称(默认'sso')
  • 示例: executeFunctions(() => console.log('执行'), 'token123')

launchMiniProgram(options)

拉起微信小程序

  • 参数: 配置对象
  • 返回: boolean
  • 示例: launchMiniProgram({userName: 'wx1234567890'}) // true

getOpenId(code)

获取微信openID

  • 参数: 微信授权后的code码
  • 返回: Promise对象,resolve时返回openid
  • 示例: await getOpenId('code1234567890') // 'openid1234567890'

环境检测工具 (charge.js)

isweixin

检测是否在微信环境中

  • 返回: Boolean

isuc

检测是否在UC浏览器中

  • 返回: Boolean

isandroid

检测是否在Android系统中

  • 返回: Boolean

isios

检测是否在iOS系统中

  • 返回: Boolean

getType(obj)

判断传入对象的数据类型

  • 参数: 需要判断类型的对象
  • 返回: 数据类型字符串
  • 示例: getType([]) // 'Array'

getMarketUrl(appId, defaultUrl)

根据手机品牌返回对应的应用市场链接

  • 参数:
    • appId: 应用包名(默认'com.youdao.hlyd')
    • defaultUrl: 默认下载链接
  • 返回: 对应品牌手机应用市场链接或默认下载链接
  • 支持品牌: 华为、荣耀、vivo、小米、OPPO、联想、魅族等

数据验证工具 (validate.js)

validateUsername(username)

验证用户名

  • 参数: 用户名
  • 返回: 包含valid和message的对象
  • 示例: validateUsername('user123') // {valid: false, message: '用户名必须包含字母、数字和下划线'}

validatePassword(password)

验证密码

  • 参数: 密码
  • 返回: 包含valid、strength和message的对象
  • 示例: validatePassword('Test123!@#') // {valid: true, strength: 7, message: '密码强度: 强'}

validateEmail(email)

验证邮箱

  • 参数: 邮箱
  • 返回: 包含valid和message的对象
  • 示例: validateEmail('[email protected]') // {valid: true, message: ''}

mobileCheck(mobile)

验证手机号

  • 参数: 手机号
  • 返回: boolean
  • 示例: mobileCheck('13912345678') // true

idCardCheck(idCard)

验证身份证号码

  • 参数: 身份证号码
  • 返回: boolean
  • 示例: idCardCheck('110101199003077758') // true

validateIdCard(idCard)

校验身份证号码并返回详细验证结果

  • 参数: 身份证号码
  • 返回: 包含valid和message的对象
  • 示例: validateIdCard('110101199003077758') // {valid: true, message: ''}

微信工具函数 (wechat.js)

getOpenId(code)

获取微信openID

  • 参数: 微信授权后的code码
  • 返回: Promise对象,resolve时返回openid
  • 示例: await getOpenId('code1234567890') // 'openid1234567890'

navigateTo(url, options)

微信内跳转页面

  • 参数:
    • url: 需要跳转的URL地址
    • options: 配置选项
  • 返回: void
  • 示例: navigateTo('https://example.com') // 无返回

跨页面通信 (websocket.js)