Skip to content

Commit f1a1971

Browse files
committed
feat(utility): add small utility functions
1 parent 15b447d commit f1a1971

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/utility.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Noun } from './noun';
2+
import { Writable } from './textHelper';
3+
4+
export function within(word: Noun): Writable {
5+
return {
6+
write() {
7+
return `in ${word.dative().write()}`;
8+
},
9+
};
10+
}
11+
12+
export function into(word: Noun): Writable {
13+
return {
14+
write() {
15+
return `in ${word.accusative().write()}`;
16+
},
17+
};
18+
}
19+
20+
export function to(word: Noun): Writable {
21+
return {
22+
write() {
23+
return `zu ${word.dative().write()}`;
24+
},
25+
};
26+
}

test/utility.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { noun } from '../src/noun';
2+
import { into, to, within } from '../src/utility';
3+
4+
test('provides aliases', () => {
5+
const car = noun('das Haus,häuser,-es');
6+
expect(within(car).write()).toBe('in einem Haus');
7+
expect(within(car.specific()).write()).toBe('in dem Haus');
8+
9+
expect(into(car).write()).toBe('in ein Haus');
10+
11+
expect(to(car).write()).toBe('zu einem Haus');
12+
});

0 commit comments

Comments
 (0)