npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

shapeworkerjs

v1.0.0

Published

​A comprehensive JavaScript library for 2D and 3D geometric calculations (area, perimeter, volume, surface area).

Downloads

4

Readme

#shapeworkerjs A lightweight JavaScript geometry library for working with 2D and 3D shapes. Built with clean, class-based implementations and designed for developers who need accurate geometric calculations in their projects.

Table of Contents

  • Features
  • Installation
  • Quick Start
  • API Reference
    • 2D Shapes
    • 3D Shapes
    • Utility Shapes
  • Contributing
  • Author
  • License

Features

  • Simple API – Each shape is represented as a class with intuitive methods.
  • 2D Shapes – Square, Rectangle, Circle, Parallelogram, Triangle, Trapezium.
  • 3D Shapes – Sphere, Cylinder, Cube, Cuboid, Cone, Prism.
  • Accurate Math – Uses standard mathematical constants and trigonometric functions.
  • Lightweight & Fast – No external dependencies.

Installation

Install the package using NPM: npm install shapeworkerjs

Usage

ES Modules (Recommended)

import { Square, Sphere, Cone } from 'shapeworkerjs';

CommonJS (Node.js)

const { Square, Sphere, Cone } = require('shapeworkerjs');

Quick Start

// Example using ES Modules
import { Square, Sphere } from 'shapeworkerjs';

// Create a 2D Square
const square = new Square(5);
console.log(`Square Area: ${square.area()}`);       // Output: 25
console.log(`Square Perimeter: ${square.perimeter()}`);  // Output: 20

// Create a 3D Sphere
const sphere = new Sphere(3);
console.log(`Sphere Volume: ${sphere.volume()}`);     // Output: 113.097...
console.log(`Sphere Surface Area: ${sphere.surfaceArea()}`); // Output: 113.097...

API Reference

2D Shapes

Square

A shape with four equal sides. | Method | Description | Example Usage | |---|---|---| | constructor(x) | Initializes with side length x. | new Square(5) | | perimeter() | Calculates the perimeter (4 \times \text{side}). | square.perimeter() | | area() | Calculates the area (\text{side}^2). | square.area() |

Rectangle

A shape with four right angles and opposite sides of equal length. | Method | Description | Example Usage | |---|---|---| | constructor(x, y) | Initializes with side lengths x and y. | new Rectangle(4, 6) | | perimeter() | Calculates the perimeter (2 \times (x + y)). | rectangle.perimeter() | | area() | Calculates the area (x \times y). | rectangle.area() |

Circle

A round plane figure defined by its radius. | Method | Description | Example Usage | |---|---|---| | constructor(x) | Initializes with radius x. | new Circle(3) | | circumference() | Calculates the circumference (2 \pi r). | circle.circumference() | | area() | Calculates the area (\pi r^2). | circle.area() |

Parallelogram

A four-sided figure with opposite sides parallel. | Method | Description | Example Usage | |---|---|---| | constructor(x, y, param3) | Initializes with adjacent sides x and y. param3 is height (h) (number) or angle (string, e.g., "30deg"). | new Parallelogram(8, 5, "30deg") | | perimeter() | Calculates the perimeter (2 \times (x + y)). | parallelogram.perimeter() | | area() | Calculates the area (x \times h or x \times y \times \sin(\theta)). | parallelogram.area() |

Triangle

A three-sided figure. | Method | Description | Example Usage | |---|---|---| | constructor(a, b, param3) | Initializes with side a and side/base b. param3 is height (h) (number) or angle (string, e.g., "45deg") between a and b. | new Triangle(10, 6, 4) | | perimeter() | Returns a placeholder string due to ambiguity of side lengths. | triangle.perimeter() | | area() | Calculates the area (0.5 \times b \times h or 0.5 \times a \times b \times \sin(\theta)). | triangle.area() |

Trapezium (Trapezoid)

A quadrilateral with at least one pair of parallel sides. | Method | Description | Example Usage | |---|---|---| | constructor(a, b, h) | Initializes with parallel sides a, b and height h. | new Trapezium(5, 10, 4) | | perimeter() | Returns a placeholder string due to ambiguity of non-parallel sides. | trapezium.perimeter() | | area() | Calculates the area (0.5 \times (a + b) \times h). | trapezium.area() |

3D Shapes

Sphere

A perfectly round three-dimensional object. | Method | Description | Example Usage | |---|---|---| | constructor(x) | Initializes with radius x. | new Sphere(5) | | surfaceArea() | Calculates the surface area (4 \pi r^2). | sphere.surfaceArea() | | volume() | Calculates the volume (\frac{4}{3} \pi r^3). | sphere.volume() |

Cylinder

A geometric shape with two parallel circular bases and a curved surface. | Method | Description | Example Usage | |---|---|---| | constructor(r, h) | Initializes with base radius r and height h. | new Cylinder(3, 7) | | surfaceArea() | Calculates the total surface area (2\pi r(h+r)). | cylinder.surfaceArea() | | volume() | Calculates the volume (\pi r^2 h). | cylinder.volume() |

Cube

A symmetrical 3D shape contained by six equal squares. | Method | Description | Example Usage | |---|---|---| | constructor(x) | Initializes with side length x. | new Cube(4) | | surfaceArea() | Calculates the surface area (6 \times \text{side}^2). | cube.surfaceArea() | | volume() | Calculates the volume (\text{side}^3). | cube.volume() |

Cuboid

A box-shaped object whose faces are all rectangles. | Method | Description | Example Usage | |---|---|---| | constructor(x, y, z) | Initializes with side lengths x, y, and ` z$. | new Cuboid(2, 3, 4) |

Cone

A shape that tapers from a circular base to a point (apex). | Method | Description | Example Usage | |---|---|---| | constructor(r, h) | Initializes with base radius r and height h. | new Cone(3, 8) | | surfaceArea() | Calculates the total surface area (\pi r (r + \sqrt{r^2 + h^2})). | cone.surfaceArea() | | volume() | Calculates the volume (\frac{1}{3} \pi r^2 h). | cone.volume() |

Utility Shapes

Prism

A solid figure whose two end faces are similar and parallel bases. | Method | Description | Example Usage | |---|---|---| | constructor(BaseArea, h) | Initializes with the \text{BaseArea} and height h. | new Prism(20, 5) | | surfaceArea() | Returns a placeholder string due to varying lateral faces. | prism.surfaceArea() | | volume() | Calculates the volume (\text{BaseArea} \times h). | prism.volume() |

Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests. Development Setup

  • Clone the repository.
  • Submit your improvements via pull request.

Author

Raji Mahmud A.

License

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


Built with ❤️ for developers who need reliable geometry calculations in JavaScript.