Skip to content

Installation

Install kanji.js from npm, load it from a CDN, or download a built file. All three give you the same library and the same dictionary.

npm#

Install the kanji.js package for Node.js projects and for apps built with a bundler such as Vite, webpack or Rollup. This is the recommended option.

$ npm install kanji.js

The package works with other package managers too:

$ yarn add kanji.js
$ pnpm add kanji.js

CDN#

To use kanji.js in a browser without a build step, add a script tag. The script defines a global Kanji class. Pin the version in the URL so a new release can't change your page without warning.

<script src="https://cdn.jsdelivr.net/npm/kanji.js@1.6.2/dist/kanji.min.js"></script>
<script>
console.log(Kanji.getDetails('日').meanings)
// ['day', 'sun', 'Japan', 'counter for days']
</script>

unpkg serves the same file:

<script src="https://unpkg.com/kanji.js@1.6.2/dist/kanji.min.js"></script>

Direct download#

Every release on GitHub Releases includes the built kanji.min.js file and the source code. The Downloads page lists the latest releases. Copy kanji.min.js into your project and load it with a script tag, the same way as the CDN option.

TypeScript#

The package includes type declarations (index.d.ts), so you don't need to install anything else. Import the default export as usual:

import Kanji from 'kanji.js'
const day = Kanji.getDetails('日')

Bundle size#

The library includes the whole dictionary, so it's larger than a typical utility library. The minified file is about 1.9 MB, or about 350 KB over the network with gzip. In a browser app, load it only when it's needed:

button.addEventListener('click', async () => {
const { default: Kanji } = await import('kanji.js')
showResult(Kanji.random())
})

See Load the library on demand for more on this.