This repository has been archived on 2024-07-06. You can view files and clone it, but cannot push or open issues or pull requests.
rebory/test/main.cpp
Matheus Sampaio Queiroga 772443cc58
Some checks failed
Test / test_cross (16.x) (push) Failing after 2m15s
Test / test_cross (18.x) (push) Failing after 2m48s
Test / test_cross (19.x) (push) Failing after 2m47s
Test / test_cross (17.x) (push) Failing after 2m51s
Test / test_cross (20.x) (push) Failing after 1m34s
Test / test_cross (21.x) (push) Failing after 1m21s
Update node headers path and Builder
2024-02-24 17:59:43 -03:00

28 lines
1.1 KiB
C++

#include <napi.h>
#include "g.h"
Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports.Set("Test Date", Napi::Date::New(env, time(nullptr) * 1000));
exports.Set("Test", Napi::String::New(env, "Test obj"));
exports.Set("bigint", Napi::BigInt::New(env, (int64_t)(time(nullptr) * 1000)));
exports.Set("function", Napi::Function::New(env, [](const Napi::CallbackInfo &info) -> Napi::Value {
const Napi::Array args = Napi::Array::New(info.Env());
for (unsigned int i = 0; i < info.Length(); i++) {
const Napi::Value val = info[i];
if (val.IsString()) args.Set(i, "string");
else if (val.IsNumber()) args.Set(i, "number");
else if (val.IsBigInt()) args.Set(i, "bigint");
else if (val.IsBoolean()) args.Set(i, "bol");
else if (val.IsArray()) args.Set(i, "array");
else if (val.IsFunction()) args.Set(i, "function");
else if (val.IsObject()) args.Set(i, "object");
else if (val.IsNull()) args.Set(i, "null");
else if (val.IsUndefined()) args.Set(i, "undefined");
else args.Set(i, "unknown");
}
return args;
}));
return exports;
}
NODE_API_MODULE(addon, Init);