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

@sagacious/utils

v0.0.13

Published

常用工具类

Downloads

3

Readme

常用工具类

相关信息

更新日志

  • 2019-09-29 ObjectUtils类 - removeEmpty API 新增处理后值配置项,优化MathUtils类
  • 2019-09-27 新增MathUtils类
  • 2019-09-25 新增OrderQuene类
  • 2019-09-26 OrderQuene类新增stop,clear方法
  • more...

API

ObjectUtils

操作对象工具类

1. init (target: Object): ObjectUtils 初始化工具类

2. val (): ObjectTarget 获取处理后的值

3. removeEmpty (): ObjectUtils 去除对象中的非零不规范数据

type ObjectUtilsRemoveOptions = {
  /**
   * 处理后的值
   */
  targetVal?: any;
  /**
   * 元素为数组的key
   */
  arrayKeys?: string[];
  /**
   * 数组处理后的值
   */
  arrayVal?: any[];
  /**
   * 对象为数组时是否处理,默认为true
   */
  operateArray?: boolean;
};

4. static removeEmpty(target) 静态方法 去除对象中的非零不规范数据

MathUtils

数学工具类

1. init (target: number): MathUtils 初始化工具类

2. val (): number 获取处理后的值

3. evaluate (formula: string): MathUtils 执行数学公式

OrderQuene

顺序队列

1. init (quene: OrderQueneElement[], options: OrderQueneOptions): OrderQuene 初始化order quene,返回值:元素队列

2. push (...quene: OrderQueneElement[]): this 往队列里添加元素

3. start (data: any): void 开始执行队列

4. stop (): void 停止执行队列,在元素stop回调执行完毕后停止

4. clear (): OrderQueneElement[] 清空执行队列,在元素stop回调执行完毕后停止,返回值:未执行元素队列

规则

延时顺序执行(delay),最后一个元素延时更久执行(endDelay),未执行end回调时有元素推入,1). time < delay,到达delay执行. 2). delay < time < endDelay, 立即执行

数据类型

/**
 * 队列元素
 */
type OrderQueneElement = {
  /**
   * 开始执行回调
   */
  start?: (...args: any[]) => Promise<any>
  /**
   * 结束执行回调
   */
  end?: (...args: any[]) => Promise<any>
  /**
   * 延迟时间
   */
  delay?: number
  /**
   * 最后一个元素延迟时间
   */
  endDelay?: number
}
/**
 * 公共配置
 */
type OrderQueneOptions = {
  /**
   * 延迟时间
   */
  delay?: number
  /**
   * 最后一个元素延迟时间
   */
  endDelay?: number
}
/**
 * 默认配置
*/
private options: OrderQueneOptions = {
  delay: 1000 * 2,
  endDelay: 1000 * 5,
}

案例

// 初始化队列
let x = OrderQuene.init([
  {
    start () {
      console.log('start1')
    },
    end () {
      console.log('end1')
    },
  },
  {
    start () {
      console.log('start2')
    },
    end () {
      console.log('end2')
    },
  },
  {
    start () {
      console.log('start3')
    },
    end () {
      console.log('end3')
    },
  },
])

// 开始执行
x.start()

// 模拟中间插入,等待执行
setTimeout(() => {
  x.push({
    start () {
      console.log('start4')
    },
    end () {
      console.log('end4')
    },
  })
}, 7000)

// 模拟中间插入,立即执行
setTimeout(() => {
  x.push({
    start () {
      console.log('start4')
    },
    end () {
      console.log('end4')
    },
  })
}, 9000)