:package: cpp-npm-package-boilerplate
A boilerplate for creating a C++ npm package
Report Bug
Request Feature
Systems on which it has been tested:
Did you like the project? Please, considerate a donation to help improve!
A boilerplate for creating a C++ npm package✨
Getting started
![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=hebertcisco_cpp-npm-package-boilerplate&metric=vulnerabilities)
![codecov](https://codecov.io/gh/hebertcisco/cpp-npm-package-boilerplate/branch/main/graph/badge.svg?token=3N411UTGD2)
![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=hebertcisco_cpp-npm-package-boilerplate&metric=code_smells)
![Node.js build and publish package](https://github.com/hebertcisco/cpp-npm-package-boilerplate/actions/workflows/npm-publish.yml/badge.svg)
![Bugs](https://sonarcloud.io/api/project_badges/measure?project=hebertcisco_cpp-npm-package-boilerplate&metric=bugs)
![C++](https://img.shields.io/badge/C++-00599C?style=flat&logo=c%2B%2B&logoColor=white)
![GitHub Actions](https://img.shields.io/badge/github%20actions-%232671E5.svg?style=flat&logo=githubactions&logoColor=white)
Installation(Example purposes)
Install with yarn or npm: yarn
or npm
:
yarn add cpp-npm-package-boilerplate
npm i cpp-npm-package-boilerplate --save
Usage example
import { helloNative } from 'cpp-npm-package-boilerplate';
helloNative('World');
Note: This is example is a binding of the C++ function helloNative
to the JavaScript function helloNative
.
C++ function
#include <napi.h>
Napi::String hello(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::String name = info[0].As<Napi::String>();
return Napi::String::New(env, "Hello " + name.Utf8Value());
}
Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "hello"), Napi::Function::New(env, hello));
return exports;
}
NODE_API_MODULE(hello, Init)
JavaScript function
import bindings from 'bindings';
export const helloNative = bindings('hello.node').hello;
TypeScript implementation
import bindings from 'bindings';
type THelloNative = (string: string) => string;
export const helloNative: THelloNative = bindings('hello.node').hello;
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
Or buy me a coffee 🙌🏾
📝 License
Copyright © 2022 Hebert F Barros.
This project is MIT licensed.