🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@stll/fuzzy-search

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stll/fuzzy-search - npm Package Compare versions

Comparing version
0.1.2
to
1.0.0-rc.1
+581
index.cjs
// prettier-ignore
/* eslint-disable */
// @ts-nocheck
/* auto-generated by NAPI-RS */
const { readFileSync } = require('node:fs')
let nativeBinding = null
const loadErrors = []
const isMusl = () => {
let musl = false
if (process.platform === 'linux') {
musl = isMuslFromFilesystem()
if (musl === null) {
musl = isMuslFromReport()
}
if (musl === null) {
musl = isMuslFromChildProcess()
}
}
return musl
}
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
const isMuslFromFilesystem = () => {
try {
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
} catch {
return null
}
}
const isMuslFromReport = () => {
let report = null
if (typeof process.report?.getReport === 'function') {
process.report.excludeNetwork = true
report = process.report.getReport()
}
if (!report) {
return null
}
if (report.header && report.header.glibcVersionRuntime) {
return false
}
if (Array.isArray(report.sharedObjects)) {
if (report.sharedObjects.some(isFileMusl)) {
return true
}
}
return false
}
const isMuslFromChildProcess = () => {
try {
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
} catch (e) {
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
return false
}
}
function requireNative() {
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
try {
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
} catch (err) {
loadErrors.push(err)
}
} else if (process.platform === 'android') {
if (process.arch === 'arm64') {
try {
return require('./fuzzy-search.android-arm64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-android-arm64')
const bindingPackageVersion = require('@stll/fuzzy-search-android-arm64/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm') {
try {
return require('./fuzzy-search.android-arm-eabi.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-android-arm-eabi')
const bindingPackageVersion = require('@stll/fuzzy-search-android-arm-eabi/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
}
} else if (process.platform === 'win32') {
if (process.arch === 'x64') {
if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
try {
return require('./fuzzy-search.win32-x64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-win32-x64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-win32-x64-gnu/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.win32-x64-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-win32-x64-msvc')
const bindingPackageVersion = require('@stll/fuzzy-search-win32-x64-msvc/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'ia32') {
try {
return require('./fuzzy-search.win32-ia32-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-win32-ia32-msvc')
const bindingPackageVersion = require('@stll/fuzzy-search-win32-ia32-msvc/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./fuzzy-search.win32-arm64-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-win32-arm64-msvc')
const bindingPackageVersion = require('@stll/fuzzy-search-win32-arm64-msvc/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
}
} else if (process.platform === 'darwin') {
try {
return require('./fuzzy-search.darwin-universal.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-darwin-universal')
const bindingPackageVersion = require('@stll/fuzzy-search-darwin-universal/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
if (process.arch === 'x64') {
try {
return require('./fuzzy-search.darwin-x64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-darwin-x64')
const bindingPackageVersion = require('@stll/fuzzy-search-darwin-x64/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./fuzzy-search.darwin-arm64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-darwin-arm64')
const bindingPackageVersion = require('@stll/fuzzy-search-darwin-arm64/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
}
} else if (process.platform === 'freebsd') {
if (process.arch === 'x64') {
try {
return require('./fuzzy-search.freebsd-x64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-freebsd-x64')
const bindingPackageVersion = require('@stll/fuzzy-search-freebsd-x64/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./fuzzy-search.freebsd-arm64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-freebsd-arm64')
const bindingPackageVersion = require('@stll/fuzzy-search-freebsd-arm64/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
}
} else if (process.platform === 'linux') {
if (process.arch === 'x64') {
if (isMusl()) {
try {
return require('./fuzzy-search.linux-x64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-x64-musl')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-x64-musl/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.linux-x64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-x64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-x64-gnu/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'arm64') {
if (isMusl()) {
try {
return require('./fuzzy-search.linux-arm64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-arm64-musl')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-arm64-musl/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.linux-arm64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-arm64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-arm64-gnu/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'arm') {
if (isMusl()) {
try {
return require('./fuzzy-search.linux-arm-musleabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-arm-musleabihf')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-arm-musleabihf/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.linux-arm-gnueabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-arm-gnueabihf')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-arm-gnueabihf/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'loong64') {
if (isMusl()) {
try {
return require('./fuzzy-search.linux-loong64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-loong64-musl')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-loong64-musl/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.linux-loong64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-loong64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-loong64-gnu/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'riscv64') {
if (isMusl()) {
try {
return require('./fuzzy-search.linux-riscv64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-riscv64-musl')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-riscv64-musl/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.linux-riscv64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-riscv64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-riscv64-gnu/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'ppc64') {
try {
return require('./fuzzy-search.linux-ppc64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-ppc64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-ppc64-gnu/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 's390x') {
try {
return require('./fuzzy-search.linux-s390x-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-s390x-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-s390x-gnu/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
}
} else if (process.platform === 'openharmony') {
if (process.arch === 'arm64') {
try {
return require('./fuzzy-search.openharmony-arm64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-openharmony-arm64')
const bindingPackageVersion = require('@stll/fuzzy-search-openharmony-arm64/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'x64') {
try {
return require('./fuzzy-search.openharmony-x64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-openharmony-x64')
const bindingPackageVersion = require('@stll/fuzzy-search-openharmony-x64/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm') {
try {
return require('./fuzzy-search.openharmony-arm.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-openharmony-arm')
const bindingPackageVersion = require('@stll/fuzzy-search-openharmony-arm/package.json').version
if (bindingPackageVersion !== '1.0.0-rc.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0-rc.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
}
} else {
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
}
}
nativeBinding = requireNative()
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
let wasiBinding = null
let wasiBindingError = null
try {
wasiBinding = require('./fuzzy-search.wasi.cjs')
nativeBinding = wasiBinding
} catch (err) {
if (process.env.NAPI_RS_FORCE_WASI) {
wasiBindingError = err
}
}
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
try {
wasiBinding = require('@stll/fuzzy-search-wasm32-wasi')
nativeBinding = wasiBinding
} catch (err) {
if (process.env.NAPI_RS_FORCE_WASI) {
if (!wasiBindingError) {
wasiBindingError = err
} else {
wasiBindingError.cause = err
}
loadErrors.push(err)
}
}
}
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
error.cause = wasiBindingError
throw error
}
}
if (!nativeBinding) {
if (loadErrors.length > 0) {
throw new Error(
`Cannot find native binding. ` +
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
{
cause: loadErrors.reduce((err, cur) => {
cur.cause = err
return cur
}),
},
)
}
throw new Error(`Failed to load native binding`)
}
module.exports = nativeBinding
module.exports.FuzzySearch = nativeBinding.FuzzySearch
module.exports.distance = nativeBinding.distance
module.exports.Metric = nativeBinding.Metric
+1
-1

@@ -129,3 +129,3 @@ import { createRequire } from "node:module";

//#region src/index.ts
initBinding(createRequire(import.meta.url)("../index.js"));
initBinding(createRequire(import.meta.url)("../index.cjs"));
//#endregion

@@ -132,0 +132,0 @@ export { FuzzySearch, distance };

@@ -1,1 +0,1 @@

{"version":3,"file":"index.mjs","names":[],"sources":["../src/core.ts","../src/index.ts"],"sourcesContent":["/* Shared core: types, helpers, and classes that\n * use a late-bound native backend (NAPI-RS or WASM).\n * Call initBinding() before constructing classes. */\n\n// -- Native binding types ----------------------------\n\nexport type NativeBinding = {\n FuzzySearch: new (\n entries: NormalizedEntry[],\n options?: Options,\n ) => NativeFuzzySearch;\n distance: (\n a: string,\n b: string,\n metric: Metric | null,\n ) => number;\n};\n\ntype NativeFuzzySearch = {\n patternCount: number;\n isMatch(haystack: string): boolean;\n _findIterPacked(haystack: string): Uint32Array;\n replaceAll(\n haystack: string,\n replacements: string[],\n ): string;\n};\n\ntype NormalizedEntry = {\n pattern: string;\n distance?: number;\n name?: string;\n};\n\n// -- Late-bound native binding -----------------------\n\nlet binding: NativeBinding;\n\n/** Set the native backend. Must be called once\n * before any class constructor. */\nexport const initBinding = (b: NativeBinding) => {\n binding = b;\n};\n\n// -- Public types ------------------------------------\n\n/** Distance metric for fuzzy matching. */\nexport type Metric = \"levenshtein\" | \"damerau-levenshtein\";\n\n/** Options for constructing a `FuzzySearch`. */\nexport type Options = {\n /**\n * Distance metric.\n * - `\"levenshtein\"`: insertions, deletions,\n * substitutions (default).\n * - `\"damerau-levenshtein\"`: + transpositions\n * of adjacent characters (ab -> ba = 1 edit).\n * @default \"levenshtein\"\n */\n metric?: Metric;\n /**\n * Strip diacritics before matching (NFD\n * decompose + remove combining marks).\n * \"Pribram\" matches \"Pribram\" at distance 0.\n * @default false\n */\n normalizeDiacritics?: boolean;\n /**\n * Use Unicode word boundaries (covers all\n * scripts). CJK characters are treated as\n * standalone words.\n * @default true\n */\n unicodeBoundaries?: boolean;\n /**\n * Only match whole words. Fuzzy matches on\n * substrings are usually noise; require word\n * boundaries unless opted out.\n * @default true\n */\n wholeWords?: boolean;\n /**\n * Case-insensitive matching (Unicode-aware).\n * @default false\n */\n caseInsensitive?: boolean;\n};\n\n/** A pattern entry with its edit distance. */\nexport type PatternEntry =\n | string\n | {\n pattern: string;\n /** Max edit distance. Must be less than\n * pattern length. `\"auto\"` uses the\n * Elasticsearch convention: 1-2 chars -> 0,\n * 3-5 chars -> 1, 6+ chars -> 2.\n * @default 1 */\n distance?: number | \"auto\";\n /** Optional name for the pattern. */\n name?: string;\n };\n\n/** A single fuzzy match result. */\nexport type FuzzyMatch = {\n /** Index into the patterns array. */\n pattern: number;\n /** Start UTF-16 code unit offset (compatible\n * with `String.prototype.slice()`). */\n start: number;\n /** End offset (exclusive). */\n end: number;\n /** The matched text\n * (`haystack.slice(start, end)`). */\n text: string;\n /** Actual Levenshtein edit distance. */\n distance: number;\n /** Pattern name (if provided). */\n name?: string;\n};\n\n// -- Internal helpers --------------------------------\n\nconst resolveDistance = (\n dist: number | \"auto\",\n patternLength: number,\n): number => {\n if (dist !== \"auto\") return dist;\n if (patternLength <= 2) return 0;\n if (patternLength <= 5) return 1;\n return 2;\n};\n\nconst normalizeEntry = (\n p: PatternEntry,\n i: number,\n): NormalizedEntry => {\n if (typeof p === \"string\") {\n return { pattern: p };\n }\n if (\n typeof p === \"object\" &&\n p !== null &&\n typeof p.pattern === \"string\"\n ) {\n if (p.distance === \"auto\") {\n return {\n ...p,\n distance: resolveDistance(\"auto\", p.pattern.length),\n };\n }\n // SAFETY: The \"auto\" case was already handled above,\n // so p.distance is number | undefined — matching\n // NormalizedEntry.\n return p as NormalizedEntry;\n }\n throw new TypeError(\n `Pattern at index ${i} must be a string ` +\n `or { pattern, distance?, name? }`,\n );\n};\n\nconst unpack = (\n packed: Uint32Array,\n haystack: string,\n names: (string | undefined)[],\n): FuzzyMatch[] => {\n const len = packed.length;\n const matches: FuzzyMatch[] = [];\n for (let i = 0; i < len; i += 4) {\n const idx = packed[i];\n const start = packed[i + 1];\n const end = packed[i + 2];\n const distance = packed[i + 3];\n if (\n idx === undefined ||\n start === undefined ||\n end === undefined ||\n distance === undefined\n ) {\n throw new Error(\n `Malformed packed array at offset ${String(i)}`,\n );\n }\n const m: FuzzyMatch = {\n pattern: idx,\n start,\n end,\n text: haystack.slice(start, end),\n distance,\n };\n if (names[idx] !== undefined) {\n m.name = names[idx];\n }\n matches.push(m);\n }\n return matches;\n};\n\n// -- Classes -----------------------------------------\n\n/**\n * Fuzzy string matcher. Finds approximate\n * matches within edit distance k, immune to\n * typos, OCR errors, and diacritics variants.\n *\n * Uses Myers' bit-parallel algorithm for O(n)\n * scanning per pattern (patterns up to 64 chars).\n *\n * @throws {Error} If a pattern is empty, too\n * long (> 64 chars), or distance > 3.\n *\n * @example\n * ```ts\n * const fs = new FuzzySearch([\n * { pattern: \"Gaislerova\", distance: 1 },\n * { pattern: \"Novak\", distance: 1 },\n * ], {\n * normalizeDiacritics: true,\n * wholeWords: true,\n * });\n *\n * fs.findIter(\"Gais1erova a Nowak\");\n * // [\n * // { pattern: 0, start: 0, end: 10,\n * // text: \"Gais1erova\", distance: 1 },\n * // { pattern: 1, start: 13, end: 18,\n * // text: \"Nowak\", distance: 1 },\n * // ]\n * ```\n */\nexport class FuzzySearch {\n private _names: (string | undefined)[];\n private _inner: NativeFuzzySearch;\n\n constructor(patterns: PatternEntry[], options?: Options) {\n const entries = patterns.map(normalizeEntry);\n this._names = entries.map((e) => e.name);\n this._inner = new binding.FuzzySearch(entries, options);\n }\n\n /** Number of patterns in the matcher. */\n get patternCount(): number {\n return this._inner.patternCount;\n }\n\n /**\n * Returns `true` if any pattern matches\n * within its edit distance.\n */\n isMatch(haystack: string): boolean {\n return this._inner.isMatch(haystack);\n }\n\n /** Find all non-overlapping fuzzy matches. */\n findIter(haystack: string): FuzzyMatch[] {\n return unpack(\n this._inner._findIterPacked(haystack),\n haystack,\n this._names,\n );\n }\n\n /**\n * Replace all fuzzy matches.\n * `replacements[i]` replaces pattern `i`.\n *\n * @throws {Error} If `replacements.length`\n * does not equal `patternCount`.\n */\n replaceAll(\n haystack: string,\n replacements: string[],\n ): string {\n return this._inner.replaceAll(haystack, replacements);\n }\n}\n\n/**\n * Compute edit distance between two strings.\n *\n * Uses Unicode characters (not UTF-16 code units),\n * so emoji and supplementary plane characters are\n * handled correctly.\n *\n * @example\n * ```ts\n * distance(\"Novak\", \"Nowak\"); // 1\n * distance(\"abcd\", \"abdc\"); // 2\n * distance(\"abcd\", \"abdc\",\n * \"damerau-levenshtein\"); // 1\n * ```\n */\nexport const distance = (\n a: string,\n b: string,\n metric?: Metric,\n): number => binding.distance(a, b, metric ?? null);\n","/* Main entry point — loads the native NAPI-RS\n * binding and re-exports the public API. */\n\nimport { createRequire } from \"node:module\";\n\nimport { initBinding, type NativeBinding } from \"./core\";\n\nconst require = createRequire(import.meta.url);\n// SAFETY: NAPI-RS auto-generated loader returns the\n// native binding object; its shape is validated by\n// usage in the core classes.\nconst native = require(\"../index.js\") as NativeBinding;\n\ninitBinding(native);\n\nexport { FuzzySearch, distance } from \"./core\";\n\nexport type {\n FuzzyMatch,\n Metric,\n NativeBinding,\n Options,\n PatternEntry,\n} from \"./core\";\n"],"mappings":";;AAoCA,IAAI;;;AAIJ,MAAa,eAAe,MAAqB;AAC/C,WAAU;;AAkFZ,MAAM,mBACJ,MACA,kBACW;AACX,KAAI,SAAS,OAAQ,QAAO;AAC5B,KAAI,iBAAiB,EAAG,QAAO;AAC/B,KAAI,iBAAiB,EAAG,QAAO;AAC/B,QAAO;;AAGT,MAAM,kBACJ,GACA,MACoB;AACpB,KAAI,OAAO,MAAM,SACf,QAAO,EAAE,SAAS,GAAG;AAEvB,KACE,OAAO,MAAM,YACb,MAAM,QACN,OAAO,EAAE,YAAY,UACrB;AACA,MAAI,EAAE,aAAa,OACjB,QAAO;GACL,GAAG;GACH,UAAU,gBAAgB,QAAQ,EAAE,QAAQ,OAAO;GACpD;AAKH,SAAO;;AAET,OAAM,IAAI,UACR,oBAAoB,EAAE,oDAEvB;;AAGH,MAAM,UACJ,QACA,UACA,UACiB;CACjB,MAAM,MAAM,OAAO;CACnB,MAAM,UAAwB,EAAE;AAChC,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,KAAK,GAAG;EAC/B,MAAM,MAAM,OAAO;EACnB,MAAM,QAAQ,OAAO,IAAI;EACzB,MAAM,MAAM,OAAO,IAAI;EACvB,MAAM,WAAW,OAAO,IAAI;AAC5B,MACE,QAAQ,KAAA,KACR,UAAU,KAAA,KACV,QAAQ,KAAA,KACR,aAAa,KAAA,EAEb,OAAM,IAAI,MACR,oCAAoC,OAAO,EAAE,GAC9C;EAEH,MAAM,IAAgB;GACpB,SAAS;GACT;GACA;GACA,MAAM,SAAS,MAAM,OAAO,IAAI;GAChC;GACD;AACD,MAAI,MAAM,SAAS,KAAA,EACjB,GAAE,OAAO,MAAM;AAEjB,UAAQ,KAAK,EAAE;;AAEjB,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCT,IAAa,cAAb,MAAyB;CACvB;CACA;CAEA,YAAY,UAA0B,SAAmB;EACvD,MAAM,UAAU,SAAS,IAAI,eAAe;AAC5C,OAAK,SAAS,QAAQ,KAAK,MAAM,EAAE,KAAK;AACxC,OAAK,SAAS,IAAI,QAAQ,YAAY,SAAS,QAAQ;;;CAIzD,IAAI,eAAuB;AACzB,SAAO,KAAK,OAAO;;;;;;CAOrB,QAAQ,UAA2B;AACjC,SAAO,KAAK,OAAO,QAAQ,SAAS;;;CAItC,SAAS,UAAgC;AACvC,SAAO,OACL,KAAK,OAAO,gBAAgB,SAAS,EACrC,UACA,KAAK,OACN;;;;;;;;;CAUH,WACE,UACA,cACQ;AACR,SAAO,KAAK,OAAO,WAAW,UAAU,aAAa;;;;;;;;;;;;;;;;;;AAmBzD,MAAa,YACX,GACA,GACA,WACW,QAAQ,SAAS,GAAG,GAAG,UAAU,KAAK;;;AC5RnD,YANgB,cAAc,OAAO,KAAK,IAAI,CAIvB,cAAc,CAElB"}
{"version":3,"file":"index.mjs","names":[],"sources":["../src/core.ts","../src/index.ts"],"sourcesContent":["/* Shared core: types, helpers, and classes that\n * use a late-bound native backend (NAPI-RS or WASM).\n * Call initBinding() before constructing classes. */\n\n// -- Native binding types ----------------------------\n\nexport type NativeBinding = {\n FuzzySearch: new (\n entries: NormalizedEntry[],\n options?: Options,\n ) => NativeFuzzySearch;\n distance: (\n a: string,\n b: string,\n metric: Metric | null,\n ) => number;\n};\n\ntype NativeFuzzySearch = {\n patternCount: number;\n isMatch(haystack: string): boolean;\n _findIterPacked(haystack: string): Uint32Array;\n replaceAll(\n haystack: string,\n replacements: string[],\n ): string;\n};\n\ntype NormalizedEntry = {\n pattern: string;\n distance?: number;\n name?: string;\n};\n\n// -- Late-bound native binding -----------------------\n\nlet binding: NativeBinding;\n\n/** Set the native backend. Must be called once\n * before any class constructor. */\nexport const initBinding = (b: NativeBinding) => {\n binding = b;\n};\n\n// -- Public types ------------------------------------\n\n/** Distance metric for fuzzy matching. */\nexport type Metric = \"levenshtein\" | \"damerau-levenshtein\";\n\n/** Options for constructing a `FuzzySearch`. */\nexport type Options = {\n /**\n * Distance metric.\n * - `\"levenshtein\"`: insertions, deletions,\n * substitutions (default).\n * - `\"damerau-levenshtein\"`: + transpositions\n * of adjacent characters (ab -> ba = 1 edit).\n * @default \"levenshtein\"\n */\n metric?: Metric;\n /**\n * Strip diacritics before matching (NFD\n * decompose + remove combining marks).\n * \"Pribram\" matches \"Pribram\" at distance 0.\n * @default false\n */\n normalizeDiacritics?: boolean;\n /**\n * Use Unicode word boundaries (covers all\n * scripts). CJK characters are treated as\n * standalone words.\n * @default true\n */\n unicodeBoundaries?: boolean;\n /**\n * Only match whole words. Fuzzy matches on\n * substrings are usually noise; require word\n * boundaries unless opted out.\n * @default true\n */\n wholeWords?: boolean;\n /**\n * Case-insensitive matching (Unicode-aware).\n * @default false\n */\n caseInsensitive?: boolean;\n};\n\n/** A pattern entry with its edit distance. */\nexport type PatternEntry =\n | string\n | {\n pattern: string;\n /** Max edit distance. Must be less than\n * pattern length. `\"auto\"` uses the\n * Elasticsearch convention: 1-2 chars -> 0,\n * 3-5 chars -> 1, 6+ chars -> 2.\n * @default 1 */\n distance?: number | \"auto\";\n /** Optional name for the pattern. */\n name?: string;\n };\n\n/** A single fuzzy match result. */\nexport type FuzzyMatch = {\n /** Index into the patterns array. */\n pattern: number;\n /** Start UTF-16 code unit offset (compatible\n * with `String.prototype.slice()`). */\n start: number;\n /** End offset (exclusive). */\n end: number;\n /** The matched text\n * (`haystack.slice(start, end)`). */\n text: string;\n /** Actual Levenshtein edit distance. */\n distance: number;\n /** Pattern name (if provided). */\n name?: string;\n};\n\n// -- Internal helpers --------------------------------\n\nconst resolveDistance = (\n dist: number | \"auto\",\n patternLength: number,\n): number => {\n if (dist !== \"auto\") return dist;\n if (patternLength <= 2) return 0;\n if (patternLength <= 5) return 1;\n return 2;\n};\n\nconst normalizeEntry = (\n p: PatternEntry,\n i: number,\n): NormalizedEntry => {\n if (typeof p === \"string\") {\n return { pattern: p };\n }\n if (\n typeof p === \"object\" &&\n p !== null &&\n typeof p.pattern === \"string\"\n ) {\n if (p.distance === \"auto\") {\n return {\n ...p,\n distance: resolveDistance(\"auto\", p.pattern.length),\n };\n }\n // SAFETY: The \"auto\" case was already handled above,\n // so p.distance is number | undefined — matching\n // NormalizedEntry.\n return p as NormalizedEntry;\n }\n throw new TypeError(\n `Pattern at index ${i} must be a string ` +\n `or { pattern, distance?, name? }`,\n );\n};\n\nconst unpack = (\n packed: Uint32Array,\n haystack: string,\n names: (string | undefined)[],\n): FuzzyMatch[] => {\n const len = packed.length;\n const matches: FuzzyMatch[] = [];\n for (let i = 0; i < len; i += 4) {\n const idx = packed[i];\n const start = packed[i + 1];\n const end = packed[i + 2];\n const distance = packed[i + 3];\n if (\n idx === undefined ||\n start === undefined ||\n end === undefined ||\n distance === undefined\n ) {\n throw new Error(\n `Malformed packed array at offset ${String(i)}`,\n );\n }\n const m: FuzzyMatch = {\n pattern: idx,\n start,\n end,\n text: haystack.slice(start, end),\n distance,\n };\n if (names[idx] !== undefined) {\n m.name = names[idx];\n }\n matches.push(m);\n }\n return matches;\n};\n\n// -- Classes -----------------------------------------\n\n/**\n * Fuzzy string matcher. Finds approximate\n * matches within edit distance k, immune to\n * typos, OCR errors, and diacritics variants.\n *\n * Uses Myers' bit-parallel algorithm for O(n)\n * scanning per pattern (patterns up to 64 chars).\n *\n * @throws {Error} If a pattern is empty, too\n * long (> 64 chars), or distance > 3.\n *\n * @example\n * ```ts\n * const fs = new FuzzySearch([\n * { pattern: \"Gaislerova\", distance: 1 },\n * { pattern: \"Novak\", distance: 1 },\n * ], {\n * normalizeDiacritics: true,\n * wholeWords: true,\n * });\n *\n * fs.findIter(\"Gais1erova a Nowak\");\n * // [\n * // { pattern: 0, start: 0, end: 10,\n * // text: \"Gais1erova\", distance: 1 },\n * // { pattern: 1, start: 13, end: 18,\n * // text: \"Nowak\", distance: 1 },\n * // ]\n * ```\n */\nexport class FuzzySearch {\n private _names: (string | undefined)[];\n private _inner: NativeFuzzySearch;\n\n constructor(patterns: PatternEntry[], options?: Options) {\n const entries = patterns.map(normalizeEntry);\n this._names = entries.map((e) => e.name);\n this._inner = new binding.FuzzySearch(entries, options);\n }\n\n /** Number of patterns in the matcher. */\n get patternCount(): number {\n return this._inner.patternCount;\n }\n\n /**\n * Returns `true` if any pattern matches\n * within its edit distance.\n */\n isMatch(haystack: string): boolean {\n return this._inner.isMatch(haystack);\n }\n\n /** Find all non-overlapping fuzzy matches. */\n findIter(haystack: string): FuzzyMatch[] {\n return unpack(\n this._inner._findIterPacked(haystack),\n haystack,\n this._names,\n );\n }\n\n /**\n * Replace all fuzzy matches.\n * `replacements[i]` replaces pattern `i`.\n *\n * @throws {Error} If `replacements.length`\n * does not equal `patternCount`.\n */\n replaceAll(\n haystack: string,\n replacements: string[],\n ): string {\n return this._inner.replaceAll(haystack, replacements);\n }\n}\n\n/**\n * Compute edit distance between two strings.\n *\n * Uses Unicode characters (not UTF-16 code units),\n * so emoji and supplementary plane characters are\n * handled correctly.\n *\n * @example\n * ```ts\n * distance(\"Novak\", \"Nowak\"); // 1\n * distance(\"abcd\", \"abdc\"); // 2\n * distance(\"abcd\", \"abdc\",\n * \"damerau-levenshtein\"); // 1\n * ```\n */\nexport const distance = (\n a: string,\n b: string,\n metric?: Metric,\n): number => binding.distance(a, b, metric ?? null);\n","/* Main entry point — loads the native NAPI-RS\n * binding and re-exports the public API. */\n\nimport { createRequire } from \"node:module\";\n\nimport { initBinding, type NativeBinding } from \"./core\";\n\nconst require = createRequire(import.meta.url);\n// SAFETY: NAPI-RS auto-generated loader returns the\n// native binding object; its shape is validated by\n// usage in the core classes.\nconst native = require(\"../index.cjs\") as NativeBinding;\n\ninitBinding(native);\n\nexport { FuzzySearch, distance } from \"./core\";\n\nexport type {\n FuzzyMatch,\n Metric,\n NativeBinding,\n Options,\n PatternEntry,\n} from \"./core\";\n"],"mappings":";;AAoCA,IAAI;;;AAIJ,MAAa,eAAe,MAAqB;AAC/C,WAAU;;AAkFZ,MAAM,mBACJ,MACA,kBACW;AACX,KAAI,SAAS,OAAQ,QAAO;AAC5B,KAAI,iBAAiB,EAAG,QAAO;AAC/B,KAAI,iBAAiB,EAAG,QAAO;AAC/B,QAAO;;AAGT,MAAM,kBACJ,GACA,MACoB;AACpB,KAAI,OAAO,MAAM,SACf,QAAO,EAAE,SAAS,GAAG;AAEvB,KACE,OAAO,MAAM,YACb,MAAM,QACN,OAAO,EAAE,YAAY,UACrB;AACA,MAAI,EAAE,aAAa,OACjB,QAAO;GACL,GAAG;GACH,UAAU,gBAAgB,QAAQ,EAAE,QAAQ,OAAO;GACpD;AAKH,SAAO;;AAET,OAAM,IAAI,UACR,oBAAoB,EAAE,oDAEvB;;AAGH,MAAM,UACJ,QACA,UACA,UACiB;CACjB,MAAM,MAAM,OAAO;CACnB,MAAM,UAAwB,EAAE;AAChC,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,KAAK,GAAG;EAC/B,MAAM,MAAM,OAAO;EACnB,MAAM,QAAQ,OAAO,IAAI;EACzB,MAAM,MAAM,OAAO,IAAI;EACvB,MAAM,WAAW,OAAO,IAAI;AAC5B,MACE,QAAQ,KAAA,KACR,UAAU,KAAA,KACV,QAAQ,KAAA,KACR,aAAa,KAAA,EAEb,OAAM,IAAI,MACR,oCAAoC,OAAO,EAAE,GAC9C;EAEH,MAAM,IAAgB;GACpB,SAAS;GACT;GACA;GACA,MAAM,SAAS,MAAM,OAAO,IAAI;GAChC;GACD;AACD,MAAI,MAAM,SAAS,KAAA,EACjB,GAAE,OAAO,MAAM;AAEjB,UAAQ,KAAK,EAAE;;AAEjB,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCT,IAAa,cAAb,MAAyB;CACvB;CACA;CAEA,YAAY,UAA0B,SAAmB;EACvD,MAAM,UAAU,SAAS,IAAI,eAAe;AAC5C,OAAK,SAAS,QAAQ,KAAK,MAAM,EAAE,KAAK;AACxC,OAAK,SAAS,IAAI,QAAQ,YAAY,SAAS,QAAQ;;;CAIzD,IAAI,eAAuB;AACzB,SAAO,KAAK,OAAO;;;;;;CAOrB,QAAQ,UAA2B;AACjC,SAAO,KAAK,OAAO,QAAQ,SAAS;;;CAItC,SAAS,UAAgC;AACvC,SAAO,OACL,KAAK,OAAO,gBAAgB,SAAS,EACrC,UACA,KAAK,OACN;;;;;;;;;CAUH,WACE,UACA,cACQ;AACR,SAAO,KAAK,OAAO,WAAW,UAAU,aAAa;;;;;;;;;;;;;;;;;;AAmBzD,MAAa,YACX,GACA,GACA,WACW,QAAQ,SAAS,GAAG,GAAG,UAAU,KAAK;;;AC5RnD,YANgB,cAAc,OAAO,KAAK,IAAI,CAIvB,eAAe,CAEnB"}
{
"name": "@stll/fuzzy-search",
"version": "0.1.2",
"description": "NAPI-RS bindings for fuzzy string matching via Myers' bit-parallel algorithm for Node.js/Bun",
"version": "1.0.0-rc.1",
"description": "Approximate substring matching for Node.js and Bun via a Rust Myers engine exposed through NAPI-RS.",
"keywords": [

@@ -21,7 +21,7 @@ "approximate-matching",

"type": "git",
"url": "https://github.com/stella/fuzzy-search"
"url": "git+https://github.com/stella/fuzzy-search.git"
},
"files": [
"dist",
"index.js"
"index.cjs"
],

@@ -38,14 +38,19 @@ "type": "module",

"publishConfig": {
"access": "restricted"
"access": "public"
},
"scripts": {
"build": "napi build --platform --release",
"build:debug": "napi build --platform",
"build:wasm": "napi build --platform --target wasm32-wasip1-threads --release",
"fix:loader": "node scripts/fix-napi-loader.mjs",
"build": "node scripts/build-native.mjs --platform --release",
"build:debug": "node scripts/build-native.mjs --platform",
"build:wasm": "node scripts/build-native.mjs --platform --target wasm32-wasip1-threads --release",
"artifacts": "napi artifacts",
"universal": "napi universal",
"build:js": "tsdown",
"prepublishOnly": "napi prepublish -t npm && tsdown",
"build:js": "node scripts/ensure-wasm-artifact.mjs && tsdown && node scripts/fix-napi-loader.mjs",
"prepublishOnly": "napi prepublish -t npm && tsdown && node scripts/fix-napi-loader.mjs",
"test": "bun test __test__/index.spec.ts",
"test:props": "bun test __test__/properties.spec.ts",
"test:runtime:bun": "bun scripts/runtime-smoke.mjs",
"test:runtime:node": "node scripts/runtime-smoke.mjs",
"version:sync": "node scripts/version-sync.mjs sync",
"version:check": "node scripts/version-sync.mjs check",
"format": "oxfmt . && rustfmt src/lib.rs",

@@ -61,20 +66,22 @@ "lint": "oxlint .",

"devDependencies": {
"@emnapi/core": "^1.9.1",
"@emnapi/runtime": "^1.9.1",
"@napi-rs/cli": "^3.5.1",
"@emnapi/core": "^1.9.2",
"@emnapi/runtime": "^1.9.2",
"@napi-rs/cli": "^3.6.1",
"@tybys/wasm-util": "^0.10.1",
"@types/node": "^25.5.0",
"@types/node": "^25.5.2",
"bun-types": "^1.3.11",
"emnapi": "^1.9.1",
"emnapi": "^1.9.2",
"fast-check": "^4.6.0",
"oxfmt": "^0.42.0",
"oxlint": "^1.57.0",
"tsdown": "^0.21.6"
"oxfmt": "^0.44.0",
"oxlint": "^1.59.0",
"tsdown": "^0.21.7",
"typescript": "^5.9.3",
"vite": "^8.0.8"
},
"optionalDependencies": {
"@stll/fuzzy-search-darwin-x64": "0.1.2",
"@stll/fuzzy-search-darwin-arm64": "0.1.2",
"@stll/fuzzy-search-linux-x64-gnu": "0.1.2",
"@stll/fuzzy-search-linux-arm64-gnu": "0.1.2",
"@stll/fuzzy-search-wasm32-wasi": "0.1.2"
"@stll/fuzzy-search-darwin-arm64": "1.0.0-rc.1",
"@stll/fuzzy-search-darwin-x64": "1.0.0-rc.1",
"@stll/fuzzy-search-linux-arm64-gnu": "1.0.0-rc.1",
"@stll/fuzzy-search-linux-x64-gnu": "1.0.0-rc.1",
"@stll/fuzzy-search-wasm32-wasi": "1.0.0-rc.1"
},

@@ -94,2 +101,2 @@ "napi": {

}
}
}
+78
-47

@@ -0,7 +1,12 @@

<p align="center">
<img src=".github/assets/banner.png" alt="Stella" width="100%" />
</p>
# @stll/fuzzy-search
[NAPI-RS](https://napi.rs/) fuzzy string matching
for Node.js and Bun. Finds approximate occurrences
of patterns within edit distance k, immune to typos,
OCR errors, and diacritics variants.
[NAPI-RS](https://napi.rs/) approximate substring
matching for Node.js and Bun. Finds near-matches
within edit distance k with stable UTF-16 offsets,
replace-safe match ranges, and optional diacritics
normalization.

@@ -20,4 +25,23 @@ Built on [Myers' bit-parallel algorithm](https://doi.org/10.1145/316542.316550)

Prebuilt binaries are available for:
The companion `@stll/fuzzy-search-wasm` package is
available for browser builds.
If you use the browser package with Vite, import the
bundled plugin so the generated WASM loader is not
pre-bundled into broken asset URLs:
```typescript
import { defineConfig } from "vite";
import stllFuzzySearchWasm from "@stll/fuzzy-search-wasm/vite";
export default defineConfig({
plugins: [stllFuzzySearchWasm()],
});
```
GitHub releases include npm tarballs, an SBOM, and
third-party notices.
Prebuilts are available for:
| Platform | Architecture |

@@ -27,4 +51,3 @@ | ------------- | ------------ |

| Linux (glibc) | x64, arm64 |
| Linux (musl) | x64 |
| Windows | x64 |
| WASM | browser |

@@ -109,34 +132,53 @@ ## Usage

### Distance helper
```typescript
import { distance } from "@stll/fuzzy-search";
distance("kitten", "sitting"); // 3
distance("abcd", "abdc", "damerau-levenshtein"); // 1
```
## Benchmarks
Measured on Apple M3, 24 GB RAM, macOS 25.3.0,
Bun 1.3.10. Search-only times, automaton pre-built.
The repository includes a checked-in benchmark harness
for synthetic and corpus-based searches. The inputs
are public and the scripts are reproducible from the
repo. Run them locally:
### Synthetic legal text (64KB, 5 patterns, dist 1-2)
```bash
bun run bench:install
bun run bench:download
bun run bench:speed
bun run bench:correctness
```
| Library | Time | Speedup |
| ---------------------------- | ---------- | ------- |
| **@stll/fuzzy-search** | **2.3 ms** | — |
| fuzzball.extract | 9.2 ms | 3.9x |
| fuse.js (word-split) | 57 ms | 25x |
| fastest-levenshtein + window | 82 ms | 35x |
| naive JS (sliding window) | 511 ms | 219x |
The speed harness compares practical JS ecosystem
alternatives, but not every comparator implements the
same exact semantics. `@stll/fuzzy-search` is solving
approximate substring search with offsets and
replacement-friendly match ranges; tools like
`fuse.js` and `fuzzball` are included as reference
points, not as exact drop-in equivalents. The
headline comparisons in this repo are the
substring-mode rows against sliding-window
Levenshtein baselines.
### Real corpus (Canterbury bible.txt, 4.0 MB)
Representative baseline from the checked-in public
harness on this machine:
| Library | Time | Speedup |
| ---------------------------- | ---------- | ------- |
| **@stll/fuzzy-search** | **258 ms** | — |
| fastest-levenshtein + window | 4,249 ms | 16.5x |
- runtime: Bun `1.3.12`
- platform: macOS `26.4.1` (`Darwin arm64`)
### Real corpus (Leipzig Czech news, 4.8 MB)
| Scenario | `@stll/fuzzy-search` | Sliding-window JS baseline | Relative |
| -------------------------------- | -------------------- | -------------------------- | -------- |
| Czech legal, `64 KB`, `5` names | `2.41 ms` | `80.78 ms` | `33.5x` |
| Bible, `4.0 MB`, `5` names | `239.91 ms` | `3903.26 ms` | `16.3x` |
| Czech news, `4.8 MB`, `5` names | `262.39 ms` | `4350.52 ms` | `16.6x` |
| German news, `5.5 MB`, `5` names | `405.72 ms` | `6816.03 ms` | `16.8x` |
| Library | Time | Speedup |
| ---------------------------- | ---------- | ------- |
| **@stll/fuzzy-search** | **249 ms** | — |
| fastest-levenshtein + window | 4,147 ms | 16.6x |
These rows are substring mode (`wholeWords: false`)
with edit distance `1-2`, which is the core workload
this package is designed for.
Run locally:
`bun run bench:install && bun run bench:download && bun run bench:speed`
<details>

@@ -154,19 +196,8 @@ <summary>Alternatives tested</summary>

Every match is verified against a naive Levenshtein
oracle:
Correctness is covered by example-based tests and
property tests. The property suite verifies distance
bounds, oracle agreement, whole-word boundaries,
UTF-16 offset stability, normalization behavior, and
mixed option combinations over randomized inputs.
- **36 property tests** × 1,000 random inputs =
36,000 test cases (~9,000 assertions).
- **25,528 matches** oracle-verified on real corpora
(Canterbury bible.txt, Leipzig Czech news) across
all option combinations.
- **9 bugs found and fixed** by property tests.
Properties include: distance correctness (oracle),
non-overlapping, monotonic offsets, wholeWords
boundaries, normalization idempotence, full cartesian
product of all option combinations × distances,
UTF-16 supplementary plane, CJK text, long patterns
(50-63 chars), duplicate/substring patterns.
## API

@@ -247,3 +278,3 @@

`@stll/aho-corasick`'s `StreamMatcher` for exact
matches and fuzzy-search on flagged regions.
prefiltering and fuzzy-search on flagged regions.
- **WASM requires `SharedArrayBuffer`.** Browser

@@ -250,0 +281,0 @@ builds need `Cross-Origin-Opener-Policy: same-origin`

// prettier-ignore
/* eslint-disable */
// @ts-nocheck
/* auto-generated by NAPI-RS */
const { readFileSync } = require('node:fs')
let nativeBinding = null
const loadErrors = []
const isMusl = () => {
let musl = false
if (process.platform === 'linux') {
musl = isMuslFromFilesystem()
if (musl === null) {
musl = isMuslFromReport()
}
if (musl === null) {
musl = isMuslFromChildProcess()
}
}
return musl
}
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
const isMuslFromFilesystem = () => {
try {
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
} catch {
return null
}
}
const isMuslFromReport = () => {
let report = null
if (typeof process.report?.getReport === 'function') {
process.report.excludeNetwork = true
report = process.report.getReport()
}
if (!report) {
return null
}
if (report.header && report.header.glibcVersionRuntime) {
return false
}
if (Array.isArray(report.sharedObjects)) {
if (report.sharedObjects.some(isFileMusl)) {
return true
}
}
return false
}
const isMuslFromChildProcess = () => {
try {
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
} catch (e) {
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
return false
}
}
function requireNative() {
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
try {
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
} catch (err) {
loadErrors.push(err)
}
} else if (process.platform === 'android') {
if (process.arch === 'arm64') {
try {
return require('./fuzzy-search.android-arm64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-android-arm64')
const bindingPackageVersion = require('@stll/fuzzy-search-android-arm64/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm') {
try {
return require('./fuzzy-search.android-arm-eabi.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-android-arm-eabi')
const bindingPackageVersion = require('@stll/fuzzy-search-android-arm-eabi/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
}
} else if (process.platform === 'win32') {
if (process.arch === 'x64') {
if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
try {
return require('./fuzzy-search.win32-x64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-win32-x64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-win32-x64-gnu/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.win32-x64-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-win32-x64-msvc')
const bindingPackageVersion = require('@stll/fuzzy-search-win32-x64-msvc/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'ia32') {
try {
return require('./fuzzy-search.win32-ia32-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-win32-ia32-msvc')
const bindingPackageVersion = require('@stll/fuzzy-search-win32-ia32-msvc/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./fuzzy-search.win32-arm64-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-win32-arm64-msvc')
const bindingPackageVersion = require('@stll/fuzzy-search-win32-arm64-msvc/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
}
} else if (process.platform === 'darwin') {
try {
return require('./fuzzy-search.darwin-universal.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-darwin-universal')
const bindingPackageVersion = require('@stll/fuzzy-search-darwin-universal/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
if (process.arch === 'x64') {
try {
return require('./fuzzy-search.darwin-x64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-darwin-x64')
const bindingPackageVersion = require('@stll/fuzzy-search-darwin-x64/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./fuzzy-search.darwin-arm64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-darwin-arm64')
const bindingPackageVersion = require('@stll/fuzzy-search-darwin-arm64/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
}
} else if (process.platform === 'freebsd') {
if (process.arch === 'x64') {
try {
return require('./fuzzy-search.freebsd-x64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-freebsd-x64')
const bindingPackageVersion = require('@stll/fuzzy-search-freebsd-x64/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./fuzzy-search.freebsd-arm64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-freebsd-arm64')
const bindingPackageVersion = require('@stll/fuzzy-search-freebsd-arm64/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
}
} else if (process.platform === 'linux') {
if (process.arch === 'x64') {
if (isMusl()) {
try {
return require('./fuzzy-search.linux-x64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-x64-musl')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-x64-musl/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.linux-x64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-x64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-x64-gnu/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'arm64') {
if (isMusl()) {
try {
return require('./fuzzy-search.linux-arm64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-arm64-musl')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-arm64-musl/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.linux-arm64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-arm64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-arm64-gnu/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'arm') {
if (isMusl()) {
try {
return require('./fuzzy-search.linux-arm-musleabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-arm-musleabihf')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-arm-musleabihf/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.linux-arm-gnueabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-arm-gnueabihf')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-arm-gnueabihf/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'loong64') {
if (isMusl()) {
try {
return require('./fuzzy-search.linux-loong64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-loong64-musl')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-loong64-musl/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.linux-loong64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-loong64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-loong64-gnu/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'riscv64') {
if (isMusl()) {
try {
return require('./fuzzy-search.linux-riscv64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-riscv64-musl')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-riscv64-musl/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./fuzzy-search.linux-riscv64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-riscv64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-riscv64-gnu/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'ppc64') {
try {
return require('./fuzzy-search.linux-ppc64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-ppc64-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-ppc64-gnu/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 's390x') {
try {
return require('./fuzzy-search.linux-s390x-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-linux-s390x-gnu')
const bindingPackageVersion = require('@stll/fuzzy-search-linux-s390x-gnu/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
}
} else if (process.platform === 'openharmony') {
if (process.arch === 'arm64') {
try {
return require('./fuzzy-search.openharmony-arm64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-openharmony-arm64')
const bindingPackageVersion = require('@stll/fuzzy-search-openharmony-arm64/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'x64') {
try {
return require('./fuzzy-search.openharmony-x64.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-openharmony-x64')
const bindingPackageVersion = require('@stll/fuzzy-search-openharmony-x64/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm') {
try {
return require('./fuzzy-search.openharmony-arm.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@stll/fuzzy-search-openharmony-arm')
const bindingPackageVersion = require('@stll/fuzzy-search-openharmony-arm/package.json').version
if (bindingPackageVersion !== '0.1.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 0.1.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
}
} else {
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
}
}
nativeBinding = requireNative()
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
let wasiBinding = null
let wasiBindingError = null
try {
wasiBinding = require('./fuzzy-search.wasi.cjs')
nativeBinding = wasiBinding
} catch (err) {
if (process.env.NAPI_RS_FORCE_WASI) {
wasiBindingError = err
}
}
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
try {
wasiBinding = require('@stll/fuzzy-search-wasm32-wasi')
nativeBinding = wasiBinding
} catch (err) {
if (process.env.NAPI_RS_FORCE_WASI) {
if (!wasiBindingError) {
wasiBindingError = err
} else {
wasiBindingError.cause = err
}
loadErrors.push(err)
}
}
}
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
error.cause = wasiBindingError
throw error
}
}
if (!nativeBinding) {
if (loadErrors.length > 0) {
throw new Error(
`Cannot find native binding. ` +
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
{
cause: loadErrors.reduce((err, cur) => {
cur.cause = err
return cur
}),
},
)
}
throw new Error(`Failed to load native binding`)
}
module.exports = nativeBinding
module.exports.FuzzySearch = nativeBinding.FuzzySearch
module.exports.distance = nativeBinding.distance
module.exports.Metric = nativeBinding.Metric