@freearhey/search-js

中文文档
0.3.0发布于 2026/04/29MITESM + CJS零依赖近 30 天下载 2.8万

A tool for searching elements in JavaScript arrays.

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Testing
  4. Linting
  5. Contribution
  6. License

search-js

A tool for searching elements in JavaScript arrays.

Installation

npm install @freearhey/search-js

Usage

import sj from '@freearhey/search-js'

const data = [
  { name: 'Nikita', age: 24 },
  { name: 'Jeremy', age: 13 },
  { name: 'Jerry', age: 18 },
  { name: 'Gwendolyn', age: 43 }
]

const index = sj.createIndex(data)

const results = index.search('Jer')

console.log(results)

Output:

[
  { name: 'Jeremy', age: 13 },
  { name: 'Jerry', age: 18 },
]

Search syntax:

ExampleDescription
catFinds items that have "cat" in their descriptions
cat dogFinds items that have "cat" AND "dog" in their descriptions
cat,dogFinds items that have "cat" OR "dog" in their descriptions
bio:"electric tape"Finds items that have "electric tape" in the bio
email:/./Finds items that have an email
stars:>4Finds items with more than 5 stars
stars:<2Finds items with less than 2 stars

Options:

NameTypeDescription
searchableArrayList of searchable attributes. By default, all attributes will be searched.

Example:

index.search('t', { searchable: ['lastName'] })

Testing

npm test

Linting

npm run lint

Contribution

If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.

License

MIT

版本与发布记录

@freearhey/search-js 共发布 6 个版本,首次发布于 2023/02/28;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.3.0latest2026/04/296 个月前
0.2.12026/03/138 个月前
0.2.02025/08/311.2 年前
0.1.22025/03/091.7 年前
0.1.12023/02/283 年前
0.1.02023/02/283 年前

关于 @freearhey/search-js 的常见问题

@freearhey/search-js 是什么?

A tool for searching elements in JavaScript arrays.

如何安装 @freearhey/search-js?

在项目目录运行 npm install @freearhey/search-js,或使用 pnpm add / yarn add / bun add。

@freearhey/search-js 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/freearhey__search-js 是否存在。

@freearhey/search-js 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@freearhey/search-js 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.6.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@freearhey/search-js 可以商用吗?

@freearhey/search-js 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@freearhey/search-js 的下载量有多少?

根据 npm 官方下载统计,@freearhey/search-js 在 2026/10/16 – 2026/11/14 这 30 天内被下载 27,674 次,日均约 922 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@freearhey/search-js 还在维护吗?

最新版本 0.3.0 发布于 2026/04/29(6 个月前);至今共发布 6 个版本,其中过去 12 个月发布了 2 个;首次发布于 2023/02/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。