aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/base.ts20
-rw-r--r--api/glossary.ts15
-rw-r--r--api/readme.md6
-rw-r--r--api/sentence.ts15
-rw-r--r--api/word.ts15
-rw-r--r--api/yomikun.ts16
6 files changed, 87 insertions, 0 deletions
diff --git a/api/base.ts b/api/base.ts
new file mode 100644
index 0000000..e89e76b
--- /dev/null
+++ b/api/base.ts
@@ -0,0 +1,20 @@
+import Core from "../core/api.ts";
+import Yomikun from "./yomikun.ts";
+
+/** @summary generic class that keeps a reference to parent API reference */
+export default abstract class APIBase {
+ private _resolveAPI: (api: Yomikun) => void = _ => {};
+
+ protected api: Promise<Yomikun>;
+
+ constructor() {
+ this.api = new Promise<Yomikun>(res => this._resolveAPI = res);
+ }
+
+ /** @summary set API reference and return self (for use directly after constructor) */
+ withParent(api: Yomikun) {
+ this._resolveAPI(api);
+ return this;
+ }
+}
+
diff --git a/api/glossary.ts b/api/glossary.ts
new file mode 100644
index 0000000..0b16e48
--- /dev/null
+++ b/api/glossary.ts
@@ -0,0 +1,15 @@
+import APIBase from "./base.ts";
+
+export default class Glossary extends APIBase {
+ constructor() {
+ super();
+ }
+
+ dict(name: string): Array<string> {
+ return this.all();
+ }
+
+ all(): Array<string> {
+ return [];
+ }
+}
diff --git a/api/readme.md b/api/readme.md
new file mode 100644
index 0000000..58ebbcb
--- /dev/null
+++ b/api/readme.md
@@ -0,0 +1,6 @@
+# Yomikun API
+
+This folder contains an abstracted version of the [Core
+API](../core/readme.md), which is recommended for general use. Please see [the
+API examples](../examples/readme.md).
+
diff --git a/api/sentence.ts b/api/sentence.ts
new file mode 100644
index 0000000..dc14cb2
--- /dev/null
+++ b/api/sentence.ts
@@ -0,0 +1,15 @@
+import APIBase from "./base.ts";
+import Word from "./word.ts";
+import Yomikun from "./yomikun.ts";
+
+export default class Sentence extends APIBase {
+ public words: Array<Word> = [];
+
+ constructor() {
+ super();
+ }
+
+ first(searchValue: RegExp | string): Word | undefined {
+ return this.words[0];
+ }
+}
diff --git a/api/word.ts b/api/word.ts
new file mode 100644
index 0000000..d2df69e
--- /dev/null
+++ b/api/word.ts
@@ -0,0 +1,15 @@
+import Glossary from "./glossary.ts";
+import APIBase from "./base.ts";
+
+export default class Word extends APIBase {
+ public writing: string = "TODO";
+ public reading: string = "TODO";
+
+ constructor() {
+ super();
+ }
+
+ async glossary() {
+ return new Glossary().withParent(await this.api);
+ }
+}
diff --git a/api/yomikun.ts b/api/yomikun.ts
new file mode 100644
index 0000000..4971567
--- /dev/null
+++ b/api/yomikun.ts
@@ -0,0 +1,16 @@
+import Core from "../core/api.ts";
+import RemoteCoreClient from "../core/http/client.ts";
+import Sentence from "./sentence.ts";
+
+export default class Yomikun {
+ protected core: Core;
+
+ constructor(core?: Core) {
+ this.core = core ?? new RemoteCoreClient();
+ }
+
+ async sentence(input: string): Promise<Sentence> {
+ return new Sentence().withParent(this);
+ }
+}
+