@prose-reader/enhancer-search 1.164.0 → 1.166.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prose-reader/enhancer-search",
3
- "version": "1.164.0",
3
+ "version": "1.166.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.umd.cjs",
6
6
  "module": "./dist/index.js",
@@ -14,15 +14,13 @@
14
14
  "scripts": {
15
15
  "start": "vite build --watch --mode development",
16
16
  "build": "tsc && vite build",
17
- "lint:read": "prettier --check . && eslint . --ext .ts,.tsx,.js,.jsx",
18
- "lint:write": "prettier --write . && eslint --fix . --ext .ts,.tsx,.js,.jsx",
19
17
  "test": "vitest run --coverage"
20
18
  },
21
19
  "dependencies": {
22
- "@prose-reader/core": "^1.164.0"
20
+ "@prose-reader/core": "^1.166.0"
23
21
  },
24
22
  "peerDependencies": {
25
23
  "rxjs": "*"
26
24
  },
27
- "gitHead": "6f037c838ab7ea03dcb34000c7896e496efd1782"
25
+ "gitHead": "949886f6d3d44e3b3034bf8d71bbb1abe7e76fb4"
28
26
  }
package/src/index.test.ts CHANGED
@@ -3,5 +3,3 @@ import { expect, test } from "vitest"
3
3
  test("it works", () => {
4
4
  expect(true).toBe(true)
5
5
  })
6
-
7
- export {}
package/src/index.ts CHANGED
@@ -1,8 +1,7 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { deferIdle, Reader } from "@prose-reader/core"
3
- import { defer, forkJoin, Observable, of } from "rxjs"
1
+ import { deferIdle, type Reader } from "@prose-reader/core"
2
+ import { defer, forkJoin, type Observable, of } from "rxjs"
4
3
  import { catchError, finalize, map, switchMap } from "rxjs/operators"
5
- import { searchInDocument, SearchResult } from "./search"
4
+ import { searchInDocument, type SearchResult } from "./search"
6
5
  import { report } from "./report"
7
6
 
8
7
  /**
@@ -14,7 +13,9 @@ import { report } from "./report"
14
13
  * enhancer is agnostic and can only search into documents.
15
14
  */
16
15
  export const searchEnhancer =
17
- <InheritOptions, InheritOutput extends Reader>(next: (options: InheritOptions) => InheritOutput) =>
16
+ <InheritOptions, InheritOutput extends Reader>(
17
+ next: (options: InheritOptions) => InheritOutput,
18
+ ) =>
18
19
  (
19
20
  options: InheritOptions,
20
21
  ): InheritOutput & {
@@ -37,7 +38,9 @@ export const searchEnhancer =
37
38
 
38
39
  if (!doc) return of([])
39
40
 
40
- return deferIdle(() => searchInDocument(reader, item, doc, text)).pipe(
41
+ return deferIdle(() =>
42
+ searchInDocument(reader, item, doc, text),
43
+ ).pipe(
41
44
  finalize(() => {
42
45
  release?.()
43
46
  }),
@@ -57,7 +60,10 @@ export const searchEnhancer =
57
60
  return of([])
58
61
  }
59
62
 
60
- const searches$ = reader.context.manifest?.spineItems.map((_, index) => searchForItem(index, text)) || []
63
+ const searches$ =
64
+ reader.context.manifest?.spineItems.map((_, index) =>
65
+ searchForItem(index, text),
66
+ ) || []
61
67
 
62
68
  return forkJoin([...searches$, of([])])
63
69
  }).pipe(
package/src/search.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { Reader, SpineItem } from "@prose-reader/core"
2
- import { Observable, of } from "rxjs"
3
- import { ResultItem } from "./types"
1
+ import type { Reader, SpineItem } from "@prose-reader/core"
2
+ import { type Observable, of } from "rxjs"
3
+ import type { ResultItem } from "./types"
4
4
 
5
5
  export type SearchResult = ResultItem[]
6
6
 
@@ -25,9 +25,10 @@ const searchNodeContainingText = (node: Node, text: string) => {
25
25
  if (subNode.nodeType === 3) {
26
26
  const content = (subNode as Text).data.toLowerCase()
27
27
  if (content) {
28
- let match
28
+ let match: RegExpExecArray | null = null
29
29
  const regexp = RegExp(`(${text})`, `gi`)
30
30
 
31
+ // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
31
32
  while ((match = regexp.exec(content)) !== null) {
32
33
  if (match.index >= 0 && subNode.ownerDocument) {
33
34
  const range = subNode.ownerDocument.createRange()
@@ -44,7 +45,12 @@ const searchNodeContainingText = (node: Node, text: string) => {
44
45
  return rangeList
45
46
  }
46
47
 
47
- export const searchInDocument = (reader: Reader, item: SpineItem, doc: Document, text: string): Observable<SearchResult> => {
48
+ export const searchInDocument = (
49
+ reader: Reader,
50
+ item: SpineItem,
51
+ doc: Document,
52
+ text: string,
53
+ ): Observable<SearchResult> => {
48
54
  const ranges = searchNodeContainingText(doc, text)
49
55
 
50
56
  const newResults = ranges.map((range) => {
package/vite.config.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineConfig } from "vite"
2
2
  import dts from "vite-plugin-dts"
3
- import { resolve } from "path"
3
+ import { resolve } from "node:path"
4
4
  import { name } from "./package.json"
5
5
  import externals from "rollup-plugin-node-externals"
6
6
 
package/.eslintrc.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require(`../../.eslintrc.cjs`)
package/.prettierrc.cjs DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- ...require("../../.prettierrc.js"),
3
- }