npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yomichan-dict-builder

v2.9.2

Published

Build Yomichan/Yomitan dictionaries with ease.

Downloads

393

Readme

Yomichan/Yomitan Dictionary Builder

npm

This is a library for building dictionaries for Yomitan (formerly Yomichan).

Installation

npm install yomichan-dict-builder

Contributing

Please let me know if you find any bugs or have any feature requests. I'd love to see this library be used to create more Yomitan dictionaries, so if you do end up using it, please let me know!

Used In

Relevant Tools and Information

Usage

  • The Dictionary class represents a Yomitan dictionary. You can add entries, kanji, and other things to it before exporting it with export().
  • The DictionaryIndex, TermEntry, and KanjiEntry classes represent some of the more complicated parts of a Yomitan dictionary. You can create them and add them to a dictionary using the setIndex(), addTerm(), and addKanji() methods of the Dictionary class.
  • If using JS, you might want to set "js/ts.implicitProjectConfig.checkJs": true in your VSCode settings to get type checking for JavaScript files and not have to deal with your dictionaries failing to validate against the Yomitan schemas. However, I recommend using TypeScript.
  • In particular, it might be a good idea to check out the Yomitan Schemas as well as the type definitions within the package so that you know what's available for use when creating detailed definitions.
  • You can then type your objects in JS by using JSDoc comments to provide editor intellisense and type checking. You can see this in action in example.js.
  • You can simply add a styles.css file using the addFile() method to add custom CSS to your dictionary. Read more in the official docs.

Dictionary Class

The Dictionary class represents a Yomitan dictionary and is used to manage entries, kanji, and various metadata before exporting.

Initializing a Dictionary

To create a new dictionary:

const { Dictionary } = require('yomichan-dict-builder');

const dictionary = new Dictionary({
  fileName: 'test.zip',
});

Setting Index Information

You can create an index for the dictionary using the DictionaryIndex class and add it to the dictionary using setIndex():

const { DictionaryIndex } = require('yomichan-dict-builder');

const index = new DictionaryIndex()
  .setTitle('Test Dictionary')
  .setRevision('1.0')
  .setAuthor('Marv')
  .setDescription('Test dictionary for yomichan-dict-builder')
  // ...additional index details
  .build();

await dictionary.setIndex(index);

Adding Term Entries

Term entries can be added using the addTerm() method of the Dictionary class:

const { TermEntry } = require('yomichan-dict-builder');

const entry = new TermEntry('test').setReading('test').build();
await dictionary.addTerm(entry);

Additionally, detailed definitions can be added to a term entry:

// Creating a detailed definition
const detailedDefinition = {
  type: 'structured-content',
  // ...detailed definition content
};

const entry2 = new TermEntry('test2')
  .setReading('reading')
  .addDetailedDefinition(detailedDefinition)
  .addDetailedDefinition('test2')
  .build();

await dictionary.addTerm(entry2);

Adding Kanji Entries

Kanji entries can be added using the addKanji() method:

dictionary.addKanji({
  kanji: '読',
  kunyomi: 'あ',
  onyomi: 'ア',
  meanings: ['Asia'],
  stats: {
    strokes: '7',
    grade: '8',
  },
});
dictionary.addKanji({
  kanji: '詠',
});

// Alternatively, create a KanjiEntry object first
const { KanjiEntry } = require('yomichan-dict-builder');
const kanjiEntry = new KanjiEntry('亜')
  .setKunyomi('あ')
  .setOnyomi('ア')
  .addMeaning('Asia')
  .setStats({ strokes: '7', grade: '8' });

dictionary.addKanji(kanjiEntry.build());

Note that the statistics added here must be added as tags as well.

Adding Frequency

Frequency information can be added to terms and kanji using the addTermMeta() and addKanjiMeta() methods:

dictionary.addTermMeta(['term', 'freq', 1]);
dictionary.addTermMeta(['term', 'freq', 'N1']);
// ...additional term metadata

dictionary.addKanjiMeta(['亜', 'freq', 1]);
dictionary.addKanjiMeta(['亜', 'freq', 'one']);
// ...additional kanji metadata

Adding Pitch Accent

Pitch accent information can be added to terms using the addTermMeta() method:

dictionary.addTermMeta([
  '亜',
  'pitch',
  {
    reading: 'あ',
    pitches: [
      {
        position: 1,
        devoice: [], // optional
        nasal: [], // optional
      },
    ],
  },
]);

Adding Tags

Tags can be added to the dictionary. These are necessary when you add a tag/statistic to a term or kanji entry.

dictionary.addTag({
  name: 'jouyou',
  category: 'frequent',
  sortingOrder: -5,
  notes: 'included in list of regular-use characters',
  popularityScore: 0,
});

Adding Local Files

You can add local files like images to the dictionary using the addFile() method:

await dictionary.addFile('./examples/icon64.png', 'img/icon64.png');

This copies the file at ./examples/icon64.png and saves it into the dictionary zip file at img/icon64.png.

The file can then be referenced in structured content definitions:

const imageScNode = {
  tag: 'img',
  path: 'img/icon64.png',
  data: {
    'dict-data': 'testImage',
  },
  title: 'test image',
};

So addFile() allows you to bundle any needed images, audio clips, etc. into the dictionary itself.

Exporting the Dictionary

To export the constructed dictionary:

const stats = await dictionary.export('./test');
console.log('Done exporting!');
console.table(stats);
// ┌────────────────┬────────┐
// │    (index)     │ Values │
// ├────────────────┼────────┤
// │   termCount    │ 20002  │
// │ termMetaCount  │   5    │
// │   kanjiCount   │   1    │
// │ kanjiMetaCount │   3    │
// └────────────────┴────────┘