| 155 | } |
| 156 | |
| 157 | static Napi::Value GenerateDict(const Napi::CallbackInfo& info) { |
| 158 | Napi::Env env = info.Env(); |
| 159 | if (info.Length() < 4 || !info[0].IsString() || !info[1].IsString() || |
| 160 | !info[2].IsString() || !info[3].IsString()) { |
| 161 | Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); |
| 162 | return env.Undefined(); |
| 163 | } |
| 164 | const std::string inputFileName = ToUtf8String(info[0]); |
| 165 | const std::string outputFileName = ToUtf8String(info[1]); |
| 166 | const std::string formatFrom = ToUtf8String(info[2]); |
| 167 | const std::string formatTo = ToUtf8String(info[3]); |
| 168 | try { |
| 169 | opencc::ConvertDictionary(inputFileName, outputFileName, formatFrom, |
| 170 | formatTo); |
| 171 | } catch (opencc::Exception& e) { |
| 172 | Napi::Error::New(env, e.what()).ThrowAsJavaScriptException(); |
| 173 | } |
| 174 | return env.Undefined(); |
| 175 | } |
| 176 | |
| 177 | static Napi::Object Init(Napi::Env env, Napi::Object exports) { |
| 178 | Napi::Function cons = DefineClass( |
nothing calls this directly
no test coverage detected