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

easy-fmt

v1.0.1

Published

一个简单常用的格式化小工具

Downloads

7

Readme

Easy Format

简易常见的格式化小工具

安装

 npm i -S easy-fmt
 or
 yarn add easy-fmt

使用

import fmt from "easy-fmt";

let io = fmt.IntersectionObserver(document.getElementById("box", true));

io.then((entries, observe) => {
  if (entries[0].intersectionRatio <= 0) return;
  // 元素在可视区的处理逻辑
  observe.disconnect();
});

fmt.currency(12000); // 12,000.00

fmt.time(new Date(2020, 10, 22, 10, 15, 2), "YYYY-MM-DD hh:mm:ss"); // 2020-11-22 10:15:02

fmt.param({
  orderId: 15,
  orderNo: "Order20201022",
}); // ?orderId=15&orderNo=Order20201022

fmt.prefixZero(12, 5); // 00012
fmt.prefixZero(12, 1); // 12
fmt.prefixZero(-12, 3); // -012

fmt.round(12.456, 2); // 12.46

fmt.mask("15211112222", 12, 4); // 15211112222
fmt.mask("15211112222", 3, 4); // 152****2222

fmt.trim(" 152  111 222 ", "all"); // 152111222

fmt.phone("15211112222"); // 152-1111-2222
fmt.phone("15211112222", "/"); // 152/1111/2222
fmt.phone("15211112222", "-", "1/1/1"); // 1-5-2-11112222

API

| 方法 | 实例 | 备注 | | ---------------------- | ----------------------------------------------------------------------------- | -------------------------- | | IntersectionObserver | fmt.IntersectionObserver(el:Element, showOnce: Boolean) | 监听指定元素是否在可视区域 | | currency | fmt.currency(num: Number,placeholder: Boolean) | 格式化货币 | | time | fmt.time(value: Number | Date | String, format: String) | 格式化时间 | | param | fmt.param(obj: Object) | 将对象转换成 query | | unparam | fmt.unparam(val: String) | 将 query 转换成对象 | | prefixZero | fmt.prefixZero(num: Number, length: Number) | 补零 | | round | fmt.round(num: Number, decimals: Number) | 四舍五入 | | randomNum | fmt.randomNum(min: Number, max?: Number) | 指定范围内的随机数 | | mask | fmt.mask(str: String, start: Number, maskLen: Number, _placeholder: String) | 字符串遮挡 | | maskLeft | fmt.maskLeft(str: String, maskLen: Number, _placeholder: String) | 从左侧开始遮挡 | | maskRight | fmt.maskRight(str: String, maskLen: Number, _placeholder: String) | 从右侧开始遮挡 | | trim | fmt.trim(str: String, type: String['all', 'lr', 'left', 'right']) | 清空字符串空格 | | guid | fmt.guid() | 生成随机码 | | phone | fmt.phone(PhoneNumber: String, split: String, distribute: String) | 格式化手机号码 |