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

wdg-utils

v1.1.1

Published

Common tool functions for the front-end

Downloads

1

Readme

前端项目开发中,会经常使用一些工具函数,随着项目数量的增多、工具函数的增多,在每个项目里面都维护一个 util.js 会带来不少的麻烦,所以还是维护一个工具函数包!

安装使用

1. 安装包使用方式

安装

# npm
npm install wdg-utils -S

# yarn
yarn add wdg-utils -S

ESM 导入使用

import { random } from 'wdg-utils';
console.log(random(1, 10));

RequireJS 导入使用

const { random } = require('wdg-utils');
console.log(random(1, 10));

2. 网页 script 直接引入使用方式

直接拷贝 dist 下的 wdg-utils.umd.js 到项目里面,可直接引用

<!DOCTYPE html>
<html lang="en">
  <body>
    <script src="/dist/wdg-utils.umd.js"></script>
    <script>
      console.log(wdg-utils.random(1, 10))
    </script>
  </body>
</html>

函数概览

  /**
   * 生成数字范围内的随机数
   * @param min 最小数字
   * @param max 最大数字
   * @returns number类型
   */
  export function random(min, max)
  /**
   * 时间字符串转换为时间戳
   * @param dateStr 字符串格式为 2017-02-10 18:20:30
   * 注意:此处月、日、时分秒、必须为2位数字,否则报错
   * @returns 时间戳
   */
  export function format(date, fmt)
  /**
   * 转换时间字符串为大致时间描述
   * @param date 日期:2022-03-29 09:08:11
   * @returns 时间字符串:1个月前
   */
  export function makeChTime(date)
  /**
   * 判断是否为数组
   * @param input 最小数字
   * @returns boolean
   */
  export function isArray(input)
  /**
   * 判断是否为空
   * @param input 任意值对象
   * @returns boolean
   */
  export function isEmpty(input)
  /**
   * 判断是否为数字
   * @param input 任意值对象
   * @returns boolean
   */
  export function isNumber(input)
  /**
   * 存储localStorage
   * @param name key值
   * @param content value值
   */
  export function setLocal(name, content)
  /**
   * 获取存储localStorage
   * @param name key值
   * @return string
   */
  export function getLocal(name)
  /**
   * 删除localStorage
   * @param name key值
   */
  export function removeLocal(name)