From cd01df3747ff361fab819fd1d30fac1dba6240e1 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 6 Jul 2023 18:23:02 +0200 Subject: update tests and examples --- examples/sentence-word-lookup.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'examples/sentence-word-lookup.ts') diff --git a/examples/sentence-word-lookup.ts b/examples/sentence-word-lookup.ts index d60ffbf..9ff9bdf 100644 --- a/examples/sentence-word-lookup.ts +++ b/examples/sentence-word-lookup.ts @@ -1,12 +1,11 @@ import Yomikun from "../api/yomikun.ts"; import DirectCoreClient from "../core/direct/client.ts"; -// import "../util/string.ts"; // Create a direct (local) API instance var api = new Yomikun(new DirectCoreClient()); -// Excplicitly wait until everything is ready -// await api.ready; +// Explicitly wait until everything is ready (not required) +await api.ready; // This sentence does not contain all information until it is explicitly // fetched by the user. Each subclass instantiated from an API instance keeps a @@ -14,15 +13,14 @@ var api = new Yomikun(new DirectCoreClient()); var sentence = await api.sentence("この紅茶は甘すぎる"); // Pick the word 紅茶 from the sentence in some different ways: -var word = sentence.words.find(w => w.writing == "紅茶"); // filter terms by writing (matches first only) -// var word = sentence.first("紅茶"); // reference substring (matches first only) -// var word = sentence.words[1]; // reference word index (depends on correct deconjugations/parsing) -console.log(word); +var word = sentence.words.find(w => w.written("紅茶"))!; // filter terms by writing (matches first only) +var word = sentence.first("紅茶")!; // reference substring (matches first only) +var word = sentence.words[1]; // reference word index (depends on correct deconjugations/parsing) // Fetch definitions for word -var glossary = await word?.glossary(); +var glossary = await word.glossary(); // Show some definitions -console.log(glossary?.dict("jmdict_eng")[0]); // print first definition from JMdict -// console.log(glossary.all()); // print all definitions +console.log(glossary.dict("jmdict_eng")[0]); // print first definition from JMdict +console.log(glossary.all()); // print all definitions -- cgit v1.2.3