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

aus-tools

v1.2.13

Published

一个JavaScript工具库,提供了许多常用的工具函数和类

Downloads

434

Readme

aus-tools

  • 一个JavaScript工具库。提供了许多常用的工具函数和类,以便开发人员可以更快速地完成任务

安装

pnpm install aus-tools

使用

import _ from 'aus-tools';
_.getFingerprint()

or

import { getFingerprint } from 'aus-tools';
getFingerprint()

功能列表

| 功能名称 | 调用方式 | 浏览器环境 | Node环境 | 备注 | |---------------|--------------------------------------------------------------------------|:-----:|:------:|----| | 获取浏览器指纹 | getFingerprint() | ✅ | ❌ | | | 在当前页面下载文件 | downloadUrlFile(url: string) | ✅ | ❌ | | | 下载blob格式文件 | downloadBlobFile(blob: Blob, fileName: string) | ✅ | ❌ | | | 打开新页面 | openNewPage(url: string) | ✅ | ❌ | | | 自动调整元素的屏幕适配比例 | autoScreenRatio({ dWidth: number; dHeight: number; elementId: string; }) | ✅ | ❌ | | | 复制文本 | copyText(text: string) | ✅ | ❌ | | | 睡眠函数 | sleep(ms: number) | ✅ | ✅ | | | 返回只执行一次的函数 | useOnce(callback: Function) | ✅ | ✅ | | | 获取随机生成的字符串 | getRandomValue(length: number, prefix?: string) | ✅ | ✅ | |


安全存储 webStorage二开 仅支持现代浏览器环境

根据浏览器指纹进行SM4加密 无法解密会自动删除键值 所以无法使用别的电脑加密的数据
import { safeLocalStorage, safeStorage } from 'aus-tools';
safeLocalStorage.getItem('key')

| 函数名称 | 调用方式 | 备注 | |--------|----------------------------------------------------|--------------------| | 获取存储内容 | getItem(key: string, def: any = null) | def为取值失败时的默认返回值 | | 设置存储内容 | setItem(key: string, value: any, expires?: number) | expires为过期时间戳,单位为秒 | | 删除存储内容 | remove(key: string) | | 清空存储内容 | clear() |


格式化相关

| 功能名称 | 调用方式 | 浏览器环境 | Node环境 | 备注 | |----------|-------------------------------------------------------------------------|:-----:|:------:|--------------------------------| | 格式化日期 | timeFormater(date?: Date | number | string, formater: string): string | ✅ | ✅ | 默认格式为:YYYY-MM-DD HH:mm:ss | | 格式化文件大小 | sizeFormat(size: number| string, unit: sizeUnit = 'B'): string | ✅ | ✅ | | | 获取url参数 | getUrlParams<T = Record<string, string>>(url?: string):T | ✅ | ✅❌ | node环境必须传入参数 可以通过泛型控制返回类型 | | | 解析Base64 | parseBase64(base64: string) | ✅ | ✅ | 提取其中的媒体类型(mime type)、扩展名和数据部分 | | 脱敏手机号 | desensitizePhone(str: string): string | ✅ | ✅ | 130**0000 | | 脱敏邮箱 | desensitizeEmail(str: string): string | ✅ | ✅ | [email protected] -> abc*@qq.com | | 脱敏字符串 | desensitizeStr(str: string): string | ✅ | ✅ | 保留第一位和最后一位 其余脱敏 |


Is相关

| 功能名称 | 调用方式 | 浏览器环境 | Node环境 | 备注 | |-----------------|-----------------------------------------------------|:-----:|:------:|-----------------------------------------------| | 是否是浏览器环境 | isInBrowser():boolean | ✅ | ✅ | | | 是否是Node环境 | isInNode():boolean | ✅ | ✅ | | | 是否是字符串 | isString(str: unknown):boolean | ✅ | ✅ | | | 是否是数字 | isNumber(num: unknown):boolean | ✅ | ✅ | | | 是否是布尔值 | isBoolean(bool: unknown):boolean | ✅ | ✅ | | | 是否是NaN | isNaN(val: unknown):boolean | ✅ | ✅ | | | 非null非undefined | isDefined(val: unknown):boolean | ✅ | ✅ | 用于判断值存在 允许为0或空串 | | 是否是数组 | isArray(val: unknown):boolean | ✅ | ✅ | | | 是否是空数组 | isEmptyArray(arr: T[]):boolean | ✅ | ✅ | | | 是否是对象 | isObject(fn: unknown) | ✅ | ✅ | | | 是否是空对象 | isEmptyObject(obj: Record<string, unknown>):boolean | ✅ | ✅ | | | 是否是邮箱 | isEmail(val: string):boolean | ✅ | ✅ | 判断正则:/^[\w+.-]+@[\dA-Za-z-]+.[\d.A-Za-z-]+$/ | | 是否是手机号 | isPhone(val: string):boolean | ✅ | ✅ | 判断正则:/^1(3[0-9] |4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/ | | 是否是URL | isUrl(val: string):boolean | ✅ | ✅ | | | 是否是Date | isDate(val: unknown):boolean | ✅ | ✅ | | | 返回值类型 | getType(value: unknown): Type | ✅ | ✅ | 无法判断返回“Object” |


优化相关

| 功能名称 | 调用方式 | 浏览器环境 | Node环境 | 备注 | |------|----------------------------------------------------------------------------------|:-----:|:------:|----| | 节流函数 | throttle(fn: Function, delay: number = 200, leading: boolean, trailing: boolean) | ✅ | ✅ | | | 防抖函数 | debounce(fn: Function, delay: number = 200, immediate: boolean) | ✅ | ✅ | |