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

yizhi-tsutil

v1.1.14

Published

此小工具包含了常用的数据操作和类型操作,具体包含: * 数组、对象、字符串的扩展操作 (导入一次即生效) * 时间操作(需要导入工具) * 数据处理(需要导入工具) * 类型定义(无需导入) * 常用文件系统操作(导入fs模块即可使用)

Downloads

54

Readme

Typescript小工具

此小工具包含了常用的数据操作和类型操作,具体包含:

  • 数组、对象、字符串的扩展操作 (导入一次即生效)
  • 时间操作(需要导入工具)
  • 数据处理(需要导入工具)
  • 类型定义(无需导入)
  • 常用文件系统操作(导入fs模块即可使用)

安装

npm install --save yizhi-tsutil

使用

//导入工具
import { util, log } from 'yizhi-tsutil'
//直接导入
import 'yizhi-tsutil'

数组操作

  • 检测是否包含:include
  • 删除元素:remove
  • 获取随机元素:getone
  • 检测当前数组中是否存在元素在另一个数组中:in
  • 获取除给定元素之外的其他元素:others
  • 删除重复元素
    • 根据数据的键进行删除(极力推荐): different(key)
    • 根据回调函数删除,没有回调函数则使用===判断(不推荐): different(callback)
    • 如果是字符串数组,请使用此方法: differentStrings

对象操作

  • 取所有键:keys
  • 取所有值:values
  • 值遍历:forEach
  • 值映射:map
  • 通过给定的键取子对象:getByKeys
  • 依据键删除元素:deleteKeys

字符串操作

  • 前填充:padStart
  • 尾填充:padEnd
  • 转换为证书:toInt
  • 转换为浮点数:toFloat
  • 转换成数组:toArray
  • 转换为时间:toTime

小工具

  • 时间操作:util.Time
  • 数据操作:util.data
  • 获取函数参数列表:util.getArguments
  • 清除控制台:util.clearTerm
  • 经常处理
    • 关闭进程 util.process.kill

日志打印

  • log.success 成功
  • log.error 错误
  • log.warn 警告
  • log.info 信息

例如:

import { log } from 'yizhi-tsutil'
log.success('server', 'server is listen on 3000')

文件系统扩充

为fs模块扩充了其他复杂的操作,具体使用参照typing/fs.d.ts

import fs from 'fs'
fs.rmdirDeepSync('dist')

深度删除目录

  • fs.rmdirDeep
  • fs.rmdirDeepSync

深度创建目录

  • fs.mkdirDeep
  • fs.mkdirDeepSync

复制文件夹

  • fs.copyDir
  • fs.copyDirSync

查找文件

  • fs.findFile
  • fs.findFileSync

配置读取器

提供一个简单的配置读取器,允许操作.ini.json配置文件,json可以使用注释。

使用方式:先调用xxx.set函数配置读取器,然后调用xxx.from加载配置文件,加载后调用对应函数进行读取。

import { config } from 'yizhi-tsutil'

//设置
config.ini.set({ configFolder: __dirname })
//读取server.bin为int类型
config.ini.form('server').int('server.bin')