Skip to content

Commit 76a34f8

Browse files
authored
Merge pull request #5 from peterhil/reduce-size
deps: Update rambdax to latest version 11.2.0
2 parents 747a4e3 + 0a564a1 commit 76a34f8

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@
7474
"string-algorithm"
7575
],
7676
"dependencies": {
77-
"rambdax": "^7.4.1"
77+
"rambdax": "^11.2.0"
7878
}
7979
}

pnpm-lock.yaml

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commonTypes.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export interface Dictionary<T> {[index: string]: T}
22

3+
export type Length = number
34
export type Ngram = string
45
export type Position = number
56
export type Term = string
@@ -9,7 +10,7 @@ export type NormaliseFunction = (term: Term) => Ngram
910
export type Indexable = string | number | symbol
1011

1112
export type Description = Record<Indexable, Position[]>
12-
export type Positions = Dictionary<Position>
13+
export type Lengths = Dictionary<Length>
1314
export type Locations = Dictionary<Position[]>
1415
export type StringDescription = Record<string, Position[]>
1516
export type Terms = Term[] | Record<Indexable, Term>

src/search.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
add,
32
filter,
43
filterObject,
54
flatten,
@@ -13,19 +12,18 @@ import {
1312
mergeAll,
1413
not,
1514
pick,
16-
pipe,
1715
reduce,
1816
splitAt,
1917
values,
2018
} from 'rambdax'
2119

22-
import { empty, ids, match, nonEmpty } from './utils/helpers'
20+
import { empty, ids, lengthFromPositions, match, nonEmpty } from './utils/helpers'
2321
import { ngram } from './ngram'
2422

2523
import type {
2624
Description,
2725
Indexable,
28-
Positions,
26+
Lengths,
2927
Locations,
3028
Ngram,
3129
NgramIndex,
@@ -202,10 +200,9 @@ export class Index {
202200
/**
203201
* Lengths of all the terms in the index
204202
*/
205-
lengths (): Positions {
203+
lengths (): Lengths {
206204
const descriptions: Description[] = this._ends()
207-
const lengthFromPositions = pipe(last, add(1)) // get length from last position
208-
const lengths: Positions = map(
205+
const lengths: Lengths = map(
209206
lengthFromPositions,
210207
mergeAll(descriptions),
211208
)

src/utils/helpers.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import tap from 'tap'
22

33
import {
44
ids,
5+
lengthFromPositions,
56
match,
67
nonEmpty,
78
} from './helpers'
@@ -12,6 +13,13 @@ tap.test('utils ids', assert => {
1213
assert.end()
1314
})
1415

16+
tap.test('utils lengthFromPositions', assert => {
17+
assert.same(lengthFromPositions([]), 0)
18+
assert.same(lengthFromPositions([0]), 1)
19+
assert.same(lengthFromPositions([0, 1]), 2)
20+
assert.end()
21+
})
22+
1523
tap.test('utils nonEmpty', assert => {
1624
assert.ok(nonEmpty({a: []}))
1725
assert.notOk(nonEmpty({}))

src/utils/helpers.ts

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import type {
1313
Description,
1414
Indexable,
15+
Length,
1516
Position,
1617
StringDescription,
1718
} from '../commonTypes'
@@ -22,6 +23,19 @@ export const nil: Position[] = []
2223

2324
export const ids = (obj: object): Indexable[] => keys(obj)
2425

26+
/**
27+
* Get length from last position
28+
*/
29+
export function lengthFromPositions (
30+
positions: Position[]
31+
): Length {
32+
if (isEmpty(positions)) return 0
33+
34+
const length: Length = positions[positions.length - 1] + 1
35+
36+
return length
37+
}
38+
2539
/**
2640
* Rambda’s {@link https://selfrefactor.github.io/rambdax/#/?id=isempty|isEmpty} complemented (negated).
2741
* @returns true for non-empty things.

0 commit comments

Comments
 (0)