How to handle wstring with NodeJS's N-API?

255 Views Asked by At

Does the NodeJS N-API have any concept or support for C++ wstring? I can't find entries for something like

Napi::WString

The documentation makes no mention of a WString. But wstring is commonly used on Windows APIs. I'm curious how it's typically handled?

1

There are 1 best solutions below

0
Criminal_Affair_At_SO On

Napi types match the internal V8 types - and there is only one internal string type - which happens to use UTF-16 encoding. There are multiple definitions for Napi::String::New and one of them expects a char16_t * input. If your encoding is the same - which is usually the case for 16 bit chars - then you don't need anything else. But still, take care because wchar does not specify an encoding - only a character size.