init
This commit is contained in:
commit
8c18398ae4
6 changed files with 111 additions and 0 deletions
21
lib/extractor.ts
Normal file
21
lib/extractor.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
export class Extractor<O> {
|
||||
private extract: (text: string) => O | null;
|
||||
|
||||
public constructor(extract: (text: string) => O | null) {
|
||||
this.extract = extract;
|
||||
}
|
||||
|
||||
public get(text: string) {
|
||||
return this.extract(text);
|
||||
}
|
||||
|
||||
public or<T>(other: Extractor<T>) {
|
||||
const this_extract = this.extract;
|
||||
return new Extractor(text => {
|
||||
const r1 = this_extract(text);
|
||||
if (r1 !== null) return r1;
|
||||
else return other.extract(text);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue