@cosby/native-basic-math
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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

Function Description
sum(a: number, b: number): number Returns the sum of a and b.
sub(a: number, b: number): number Returns the difference when b is subtracted from a.
mul(a: number, b: number): number Not yet implemented. Intended to return the product of a and b.
div(a: number, b: number): number Not 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.

Package Sidebar

Install

npm i @cosby/native-basic-math

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

62.7 kB

Total Files

17

Last publish

Collaborators

  • cosby