Skip to content

Instantly share code, notes, and snippets.

@NickNaso
Created September 10, 2018 08:37
Show Gist options
  • Select an option

  • Save NickNaso/7bcf6a19d71adffa26d93866795c7adc to your computer and use it in GitHub Desktop.

Select an option

Save NickNaso/7bcf6a19d71adffa26d93866795c7adc to your computer and use it in GitHub Desktop.
Napi::Value value;
Napi::Function dateFunc = value.Env().Global().Get("Date").As<Napi::Function>();
if (value.As<Napi::Object>().InstanceOf(dateFunc)) {
// it is a date
}
Napi::Function isIntegerFunction = value.Env().Global().Get("Number").As<Napi::Object>().Get("IsInteger").As<Napi::Function>();
bool isInt = isIntegerFunction.Call({value}).ToBoolean().Value();
double orig_val = source.As<Napi::Number>().DoubleValue();
int32_t int_val = source.As<Napi::Number>().Int32Value();
if ((int32_t)orig_val != orig_val) // or std::trunc(orig_val) == orig_val;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment