JSPM

hoshino

2.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 56
  • Score
    100M100P100Q45620F
  • License MIT

Fast string seaching powered by Rust

Package Exports

  • hoshino
  • hoshino/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hoshino) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hoshino

Fast string seaching powered by Rust. ( built upon aho-corasick )

Install

  pnpm i -D hoshino

Usage

findAllMatchSync / findAllMatch

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')

findLeftFirstMatchSync / findLeftFirstMatch

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')
}

findLeftFirstLongestMatchSync / findLeftFirstLongestMatch

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')
}

loadPatterns

import { loadPatterns } from 'hoshino'

loadPatterns(['map', 'maple', 'Snapple'])
// use findLeftFirstMatchSync({ haystack })
// use findAllMatchSync({ haystack })
// ...

License

MIT