Skip to content

petersawm/math-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

math-utils

Simple and reliable math utility functions for JavaScript/Node.js projects.

Prerequisites

You need to authenticate with GitHub Packages. Create a .npmrc file in your project root:

@petersawm:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN

Install the package

npm install @petersawm/math-utils

Usage

import { add, subtract, multiply, divide } from '@petersawm/math-utils';

// Addition
console.log(add(5, 3));        // 8

// Subtraction
console.log(subtract(10, 4));  // 6

// Multiplication
console.log(multiply(6, 7));   // 42

// Division
console.log(divide(20, 4));    // 5

// Error handling
try {
  divide(10, 0);
} catch (error) {
  console.error(error.message); // "Cannot divide by zero"
}

API Reference

add(a, b)

Returns the sum of two numbers.

Parameters:

  • a (number): First number
  • b (number): Second number

Returns: (number) Sum of a and b

subtract(a, b)

Returns the difference of two numbers.

Parameters:

  • a (number): First number
  • b (number): Second number

Returns: (number) Difference of a and b

multiply(a, b)

Returns the product of two numbers.

Parameters:

  • a (number): First number
  • b (number): Second number

Returns: (number) Product of a and b

divide(a, b)

Returns the quotient of two numbers.

Parameters:

  • a (number): Dividend
  • b (number): Divisor

Returns: (number) Quotient of a and b

Throws: Error if divisor is zero

Development

Setup

# Clone the repository
git clone https://github.com/petersawm/math-utils.git
cd math-utils

# Install dependencies
npm install

Running Tests

npm test

Publishing

  1. Create a GitHub Personal Access Token:

    • Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
    • Click "Generate new token (classic)"
    • Select scopes: write:packages, read:packages, delete:packages
    • Copy the generated token
  2. Set your token:

export GITHUB_TOKEN=your_token_here
  1. Update .npmrc with your token:
@petersawm:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
  1. Publish the package:
npm publish

GitHub Token Setup Guide

Create Token

  1. Go to https://github.com/settings/tokens
  2. Click "Generate new token (classic)"
  3. Give it a descriptive name (e.g., "npm-packages")
  4. Select permissions:
    • write:packages
    • read:packages
    • delete:packages (optional)
  5. Click "Generate token"
  6. Copy the token immediately (you won't see it again!)

Use Token Locally

# Set as environment variable
export GITHUB_TOKEN=ghp_your_token_here

# Or add to .npmrc
echo "//npm.pkg.github.com/:_authToken=ghp_your_token_here" >> .npmrc

Use Token in CI/CD

Add GITHUB_TOKEN as a secret in your repository settings.

License

MIT

Author

Peter Sawm (@petersawm)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

Repo for use in testing github registry

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors