-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add wordClass and maxCount query parameters
- Loading branch information
1 parent
0618f74
commit 947297c
Showing
6 changed files
with
135 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './two-way-map'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
export class TwoWayMap<L extends string | number, R extends string | number> { | ||
private map: Record<L, R> = {} as Record<L, R>; | ||
private reverseMap: Record<R, L> = {} as Record<R, L>; | ||
|
||
constructor(entries: [L, R][]) { | ||
entries.forEach(([left, right]) => { | ||
this.map[left] = right; | ||
this.reverseMap[right] = left; | ||
}); | ||
} | ||
|
||
get(left: L): R { | ||
return this.map[left]; | ||
} | ||
|
||
getReverse(right: R): L { | ||
return this.reverseMap[right]; | ||
} | ||
|
||
has(left: string | number): left is L { | ||
return left in this.map; | ||
} | ||
|
||
hasReverse(right: string | number): right is R { | ||
return right in this.reverseMap; | ||
} | ||
|
||
getEntries(): [L, R][] { | ||
return Object.entries(this.map) as [L, R][]; | ||
} | ||
|
||
getReverseEntries(): [R, L][] { | ||
return Object.entries(this.reverseMap) as [R, L][]; | ||
} | ||
|
||
getKeys(): L[] { | ||
return Object.keys(this.map) as L[]; | ||
} | ||
|
||
getReverseKeys(): R[] { | ||
return Object.keys(this.reverseMap) as R[]; | ||
} | ||
|
||
getValues(): R[] { | ||
return Object.values(this.map) as R[]; | ||
} | ||
|
||
getReverseValues(): L[] { | ||
return Object.values(this.reverseMap) as L[]; | ||
} | ||
|
||
get size(): number { | ||
return Object.keys(this.map).length; | ||
} | ||
} |