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

tmaito-utils

v0.5.2

Published

utils 工具包

Downloads

186

Readme

tmaito-utils NPM version NPM Downloads

Fast, generic JavaScript/node.js utility functions.

Install

npm i tmaito-utils
// or
yarn add tmaito-utils

Usage

import * as Utils from 'tmaito-utils'

// or

import { formatTime, ...} from 'tmaito-utils'

Api 文档

formatTime(timestamp, format) 时间格式化
  • timestamp 时间戳或者年月日拼接字符串(🌰20200220200218)
  • format 自定义转化格式,默认 YYYY-MM-DD ,例如:'YYYY-MM-DD'、'YYYY/MM/DD'、'YYYYMMDD'、'YYYY-MM-DD hh:mm:ss'等

若传入非日期格式,则直接返回该值, 若传入错误的日期格式,则返回 YYYY-MM-DD hh:mm:ss 格式

randomNum(min, max) 两个数间的随机数
  • min 最小值
  • max 最大值
smalltoBig(value) 价格小写转大写
toPercent(value, isTransfer, fixed) 数字转化百分比
  • value
  • isTransfer 是否需要转化,默认为 true,例如 0.13 => 13%
  • fixed 小数点位数,默认为 0,例如 1.2%
toThousands(value, fixed, isFilling) 金额 千分位转换
  • value 金额
  • fixed 保留 fixed 位小数,若不足,则以0填充,若超出,则四舍五入后的期望位数
  • isFilling 小数位不足时是否填充,默认true 填充 。
sum(arr, key, defaultValue) 一维数组计算之和
  • arr 一维数组
  • key 需要统计的字段和
  • defaultValue 默认值,可选值

注意## 若 arr 为纯数字数组,则key 置空即可

getParams(search, key) 返回 URL 的参数
  • search: 通过 location.search 获取的参数字符串
  • key: 可选值,具体的参数

🌰:

const search = '?name=test&age=31';
getParams(search);
// {
//  name: 'test,
//  age: '21
// }

getParams(search, name);
// test

// or
const { name, age } = getParams(search);
// name = 'test';
// age = '21';
resetProtocal(url, protocal) 重置协议头
  • url: url l链接
  • protocal: 通过 location.protocal 获取当前域名的协议头

🌰:

const search = '?name=test&age=31';
resetProtocal('https://xxx.com', 'http:')
// http://xxx.com

resetProtocal('http://xxx.com', 'https:')
// https://xxx.com
queryParams2String(queryParams) 查询参数转成字符串
  • queryParams: queryParams 查询参数

🌰:

const search = '?name=test&age=31';
queryParams2String({
	name: 'test',
	age: '31'
})
// name=test&age=31

calculator 系列精度计算

calculator.strip(num, precision) 截取想要的位数

calculator.digitLength(num) 返回小数点长度

calculator.float2Fixed(num) 把小数转成整数,支持科学计数法。如果是小数则放大成整数

calculator.plus(num, ...) 精确加法

calculator.minus(num, ...) 精确减法

calculator.times(num, ...) 精确乘法

calculator.divide(num, ...) 精确除法

`calculator.round(num, ratio) 四舍五入

download(url) 下载文件

  • url: 下载文件路径

🌰:

download('xxx.xlsx')

downloadBlob( fileName, content) 文档流方式下载文件

  • fileName: 文件名
  • content: 文档流