Sign In

@squawk/navaids

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@squawk/navaids - npm Package Compare versions

Comparing version
0.4.7
to
0.5.0
+2
-1
dist/index.d.ts

@@ -5,4 +5,5 @@ /**

*/
export type { MatchRange } from '@squawk/search';
export { createNavaidResolver } from './resolver.js';
export type { NavaidResolver, NavaidResolverOptions, NearestNavaidQuery, NearestNavaidResult, NavaidFrequencyQuery, NavaidSearchQuery, } from './resolver.js';
export type { NavaidResolver, NavaidResolverOptions, NearestNavaidQuery, NearestNavaidResult, NavaidFrequencyQuery, NavaidSearchQuery, NavaidSearchField, NavaidSearchResult, } from './resolver.js';
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,eAAe,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,eAAe,CAAC"}

@@ -1,5 +0,1 @@

/**
* @packageDocumentation
* Pure logic library for querying US navaid data.
*/
export { createNavaidResolver } from './resolver.js';

@@ -0,1 +1,2 @@

import type { MatchRange } from '@squawk/search';
import type { Navaid, NavaidType } from '@squawk/types';

@@ -45,6 +46,10 @@ /**

/**
* Options for a text search query against navaid names and identifiers.
* The searchable fields a navaid {@link NavaidSearchResult} can match on.
*/
export type NavaidSearchField = 'identifier' | 'name';
/**
* Options for a fuzzy text search query against navaid identifiers and names.
*/
export interface NavaidSearchQuery {
/** Case-insensitive substring to match against navaid name or identifier. */
/** Search text, matched fuzzily and case-insensitively against each navaid's identifier and name. */
text: string;

@@ -55,4 +60,19 @@ /** Maximum number of results to return. Defaults to 20. */

types?: ReadonlySet<NavaidType>;
/** Minimum match score (exclusive) in `[0, 1]` a result must reach. Defaults to 0, which keeps every match. Raise it to drop weak fuzzy matches. */
minScore?: number;
}
/**
* A scored navaid result from a fuzzy {@link NavaidResolver.search}.
*/
export interface NavaidSearchResult {
/** The matched navaid record. */
navaid: Navaid;
/** Match strength in `[0, 1]`, where 1 is an exact identifier or name match. */
score: number;
/** Which field produced the best match, identifying what {@link NavaidSearchResult.ranges} index into. */
matchedField: NavaidSearchField;
/** Matched character ranges within the best-matching field's text, for highlighting. */
ranges: MatchRange[];
}
/**
* A stateless resolver providing navaid lookup methods.

@@ -84,6 +104,7 @@ */

/**
* Searches navaids by name or identifier using case-insensitive substring matching.
* Results are returned in alphabetical order by name.
* Fuzzy-searches navaids across identifier and name. Results are scored and
* returned best-match first, each carrying the matched field and character
* ranges for highlighting.
*/
search(query: NavaidSearchQuery): Navaid[];
search(query: NavaidSearchQuery): NavaidSearchResult[];
}

@@ -90,0 +111,0 @@ /**

@@ -1,1 +0,1 @@

{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,oDAAoD;IACpD,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ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;IACrF,KAAK,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IAChC,oJAAoJ;IACpJ,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,0GAA0G;IAC1G,YAAY,EAAE,iBAAiB,CAAC;IAChC,wFAAwF;IACxF,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEjC;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAAC;IAEnD;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,EAAE,CAAC;IAE1D;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,UAAU,CAAC,GAAG,MAAM,EAAE,CAAC;IAEjD;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,EAAE,CAAC;CACxD;AA2BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CA+FnF"}
import { greatCircle } from '@squawk/geo';
import { fuzzySearch } from '@squawk/search';
/**

@@ -102,21 +103,22 @@ * Default maximum distance in nautical miles for nearest-navaid queries.

search(query) {
const limit = query.limit ?? DEFAULT_SEARCH_LIMIT;
const needle = query.text.toLowerCase();
if (needle.length === 0) {
return [];
const options = {
keys: (navaid) => [
{ name: 'identifier', text: navaid.identifier },
{ name: 'name', text: navaid.name },
],
limit: query.limit ?? DEFAULT_SEARCH_LIMIT,
minScore: query.minScore ?? 0,
};
const types = query.types;
if (types) {
options.filter = (navaid) => types.has(navaid.type);
}
const results = [];
for (const navaid of navaids) {
if (query.types && !query.types.has(navaid.type)) {
continue;
}
if (navaid.name.toLowerCase().includes(needle) ||
navaid.identifier.toLowerCase().includes(needle)) {
results.push(navaid);
}
}
results.sort((a, b) => a.name.localeCompare(b.name));
return results.slice(0, limit);
return fuzzySearch(navaids, query.text, options).map((match) => ({
navaid: match.item,
score: match.score,
matchedField: match.field,
ranges: match.ranges,
}));
},
};
}
{
"name": "@squawk/navaids",
"version": "0.4.7",
"version": "0.5.0",
"type": "module",

@@ -45,2 +45,3 @@ "description": "Navaid queries by identifier, frequency, type, location, or name search",

"@squawk/geo": "^0.4.3",
"@squawk/search": "^0.1.0",
"@squawk/types": "^0.8.0"

@@ -47,0 +48,0 @@ },

+25
-10

@@ -6,3 +6,3 @@ <h1><img src="../../../assets/squawk-logo.svg" alt="squawk logo" width="48" height="48" style="vertical-align: middle">&nbsp; @squawk/navaids</h1>

Pure logic library for querying US navaid data. Look up navaids by identifier,
frequency, geographic proximity, type, or name search. Contains no bundled data -
frequency, geographic proximity, type, or fuzzy text search. Contains no bundled data -
accepts an array of Navaid records at initialization. For zero-config use, pair

@@ -36,4 +36,5 @@ with `@squawk/navaid-data`.

// Search by name or identifier
// Fuzzy-search across identifier and name (scored, best match first)
const results = resolver.search({ text: 'boston' });
console.log(results[0]?.navaid.name, results[0]?.score);
```

@@ -132,11 +133,25 @@

Searches navaids by name or identifier using case-insensitive substring matching.
Results are returned in alphabetical order by name.
Fuzzy-searches navaids across identifier and name. Matching is case-insensitive and
tolerant of prefixes, substrings, subsequences, and small typos. Results are scored
and returned best-match first.
| Property | Type | Description |
| -------- | ------------------------ | ----------------------------------------------------------------- |
| `text` | string | Case-insensitive substring to match against name or identifier |
| `limit` | number | Optional. Maximum number of results. Defaults to 20 |
| `types` | ReadonlySet\<NavaidType> | Optional. When provided, only navaids of these types are returned |
| Property | Type | Description |
| ---------- | ------------------------ | ---------------------------------------------------------------------------------------- |
| `text` | string | Search text, matched fuzzily against each navaid's identifier and name |
| `limit` | number | Optional. Maximum number of results. Defaults to 20 |
| `types` | ReadonlySet\<NavaidType> | Optional. When provided, only navaids of these types are returned |
| `minScore` | number | Optional. Minimum match score (exclusive) in `[0, 1]` a result must reach. Defaults to 0 |
Returns `Navaid[]`.
Returns `NavaidSearchResult[]`, sorted by descending score, each containing:
- `navaid` - the matched Navaid record
- `score` - match strength in `[0, 1]`, where 1 is an exact identifier or name match
- `matchedField` - which field produced the best match: `'identifier'` or `'name'`
- `ranges` - matched character ranges within the best-matching field's text, for highlighting
```typescript
const results = resolver.search({ text: 'boston', limit: 10 });
for (const { navaid, score, matchedField } of results) {
console.log(navaid.identifier, score, `(matched ${matchedField})`);
}
```