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 🙏

© 2024 – Pkg Stats / Ryan Hefner

lib-figure-implementation

v1.1.0

Published

> lib-figure-implementation - a library that allows you to create and work with various geometric shapes. > The library architecture allows you to draw shapes in HTML using the canvas element > ## Features

Downloads

16

Readme

lib-figure-implementation

lib-figure-implementation - a library that allows you to create and work with various geometric shapes. The library architecture allows you to draw shapes in HTML using the canvas element

Features

  • Full TypeScript support
  • Support all platforms
  • Easy to use

Table of contents

Type Aliases

InitialPointType

Ƭ InitialPointType: Object

Type declaration

| Name | Type | | :------ | :------ | | x | number | | y | number |

Defined in

features/shape/coordinates-type.ts:1

Quick start

Install

First make sure that you have installed Node.js.

Next install lib-figure-implementation from the command line using yarn or npm:

yarn:

yarn add lib-figure-implementation

npm:

npm install lib-figure-implementation --save

Ready! Now you can use the lib-figure-implementation library in your project.

Examples

Example of using the library

const circle: Circle = Circle.createCircle({ x: 1190, y: 150 }, 100, 'green');
// => instance of class Circle to the variable circle

const square: Square = Square.createSquare({ x: 850, y: 50 }, 200, 'blue');
// => instance of class Square in square
 
const triangle: Triangle = Triangle.createTriangle(
  [
    { x: 550, y: 250 },
    { x: 750, y: 250 },
    { x: 650, y: 50 }
  ],
  'black'
);
// => instance of class Triangle to the variable triangle

const rectangle: Rectangle = Rectangle.createRectangle({ x: 150, y: 50 }, 350, 200, 'red');
// => instance of class Rectangle to the variable rectangle

circle.area()
// => circle area value

circle.perimeter()
// => circle perimeter value

circle.draw()
// => draw circle in canvas

rectangle.area()
// => rectangle area value

triangle.area()
// => triangle area value

circle.changeColor("white")
// => change line color of circle

Instructions for drawing shapes using canvas

Initialize your project with the command:

yarn init --yes

You need to add the following dependencies to your project:

yarn add typescript @types/node webpack ts-loader webpack-cli lib-figure-implementation 

Create a tsconfig.json in the root of the project directory and paste the following code snippet:

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "rootDir": "./src",
    "declaration": true,
    "sourceMap": false,
    "outDir": "./dist",
    "noEmit": false,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true, 
    "skipLibCheck": true,
    "allowJs": false
  },
  "include": ["src/index.ts"],
  "exclude": ["node_modules"]
}

Add the script to the package.json to run webpack:

{
  "scripts": {
    "dev": "webpack --config webpack.config.js"
  }

Create a webpack.config.js at the root of the project and paste the following code snippet:

module.exports = {
    entry: ["entry point of your project"],
    output: {
        filename: 'filename-of-final-bundle.js in your project',
        path: __dirname + '/dist'
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js'] // allow importing TypeScript files
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/
            }
        ]
    },
    mode: "development",
};

Create index.html file with this simple structure:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Canvas</title>
        <script src="/dist/bundle.js(--path to your bundle file--)"></script>
  </head>
    <body>
      <canvas id="myCanvas" width="1300" height="1000"> </canvas>
    </body>
</html>

Create an index.ts file where you can create shapes using the lib-figure-implementation library, for example:

const circle: Circle = Circle.createCircle({ x: 1190, y: 150 }, 100, 'green');

const square: Square = Square.createSquare({ x: 850, y: 50 }, 200, 'blue');

const triangle: Triangle = Triangle.createTriangle(
    [
        { x: 550, y: 250 },
        { x: 750, y: 250 },
        { x: 650, y: 50 }
    ],
    'black'
);

const rectangle: Rectangle = Rectangle.createRectangle({ x: 150, y: 50 }, 350, 200, 'red');

window.onload = () => {
    const canvas = document.getElementById('myCanvas') as HTMLCanvasElement;
    const ctx = canvas.getContext('2d');
    square.draw(ctx as CanvasRenderingContext2D);
    triangle.draw(ctx as CanvasRenderingContext2D);
    rectangle.draw(ctx as CanvasRenderingContext2D);
    circle.draw(ctx as CanvasRenderingContext2D);
};

Run the following command to start webpack:

yarn dev 

Open index.html file in the browser.

Congratulations, you have built the necessary figures!