Skip to content

Commit 72823b7

Browse files
committed
Misc
1 parent 3b924bd commit 72823b7

File tree

7 files changed

+1061
-17
lines changed

7 files changed

+1061
-17
lines changed

eslint.config.mjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import eslint from '@eslint/js'
22
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
3+
import importPlugin from 'eslint-plugin-import'
34
import tseslint from 'typescript-eslint'
45

56
export default tseslint.config(
@@ -18,6 +19,7 @@ export default tseslint.config(
1819
...tseslint.configs.recommended,
1920
...tseslint.configs.stylisticTypeChecked,
2021
...tseslint.configs.strictTypeChecked,
22+
importPlugin.flatConfigs.recommended,
2123
eslintPluginUnicorn.configs['flat/recommended'],
2224
{
2325
rules: {
@@ -34,6 +36,38 @@ export default tseslint.config(
3436
'@typescript-eslint/ban-ts-comment': 0,
3537
'unicorn/expiring-todo-comments': 0,
3638
semi: ['error', 'never'],
39+
40+
'import/no-unresolved': 'off',
41+
'import/order': [
42+
'error',
43+
{
44+
named: true,
45+
'newlines-between': 'always',
46+
alphabetize: {
47+
order: 'asc',
48+
},
49+
groups: [
50+
'builtin',
51+
['external', 'internal'],
52+
['parent', 'sibling', 'index', 'object'],
53+
'type',
54+
],
55+
pathGroups: [
56+
{
57+
group: 'builtin',
58+
pattern: 'react',
59+
position: 'before',
60+
},
61+
{
62+
group: 'external',
63+
pattern: '@mui/icons-material',
64+
position: 'after',
65+
},
66+
],
67+
68+
pathGroupsExcludedImportTypes: ['react'],
69+
},
70+
],
3771
},
3872
},
3973
)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@typescript-eslint/eslint-plugin": "^8.4.0",
3030
"@typescript-eslint/parser": "^8.4.0",
3131
"eslint": "^9.0.0",
32+
"eslint-plugin-import": "^2.31.0",
3233
"eslint-plugin-unicorn": "^58.0.0",
3334
"generic-filehandle2": "^1.0.0",
3435
"prettier": "^3.3.3",

src/dedupe.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type Hasher<T> = (input: T) => string
2+
3+
// from https://github.com/seriousManual/dedupe/blob/master/LICENSE
4+
export function dedupe<T>(list: T[], hasher: Hasher<T> = JSON.stringify) {
5+
const clone: T[] = []
6+
const lookup = new Set<string>()
7+
8+
for (const entry of list) {
9+
const hashed = hasher(entry)
10+
11+
if (!lookup.has(hashed)) {
12+
clone.push(entry)
13+
lookup.add(hashed)
14+
}
15+
}
16+
17+
return clone
18+
}

src/index.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
import type { GenericFilehandle } from 'generic-filehandle2'
1+
import { dedupe } from './dedupe'
22
import { concatUint8Array } from './util'
33

4+
import type { GenericFilehandle } from 'generic-filehandle2'
5+
46
const CHUNK_SIZE = 65536
57

68
// this is the number of hex characters to use for the address in ixixx, see
79
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
810
const ADDRESS_SIZE = 10
911

10-
// https://stackoverflow.com/a/9229821/2129219
11-
function uniqBy<T>(a: T[], key: (elt: T) => string) {
12-
const seen = new Set()
13-
return a.filter(item => {
14-
const k = key(item)
15-
return seen.has(k) ? false : seen.add(k)
16-
})
17-
}
18-
1912
export default class Trix {
2013
constructor(
2114
public ixxFile: GenericFilehandle,
@@ -93,8 +86,8 @@ export default class Trix {
9386
}
9487
}
9588

96-
// deduplicate results based on the detail column (resultArr[1])
97-
return uniqBy(resultArr, elt => elt[1]).slice(0, this.maxResults)
89+
// de-duplicate results based on the detail column (resultArr[1])
90+
return dedupe(resultArr, elt => elt[1]).slice(0, this.maxResults)
9891
}
9992

10093
private async getIndex(opts?: { signal?: AbortSignal }) {

test/pneumobase.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { test, expect } from 'vitest'
2-
import Trix from '../src/index'
31
import { LocalFile } from 'generic-filehandle2'
2+
import { expect, test } from 'vitest'
3+
4+
import Trix from '../src/index'
45

56
test('can find pneumobase features', async () => {
67
const trix1 = new Trix(

test/search.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { describe, it, expect } from 'vitest'
2-
import Trix from '../src/index'
31
import { LocalFile } from 'generic-filehandle2'
2+
import { describe, expect, it } from 'vitest'
3+
4+
import Trix from '../src/index'
45

56
describe('Test a search of test1 ix file', () => {
67
const searchTerms = [

0 commit comments

Comments
 (0)