
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@ithinku/shared
Advanced tools
高性能、零依赖、类型安全的 TypeScript 通用工具函数库。
旨在提供日常开发中最常用的数组、对象、类型判断和时间处理函数,所有函数均支持 Tree-shaking。
sort)。npm install @ithinku/shared
# or
pnpm add @ithinku/shared
Type)提供比 typeof 更精准的类型判断。
import { isArray, isObject, isEmpty, isType } from '@ithinku/shared'
isArray([]) // true
isObject({}) // true
isObject(null) // false (注意:原生 typeof null === 'object')
// 智能判空 (支持 Array, Object, Map, Set, String)
isEmpty([]) // true
isEmpty({}) // true
isEmpty('') // true
isEmpty(0) // false (0 是有效值)
isEmpty(undefined) // true
// 获取真实类型字符串
isType(new Date()) // 'Date'
isType(/regex/) // 'RegExp'
Array)注意:所有修改操作均返回新数组,不影响原数组。
import { sort, unique, avg, max, min, mode, median } from '@ithinku/shared'
const arr = [3, 1, 2, 2]
// 排序 (返回新副本)
sort(arr) // [1, 2, 2, 3]
console.log(arr) // [3, 1, 2, 2] (原数组未变)
// 去重
unique(arr) // [3, 1, 2]
// 统计计算
avg([1, 2, 3]) // 2
max([1, 5, 2]) // 5 (空数组返回 undefined)
min([1, 5, 2]) // 1 (空数组返回 undefined)
// 众数
mode([1, 2, 2, 3]) // [2]
// 中位数
median([1, 3, 2]) // 2
Time)轻量级的日期格式化工具。
import { format } from '@ithinku/shared'
const date = new Date('2024-01-01 13:00:00')
// 默认格式: YYYY-MM-DD HH:mm:ss
format(date) // "2024-01-01 13:00:00"
// 自定义格式 (支持 YYYY, MM, DD, HH, mm, ss, SSS)
format(date, { format: 'YYYY/MM/DD' }) // "2024/01/01"
import { objToArr, arrToObj } from '@ithinku/shared'
const obj = { a: 1, b: 2 }
objToArr(obj) // [['a', 1], ['b', 2]]
const entries = [['a', 1], ['b', 2]]
arrToObj(entries) // { a: 1, b: 2 }
MIT
FAQs
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.