1.0.3 • Published 3 months ago

@cosby/native-basic-math v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Native Basic Math

This project is an example of a Native Node.js module implemented in C++ with TypeScript/JavaScript bindings. It provides basic arithmetic operations such as addition and subtraction, serving as a foundation for learning or building more complex native modules.

Installation

Using NPM

npm install @cosby/native-basic-math

Using Yarn

yarn add @cosby/native-basic-math

Using PNPM

pnpm i @cosby/native-basic-math

Usage

const math = require('@cosby/native-basic-math');

// Addition
console.log(math.sum(2, 3)); // Output: 5

// Subtraction
console.log(math.sub(5, 2)); // Output: 3

// Multiplication
console.log(math.mul(3, 4)); // Output: 12

// Division
console.log(math.div(10, 2)); // Output: 5

or

import math from '@cosby/native-basic-math';

// Addition
console.log(math.sum(2, 3)); // Output: 5

// Subtraction
console.log(math.sub(5, 2)); // Output: 3

// Multiplication
console.log(math.mul(3, 4)); // Output: 12

// Division
console.log(math.div(10, 2)); // Output: 5

API

FunctionDescription
sum(a: number, b: number): numberReturns the sum of a and b.
sub(a: number, b: number): numberReturns the difference when b is subtracted from a.
mul(a: number, b: number): numberNot yet implemented. Intended to return the product of a and b.
div(a: number, b: number): numberNot yet implemented. Intended to return the quotient when a is divided by b. Throws an error if b is 0.

Building the module

If you want to build the module from source, run:

yarn build

This will clean the environment, build the C++ native module, and compile TypeScript files.

License

This project is licensed under the MIT License. See the LICENSE file for details.

1.0.3

3 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago