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 🙏

© 2026 – Pkg Stats / Ryan Hefner

foreslash

v0.3.11

Published

Foreslash is a Javascript utilities lib which contains plenty of practical functions.

Downloads

603

Readme

Foreslash

为何选择 Foreslash

完整类型提示

Foreslash 自带完整的类型提示,无需安装 @types/XXX

低副作用

若无特殊说明,Foreslash 的任何方法都几乎没有副作用

  • Foreslash 的方法不会修改传入的原数据,返回值将是一个新的数据。
import { shuffle } from 'foreslash'

const arr = [1, 2, 3, 4, 5, 6, 7, 8]
const shuffled = shuffle(arr) // 返回新的数组 [3, 2, 6, 5, 8, 1, 7, 4] 同时 arr 并没有受到影响

函数式编程

Foreslash 提供了诸如 currypipe 等函数式编程的方法。

  • 出于性能优化的考量,若无特殊说明,此库的任何方法都不是柯里化的。
  • Foreslash 的柯里化方法 curry 和柯里化占位符 _ramda 兼容。
import { curry, _ } from 'foreslash'

// const regTest = (regex) => (str) => regex.test(str) // 传统方法,传入参数的顺序有强制规定不够灵活
const regTest = curry((str, regex) => regex.test(str)) // 这里柯里化了一个函数使其能更灵活地复用

const testString = regTest('123')
testString(/^\d+$/) // true
testString(/^[a-z]+$/) // false

const isDigits = regTest(_, /^\d+$/) // 使用占位符来跳过填充某些参数,传统方法做不到这点
isDigits('123') // true
isDigits('abc') // false

安装与使用

npm install foreslash # 使用 npm 安装
yarn add foreslash # 使用 yarn 安装
pnpm install foreslash # 使用 pnpm 安装

Foreslash 支持 ESM、CJS、UMD 三种引入方式,推荐使用 ESM。

更多 API 请参考文档

// curry & randomString
import { _, curry, randomString } from 'foreslash'

randomString(3) // 'bcD' 或 'T30' 或 '7c5' 或 ...

const curriedRanStr = curry(randomString)

const randomABCD = curriedRanStr(_, 'ABCD')
randomABCD(3) // 'BDC' 或 'ACD' 或 'DBB' 或 ...

const random1234 = curriedRanStr(_, '1234')
random1234(3) // '431' 或 '213' 或 '241' 或 ...

// fastClone
import { fastClone } from 'foreslash'

const obj = { a: { b: { c: {} } }, map: new Map() }
obj.a.b.c.d = obj // 常见的循环引用
obj.map.set(obj, 'val') // Map 键上的循环引用

const clone = fastClone(obj)
clone === obj // false
// 处理深层级对象
clone.a.b.c === obj.a.b.c // false
clone.a.b.c.d === clone // true
// 处理 Map
clone.map === obj.map // false
clone.map.get(clone) === 'val' // true

兼容性

Foreslash 兼容任何能正确运行 ES6 代码的 Javascript 环境,包括 Node.js 和浏览器。

  • 不支持 Internet Explorer,但是使用 core-js 处理并由 babel 转译为 ES5(ES2009) 后可以使用。

开源软件

Foreslash 的诞生离不开这些开源项目:

部分方法灵感源于以下开源项目: