Fast string seaching powered by Rust. ( built upon aho-corasick )
pnpm i -D hoshino
import { findAllMatchSync } from 'hoshino'
const patterns = ['apple', 'maple', 'Snapple']
const haystack = 'Nobody likes maple in their apple flavored Snapple.'
// ^ 0 ^ ^ 1 ^ ^ 2 ^
const matches = findAllMatchSync({ patterns, haystack })
// pattern
assert(patterns[matches[0].pattern], 'maple')
assert(patterns[matches[1].pattern], 'apple')
assert(patterns[matches[2].pattern], 'Snapple')
// index
const { start, end } = matches[0]
assert(haystack.slice(start, end), 'maple')
import { findLeftFirstMatchSync } from 'hoshino'
const patterns = ['apple', 'maple', 'Snapple']
const haystack = 'Nobody likes maple in their apple flavored Snapple.'
// ^^^^^ finding the leftmost first match
const { matched, pattern } = findLeftFirstMatchSync({ patterns, haystack })
if (matched) {
assert(patterns[pattern], 'maple')
}
import { findLeftFirstLongestMatch } from 'hoshino'
const patterns = ['map', 'maple', 'Snapple']
const haystack = 'Nobody likes maple in their apple flavored Snapple.'
// ^^^^^ finding the leftmost-longest first match
const { matched, pattern } = findLeftFirstLongestMatch({ patterns, haystack })
if (matched) {
assert(patterns[pattern], 'maple')
}
import { loadPatterns } from 'hoshino'
loadPatterns(['map', 'maple', 'Snapple'])
// use findLeftFirstMatchSync({ haystack })
// use findAllMatchSync({ haystack })
// ...
Add COOP
and COEP
response headers:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Add COOP
and COEP
to enable the SharedArrayBuffer
, or see stackoverflow#65743480 to patch @napi-rs/wasm-runtime
.
MIT