Skip to content

deps: Update rambdax to latest version 11.2.0 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@
"string-algorithm"
],
"dependencies": {
"rambdax": "^7.4.1"
"rambdax": "^11.2.0"
}
}
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/commonTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface Dictionary<T> {[index: string]: T}

export type Length = number
export type Ngram = string
export type Position = number
export type Term = string
Expand All @@ -9,7 +10,7 @@ export type NormaliseFunction = (term: Term) => Ngram
export type Indexable = string | number | symbol

export type Description = Record<Indexable, Position[]>
export type Positions = Dictionary<Position>
export type Lengths = Dictionary<Length>
export type Locations = Dictionary<Position[]>
export type StringDescription = Record<string, Position[]>
export type Terms = Term[] | Record<Indexable, Term>
Expand Down
11 changes: 4 additions & 7 deletions src/search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
add,
filter,
filterObject,
flatten,
Expand All @@ -13,19 +12,18 @@ import {
mergeAll,
not,
pick,
pipe,
reduce,
splitAt,
values,
} from 'rambdax'

import { empty, ids, match, nonEmpty } from './utils/helpers'
import { empty, ids, lengthFromPositions, match, nonEmpty } from './utils/helpers'
import { ngram } from './ngram'

import type {
Description,
Indexable,
Positions,
Lengths,
Locations,
Ngram,
NgramIndex,
Expand Down Expand Up @@ -202,10 +200,9 @@ export class Index {
/**
* Lengths of all the terms in the index
*/
lengths (): Positions {
lengths (): Lengths {
const descriptions: Description[] = this._ends()
const lengthFromPositions = pipe(last, add(1)) // get length from last position
const lengths: Positions = map(
const lengths: Lengths = map(
lengthFromPositions,
mergeAll(descriptions),
)
Expand Down
8 changes: 8 additions & 0 deletions src/utils/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import tap from 'tap'

import {
ids,
lengthFromPositions,
match,
nonEmpty,
} from './helpers'
Expand All @@ -12,6 +13,13 @@ tap.test('utils ids', assert => {
assert.end()
})

tap.test('utils lengthFromPositions', assert => {
assert.same(lengthFromPositions([]), 0)
assert.same(lengthFromPositions([0]), 1)
assert.same(lengthFromPositions([0, 1]), 2)
assert.end()
})

tap.test('utils nonEmpty', assert => {
assert.ok(nonEmpty({a: []}))
assert.notOk(nonEmpty({}))
Expand Down
14 changes: 14 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import type {
Description,
Indexable,
Length,
Position,
StringDescription,
} from '../commonTypes'
Expand All @@ -22,6 +23,19 @@ export const nil: Position[] = []

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

/**
* Get length from last position
*/
export function lengthFromPositions (
positions: Position[]
): Length {
if (isEmpty(positions)) return 0

const length: Length = positions[positions.length - 1] + 1

return length
}

/**
* Rambda’s {@link https://selfrefactor.github.io/rambdax/#/?id=isempty|isEmpty} complemented (negated).
* @returns true for non-empty things.
Expand Down
Loading