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

@mitchallen/pen

v0.2.6

Published

pen object that returns drawing path information

Downloads

13

Readme

@mitchallen/pen

pen object that returns drawing path information


Installation

You must use npm 2.7.0 or higher because of the scoped package name.

$ npm init
$ npm install @mitchallen/pen --save

Usage

    "use strict";
    
	var penFactory = require("@mitchallen/pen");

	var pen = penFactory.create({ 
		color: 0xFF0000,	// red pen
		fill: 0x00FF00,		// green fill
		width: 2,			// pen width 
		alpha: 0.8			// pen alpha value
	});
	
	pen.up()
	   .goto( { x: 50, y: 50 } )	// MoveTo 50, 50
	   .down()
	   .goto( { x: 10, y: 20 } )	// LineTo 10, 20
	   .goto( { x: 15, y: 30 } )	// LineTo 15, 30
	   .goto( { x: 45, y: 60 } )	// LineTo 45, 60
	   .up()
	   .goto( { x: 30, y: 40 } )	// MoveTo 30, 40
	   .goto( { x: 10, y: 20 } )	// LineTo 10, 20
	
	var path = pen.path();

Methods

penFactory = factory.create(spec)

Factory method that returns a pen object.

It takes one spec parameter can contain optional parameters:

  • color - default if missing is 0x000000 - hex RGB color value
  • width - default if missing is 1
  • alpha - default if missing is 1.0 - valid values between 0.0 and 1.0

The method will return null if create fails, such as with bad parameters. You can call create multiple times to create multiple mazes.

var penFactory = require("@mitchallen/maze-generator");

var pen1 = penFactory.create({ 
	color: 0xFF0000,	// red pen
	width: 2,			// pen width 
	alpha: 0.8			// pen alpha value
});
var pen2 = penFactory.create( { 
	color: 0x0000FF,	// blue pen
	width: 3,			// pen width 
	alpha: 0.6			// pen alpha value
});

if(!pen1 || !pen2) ...

pen.down()

Logical pen down.

pen.down();

pen.up()

Logical pen up.

pen.up();

pen.isDown()

Returns if pen is down.

if( pen.isDown() ) ...

pen.goto( { x: number, y: number } )

Maps path drawing operation. If the pen is up it generates a MoveTo. If the pen is down it generatea a LineTo. If this is the first operation it inserts a MoveTo (0,0).

pen.up()
   .goto( { x: 50, y: 50 } )	// MoveTo 50, 50
   .down()
   .goto( { x: 10, y: 20 } )	// LineTo 10, 20
   .goto( { x: 15, y: 30 } )	// LineTo 15, 30

pen.color()

Return RGB value of pen, either default or what was passed to create method.

var color = pen.color();

pen.fill()

Return RGB value of fill color, either default or what was passed to create method.

var fill = pen.fill();

pen.width()

Return width value of pen, either default or what was passed to create method.

var width = pen.width();

pen.alpha()

Return alpha value of pen, either default or what was passed to create method.

var alpha = pen.alpha();

pen.path()

Returns drawing path info in the form of an array. The array contains a series of drawing operation objects. Each operation contains an op, x and y parameter.

var path = pen.path();

Example result:

[ { op: "M", x: 10, y: 20 }, { op: "L", x: 20, y: 30 } ]

pen.viewPort()

Loops through the path values and returns an object containing the following properties:

  • xMin - Returns minimum x position visited via goto. Rounded to a whole number.
  • yMin - Returns minimum y position visited via goto. Rounded to a whole number.
  • xMax - Returns maximum x position visited via goto. Rounded to a whole number.
  • yMax - Returns maximum y position visited via goto. Rounded to a whole number.

Example:

var vp = pen.viewPort();
console.log( "xMin: ", vp.xMin );

Testing

To test, go to the root folder and type (sans $):

$ npm test 

Repo(s)


Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.


Version History

Versoin 0.2.6

  • README and LICENSE year update

Versoin 0.2.5

  • up, down and goto now support chaining

Versoin 0.2.4

  • fill can now handle 0x000000

Version 0.2.3

  • code cleanup

Version 0.2.2

  • package dependency cleanup

Version 0.2.1

  • added fill for fill color which defaults to null (aka none)

Version 0.2.0

  • min / max methods replaced with viewPort method

Version 0.1.3

  • min / max values now rounded and compared to whole numbers

Version 0.1.2

  • fixed bug where goto returned null if x or y was zero

Version 0.1.1

  • updated description in package.json

Version 0.1.0

  • initial release