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

trumangao-utils

v2.3.0

Published

A series of commonly used JavaScript utility functions.

Downloads

81

Readme

trumangao-utils

常用JavaScript工具函数

A series of commonly used JavaScript utility functions. Here for the API.

Install

npm install trumangao-utils

Usage

import { url2obj } from "trumangao-utils";

const url =
  "https://www.npmjs.com/package/trumangao-utils?name=trumangao-utils&ltypescript=true";
const obj = url2obj(url);

console.log(obj); // { name: "trumangao-utils", typescript: "true" }

API

CryptoManager

管理字符的加密/解密,基于 crypto-js

Manage the encryption/decryption of characters, based on crypto-js.

// encryption
import { CryptoManager } from "trumangao-utils";

const cryptoManager = new CryptoManager({
  key: "test_key",
  iv: "test_iv",
  suffix: "test_suffix", // optional
});

const encrypted = cryptoManager.encryptAes("this is a test string");
// decryption
import { CryptoManager } from "trumangao-utils";

const cryptoManager = new CryptoManager({
  key: "test_key",
  iv: "test_iv",
  suffix: "test_suffix", // optional
});

const decrypted = cryptoManager.decryptAes(encrypted);

console.log(decrypted); // "this is a test string"

getStorage

根据键名读取本地存储

Read local storage based on the key.

function getStorage<K extends string>(
  storageType: "sessionStorage" | "localStorage",
  storageKey: K,
): any;

setStorage

根据键名写入本地存储

Write local storage based on the key.

function setStorage<K extends string>(
  storageType: "sessionStorage" | "localStorage",
  storageKey: K,
  storageData: any,
): void;

validateValue

常见数据格式校验

Common data format validation for phone, email, and numEnCn (numbers and Chinese characters).

function validateValue(option: {
  type: "phone" | "email" | "numEnCn";
  value: any;
  required?: boolean;
}): boolean;

checkDataType

精准判断数据类型,返回类型字符串

Precisely determine the data type and return the type string.

function checkDataType(
  data: unknown,
):
  | "String"
  | "Number"
  | "Boolean"
  | "Undefined"
  | "Null"
  | "Symbol"
  | "Function"
  | "Array"
  | "Object"
  | "Date"
  | "RegExp"
  | "Error"
  | "Map"
  | "Set";

downloadBlob

下载blob

Download a blob.

function downloadBlob(blob: Blob, fileName?: string): void;

prefetchAssets

资源预加载

Resource preloading.

function prefetchAssets(assets: { src: string; type: "img" | "audio" }[]): void;

getCharLength

计算字符串长度

Calculate the length of a string.

function getCharLength(str: string): number;

url2obj

获取URL的参数

Convert a URL to an object with query parameters.

function url2obj(url?: string): { [key: string]: string };

filterEmptyValue

过滤对象中的空值,包括空字符串、null、undefined

Filter out empty values in an object, including empty strings, null, and undefined.

function filterEmptyValue<T extends { [key: string]: any }>(obj: T): Partial<T>;

date2string

Date类型数据 转 时间标准格式字符串

Convert a Date object to a standard format string.

function date2string(option?: {
  date?: Date;
  hasTime?: boolean;
  dateSeparator?: string;
  timeSeparator?: string;
}): string;

caniuse_webp

检测 webp 支持性,惰性函数

Detect webp support, lazy function

function caniuse_webp(): boolean;