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

@totebox/util

v0.13.1

Published

Uncategorized utilities.

Downloads

12

Readme

@totebox/util

安装

npm i @totebox/util

使用

import { type } from '@totebox/util';

API

noop()

type(obj)

deepAssign(target, source[, ...sources])

random(a, b)

inRandomRate(value)

randomId(length[, { uniqueId, prefix }])

uniqueId

Default: true

delayTask(task[, delay = 600]) => clearTask()

mergeSort(array)

toTree(array[, options])

把树形关系的数组结构解析成树形结构

options

options.id (Default: "id")

数据项中的 id 字段名

options.parentId (Default: "parentId")

数据项中父节点的 id 字段名

options.rootParentId (Default: 0)

数据项中顶层父节点 id 字段的值

options.children (Default: "children")

解析后树节点下,子树的字段名

chunk(array, process, context[, callback, duration = 100])

batch(array, process, context[, callback, { runDuration = 25, chunkDuration = 50 }])

motion(start, end, duration[, { step, done }]) => clearMotion()

LazyTasks

const lazyTasks = new LazyTasks()

lazyTasks.add(id, { do, delay })

lazyTasks.run(id)

lazyTasks.start(id, { cb })

lazyTasks.stop(id, { cb, clear })

parseTime(time[, maxUnit = 'day'])

解析一个毫秒值为可读的时间对象:{ day, hour, minute, second },设置的 maxUnit 如果当最大单位的时间值没有取到,就用 0 来填补。

time

要解析的毫秒值

maxUnit (default: "day")

day|hour|minute|second

或简写:d|h|m|s

formatTime(duration) => "hh:mm:ss"

countdown(value[, { onStart, onProgress, onEnd }, context])

返回:

{ start(), stop(cb) }

value

表示未来的一个时间的毫秒值,或者 n 秒倒计时

isLeapYear(year)

parseDate(value, format)

value

一个表示时间的字符串

format

时间格式化字符串,需要和 value 的格式匹配

formatDate(date, format)

parseTextPlaceholder(text, data[, dataReplaceable = false])

// return 'Hello, Nicolas!'
parseTextPlaceholder('Hello, {name}!', { name: 'Nicolas' });

parseNumberPlaceholder(text, param[, ...params])

// 'Do you love me? Yes, I love You!'
format('Do {0} love {1}? Yes, {2} love {0}!', 'you', 'me', 'I')

formatSize(bytes)

trim(text)

entityify(text)

deentityify(text)

strip(text)

escape(text)

filter(text, maxlength)

License

MIT © nicolaszhao