krdict.js
TypeScript icon, indicating that this package has built-in type declarations

1.5.0 • Public • Published

krdict.js

A node.js module to interact with krdict, the Korean Learners' Dictionary, through its API. To use this module you'll need an API key from krdict.

To install the module from npm run:

npm install krdict.js

An example of a basic query with only the required parameters:

const krdict = require('krdict.js');

krDict.setKey(API_KEY);

krdict.dictionarySearch({
    query: '나무',
}).then((response) => {
    console.log(JSON.stringify(response.data));
});

Which would ouput something like this:

{
  "channel": {
    ...
    "item": [
      {
        "word": [ "나무" ],
        "vocabularyGrade": [ "초급" ],
        "partOfSpeech": [ "명사" ],
        ...
        "meaning": [
          {
            "meaningOrder": [ "1" ],
            "definition": [ "단단한 줄기에 가지와 잎이 달린, 여러 해 동안 자라는 식물." ]
          },
          ...
        ]
      },
      ...
    ]
  }
}

Additional parameters can be passed in

const krdict = require('krdict.js');

krdict.setKey(API_KEY);

krdict.dictionarySearch({
    query: '나무',
    sortMethod: 'alphabetical',
    shouldTranslate: true,
    translationLanguage: 'english'
}).then((response) => {
    console.log(JSON.stringify(response.requestParameters));
    console.log(JSON.stringify(response.data));
});

which are mapped to the parameter names and values expected by the krdict API:

{
  "key": "xyz",
  "q": "나무",
  "sort": "dict",
  "translated": "y",
  "trans_lang": 1
}
{
  "channel": {
    ...
    "item": [
        {
            "word": [ "나무" ],
            "vocabularyGrade": [ "초급" ],
            "partOfSpeech": [ "명사" ],
            ...
            "meaning": [
                {
                    "meaningOrder": [ "1" ],
                    "definition": [ "단단한 줄기에 가지와 잎이 달린, 여러 해 동안 자라는 식물." ],
                    "translation": [{
                        "language": [ "영어" ],
                        "word": [ "tree" ],
                        "definition": [ "A plant with a hard stem, branches and leaves." ]
                    }]
                },
                ...
            ]
        },
        ...
    ]
  }
}

You can view a complete list of accepted parameters and their values on the wiki page

Package Sidebar

Install

npm i krdict.js

Weekly Downloads

8

Version

1.5.0

License

ISC

Unpacked Size

41.4 kB

Total Files

34

Last publish

Collaborators

  • fox_islam