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

usual-utils

v1.0.0

Published

some general function

Downloads

1

Readme

通用前端工具函数

记录开发中封装的公用方法,以后有用得着可以节省开发时间。

作者:陈星~

一、安装

npm i usual-utils -S

yarn add usual-utils

二、使用

import {
  isValidNumber,
  splitArray,
  realTimeRefresh,
  toValidNumber,
  scientificToNumber,
  firstUpperCase,
  arraySort,
  lazyLoadingList,
  isObjNoData,
  reverseObj,
} from 'usual-utils'

三、方法用途、参数注解及默认值

方法名: isValidNumber
用途及参数注解:
type IsValidNumberFnType = ( // 判断是否是有效数字
  val: any,                  // 传进来的值
) => boolean;                // 判断结果
默认值: 无

方法名: splitArray
用途及参数注解:
type SplitArrayFnType = ( // 把一维数组分割成二维数组
  val: any[],             // 原始数据
  interval: number,       // 分割间隔
) => any[];               // 结果数据
默认值: 无

方法名: realTimeRefresh
用途及参数注解:
type TimerNumerType = NodeJS.Timer | NodeJS.Timeout | undefined;
type RealTimeRefreshFnType = (  // 页面实时刷新/定时器
  fn: (() => void),             // 要执行的操作
  interval: number,             // 时间间隔(分)
  type: 'interval' | 'timeout', // 定时器类型
) => TimerNumerType;            // 定时器对象
默认值:
const realTimeRefresh = (
  fn,
  interval,
  type = 'interval',
) => {...}

方法名: toValidNumber
用途及参数注解:
type ToValidNumberFnType = ( // 将内容转换成有效的数字
  value: any,                // 传入的数据
) => string;                 // 转换后的字符串
默认值: 无

方法名: scientificToNumber
用途及参数注解:
type ScientificToNumberFnType = ( // 将科学计数法的数字转换成正常数字展示
  num: string,                    // 传入的数据
) => string;                      // 转换后的字符串
默认值: 无

方法名: firstUpperCase
用途及参数注解:
type FirstUpperCaseFnType = ( // 字符串转换为首字符大写
  str: string,                // 原字符串
  firstEndLowerCase: boolean, // 从第二个字符开始剩余的字符,是否转换为小写
  allTranslation: boolean,    // 是否全部单词转换
) => string;                  // 转换后的字符串
默认值:
const firstUpperCase = (
  str,
  firstEndLowerCase = false,
  allTranslation = true,
) => {...}

方法名: arraySort
用途及参数注解:
type ArraySortFnType = (                // 将数组按某个字段排序
  originalArr: any[],                   // 原数组
  pattern: 'string' | 'number',         // 字符串排序还是数字排序
  sortType: 'asc' | 'desc',             // 排序规则: 升序asc排序(或A-Z排序)/降序desc排序(或Z-A排序)
  key: string,                          // 遵循哪个字段排序
  suspenseSort: boolean,                // 两个都是无效数据时是否按其它字段排序(注:数字排序时,两个都为0时也准从这个备用排序)
  suspensePattern: 'string' | 'number', // 两个都是无效数据时的备用排序模式
  suspenseKey: string,                  // 两个都是无效数据时的备用排序字段
) => any[];                             // 排序后的数组
默认值:
const arraySort = (
  originalArr,
  pattern = 'number',
  sortType = 'asc',
  key = '',
  suspenseSort = false,
  suspensePattern = 'number',
  suspenseKey = '',
) => {...}

方法名: lazyLoadingList
用途及参数注解:
type LazyLoadingListFnType = ( // 懒加载添加数据
  totalList: any[],            // 总数据
  currentList: any[],          // 当前展示数据
  initLength: number,          // 初始加载多少条数据
  loadingType: 1 | 2,          // 去删除数据还是添加数据 1:添加,2:删除
  loadingCount: number,        // 每次添加多少条数据
) => any[];                    // 整理后的数组
默认值: 无

方法名: isObjNoData
用途及参数注解:
type IsObjNoDataFnType = (  // 判断一个对象是否无数据及所有字段无数据
  obj: object | (any & {}), // 要判断的对象
) => boolean;               // 判断结果
默认值: 无

方法名: reverseObj
用途及参数注解:
type ReverseObjFnType = (        // 将对象的键与值互换
  obj: {[keyName: string]: any}, // 传进来的对象
) => object;                     // 翻转后的对象
默认值: 无

四、更新日志

↪1.0.0

2023-07-22

☆ 第一次发布。