Why create a npm package ?
Just to:
- Understand what i use when i use
npm i ...
oryarn add ...
- Especially understand how they made it !
So, i create my first package !
What is the library ?
The library named Cedict dictionary and it's actually available on npm.js and yarnpkg.com !
This library simply give you some functions and a large JSON file with for each object the :
- Traditional character in Chinese
- Simplified character in Chinese
- Pinyin pronunciation
- English translation
Here is an example of what you can have in an object :
{
traditional: "上天入地",
simplified: "上天入地",
pinyin: "shang4",
english: "lit. to go up to heaven or down to Hades (idiom)/fig. to go to great lengths/to search heaven and earth/"
}
ℹ️ I do not currently speak Chinese while writing this article!
It’s a really complex language, though the C language and all its pointers 🤣.
What is the Cedict ?
The Cedict, called CC-CEDICT is a continuation of the CEDICT project.
This project provide a complete downloadable Chinese to English dictionary, and all of this in a specific format of CC-CEDICT.
It's an open source project who is actually frequently updated !
ℹ️ If you want, you can go to her wiki.
How the @tykok/cedict-dictionary package work
The project have two parts :
- The part who get data and format the Cedict into a JSON.
- The part who simply exploit the JSON.
To get the final JSON, we need to
- Download the
.zip
on CC-CEDICT project. - Unzip it.
- Get the file who contain the dictionary.
- Parse it into a JSON file.
All this actions are in a script called by a cronjob who simply execute this script and update the JSON Cedict of the library.
The second part is more simply than the previous one !
Here, we have a JSON file. And we can simply exploit it with some functions to get for example a chinese object with a traditional character.
A simple start with @tykok/cedict-dictionary
To start, use yarn
or npm
to install the dependency :
# With yarn
yarn add @tykok/cedict-dictionary
# With npm
npm i @tykok/cedict-dictionary
Next, just import the global class to use the Cedict :
import Cedict from '@tykok/cedict-dictionary'
And, with the Cedict
class, you can use some function to get a specific chinese character, the pronunciation or all the cedict !
To know how to use this package, you can go to the documentation.
Conclusion
This project is not just for fun. I create it to learn some things i actually don't know or improve it !
Of course, this project is open source and you can come to contribute to this project. There are still many things to improve !
Tell me if you have any suggestions, or remarks for the project. And of course if this article was interesting.
Top comments (0)