MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / ConvertSync

Method ConvertSync

node/opencc.cc:138–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136 }
137
138 Napi::Value ConvertSync(const Napi::CallbackInfo& info) {
139 Napi::Env env = info.Env();
140 if (info.Length() < 1 || !info[0].IsString()) {
141 Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
142 return env.Undefined();
143 }
144
145 const std::string input = ToUtf8String(info[0]);
146 std::string output;
147 try {
148 output = Convert(std::string_view(input));
149 } catch (opencc::Exception& e) {
150 Napi::Error::New(env, e.what()).ThrowAsJavaScriptException();
151 return env.Undefined();
152 }
153
154 return Napi::String::New(env, output);
155 }
156
157 static Napi::Value GenerateDict(const Napi::CallbackInfo& info) {
158 Napi::Env env = info.Env();

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
ToUtf8StringFunction · 0.85
ConvertFunction · 0.85
LengthMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected