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

@thallo/front-end-utils

v1.4.0

Published

> yarn add @thallo/front-end-utils

Downloads

10

Readme

yarn add @thallo/front-end-utils

Usage

import BaseUtils from '@thallo/front-end-utils'
// 组织树结构
BaseUtils.getTree(data: TreeSourceData[]): TreeData[]
// 根据末尾节点UUID,获取所有父节点
BaseUtils.getTreeNodes(data: TreeSourceData[],tail: string): TreeSourceData[]
// 文本占位符转换
BaseUtils.getFormatString(str: string, values: Obj): string
// 英文句子第一个单词首字母大写,其余小写
BaseUtils.firstUpperCase(str: string): string
// 格式化pid,pid === "0"时转化为undefined
BaseUtils.formatPid(value: {pid: string;[prop: string]: any;}): Obj
// 删除空数据,如空字符、空数组、空对象、null、undefind
BaseUtils.delEmptyData(value: Obj): Obj
// 去除对象中字符串的空格,[isAll] 是否去除字符串所有空格
BaseUtils.removeSpaces(value: Obj, isAll?: boolean): Obj
// 对比两个对象的差异,返回差异值
BaseUtils.getDifference(oldData: Obj, newData: Obj): Obj
// 获取随机数/随机数数组
BaseUtils.getRandom(max: number, min: number, num?: number): number | number[]
// 文件名md5加密
BaseUtils.getFileNameMd5(value:{name: string;type: string;id: string;}): string
// 计算列表总数,最大页码为999
BaseUtils.getTotal(value: {size: number;total: number;}): number
// 将json配置转化为option数组,[optional]指定转化的key
BaseUtils.getOption(data: { [prop in number | string]: string },optional?: Array<number | string>): Array<{ value: number | string; label: string }>
// 根据对象key获取值
BaseUtils.getData(data: { [prop in number | string]: string }|undefined,value: number | string): number | string
// 指定位数,向前补0
BaseUtils.fillIn(num: string, length: number): string
// 解析路由参数
BaseUtils.getParams(url: string): Obj
// 解析路由参数
BaseUtils.matchValue<T>(values: T[], value: T, defaults: T): T
// 转换为数字
BaseUtils.toNumber(value: string | number | boolean): number
// 取整
BaseUtils.toParseInt(value: string): number
// 处理网关响应实体
BaseUtils.getResponse(error: AxiosResponse, isDebug?:boolean ): AxiosResponse
// 全局ajax响应错误处理
BaseUtils.requestError(error: AxiosError, isDebug?:boolean ): { error: GatewayResponse; type: errorType }

Types

interface TreeSourceData {
  id: string;
  pid?: string;
  order?: number;
  name: string;
  [propName: string]: any;
}
interface TreeData extends TreeSourceData {
  children?: TreeData[];
}
interface Obj {
  [key: string]: any;
}
export interface GatewayResponse {
  status?: number;
  headers?: {
    "x-ca-error-code"?: string;
  };
  data?: any;
  config?: AxiosRequestConfig;
}
type errorType = "401"  | "403"  | "500"  | "retry"  | "system"  | "timeout"  | "network"  | "other";

- "401" - JWT认证失败
- "403" - 访问权限/服务权限/操作权限被禁止
- "500" - 服务器/后端连接/后端解析错误
- "retry" - 请求头参数过期/限流/后端请求超时/网关请求超时
- "system" - 请求非法/请求头计算错误/订购过期/服务器配置错误
- "timeout" - 请求超时
- "network" - 网络连接错误
- "other" - 服务器响应的其他错误