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

handier-utils

v1.0.4

Published

帮助 javascript/typescript 开发的函数工具集

Downloads

6

Readme

handier-utils

函数工具集

安装

npm install --save handier-utils

chunk

拆分数组

参数类型

function chunk(array: any[], size: number): any[];

使用示例

import { chunk } from "handier-utils";
const originalArray = [1, 2, 3, 4, 5, 6, 7, 8];
const chunkedArray = chunk(originalArray, 3);
console.log(chunkedArray);
// 输出: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]

debounce

防抖函数

function debounce<T extends (...args: any[]) => void>(
  func: T,
  delay?: number
): (this: ThisParameterType<T>, ...args: Parameters<T>) => void;

throttle

节流函数

function throttle<T extends (...args: any[]) => void>(
  func: T,
  delay?: number
): (this: ThisParameterType<T>, ...args: Parameters<T>) => void;

cloneDeep

深拷贝

function cloneDeep<T>(source: T): T;

使用示例

import { cloneDeep } from "handier-utils";
const source = { a: 1, b: { c2 } };
const target = cloneDeep(source);
console.log(source.b === target.b);
// 输出: false

getRandomNumber

生成范围内[min, max]随机数

function getRandomNumber(min?: number, max?: number): number;

getRandomHexColor

生成随机十六进制颜色码

function getRandomHexColor(): string;

getRandomRgbColor

生成 rgb|rgba 类型随机颜色

function getRandomRgbColor(type?: "rgb" | "rgba"): string;

getRandomString

生成随机字符串

function getRandomString(len?: number): string;

formatNumberWithCommas

数字转换为带千字符的字符串

function formatNumberWithCommas(num: number): string;

firstLetterUpper

首字母大写

function firstLetterUpper(str: string): string;

isFullScreen

判断是否全屏中

function isFullScreen(): boolean;

requestFullscreen

传入一个 dom 元素, 使其全屏

function requestFullscreen(element: HTMLElement): void;

exitFullscreen

退出全屏

function exitFullscreen(): void;

fileToBase64

文件转 base64

function fileToBase64(file: File): Promise<string | null>;

base64toFile

base64 转 file

function base64toFile(base64String: string, fileName: string): File;

base64toBlob

base64 转 blob

function base64toBlob(base64String: string): Blob;

blobToFile

blob 转 file

function blobToFile(blob: Blob, fileName: string): File;

fileToBlob

file 转 blob

function downloadFile(file: Blob, fileName: string): void;

getImageSize

获取图片宽高

function getImageSize(imageSource: string | File): Promise<{
  width: number;
  height: number;
}>;

add

数字相加,解决精度丢失问题

function add(...numbers: number[]): number;

sub

数字相减,解决精度丢失问题

function sub(...numbers: number[]): number;

wait

等待指定时间

function wait(ms: number): Promise<void>;

copyTextToClipboard

复制文本到剪贴板

function copyTextToClipboard(text: string): void;