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

jscoord

v1.2.0

Published

A simple Map coordinate system for NodeJS and potentially the browser.

Downloads

6

Readme

JSCoord

JSCoord is a simple coordinate and map system for JS. It provides a simple API for manipulating coordinates and setting maps(limits).

JSCoord's Website. Also contains documentation :)

NPM

Basic Usage

Install JSCoord using NPM:

npm i jscoord --save

Once its installed, you can import it into your application by adding this to the top of the script:

const { JSCoord } = require("jscoord")

Or if you use Typescript/Webpack:

import JSCoord from "jscoord";

Then, to create a new JSCoord instance, use:

let coords = new JSCoord(x, y, z)

And there you have it! coords will be a new JSCoords instance. You can now mutate it using the provided methods.

Properties

.x, .y, .z

Get X, Y or Z value. Do NOT modify these variables, they can break your coordinate set.

coords.x

Methods

JSCoord provides some basic mutation methods. They can be used to modify the coordinate set in different ways.

.incrX(amount), .incrY(amount), .incrZ(amount)

Increments the specified axis by amount. If amount parameter is not provided, increments by 1.

coords.incrX(10)

.decrX(amount), .decrY(amount), .decrZ(amount)

Decrements the specified axis by amount. If amount parameter is not provided, decrements by 1.

coords.decrX(10)

.setX(val), .setY(val), .setZ(val)

Sets the axis value to val.

coords.setX(20)

.invX(), .invY(), .invZ()

"Inverts" the number, so it becomes its negative/positive version. 3 becomes -3, -3 becomes 3 and so on.

coords.invX()

.setMap(x, y, z)

Sets the maximum range for each axis. It sets the maximum to the provided number and the minimum to the negative of the provided number. Other methods will fail if they are out of range. This will fail if axis is above limit already.

coords.setMap(100, 100, 100)

.mapJSON

Get Map as Object.

coords.mapJSON // {x: 20, y: 0, z: 0}

.mapArray

Get Map as Array.

coords.mapArray // [x, y, z]

.JSON

Returns the X, Y and Z axis values as an object.

coords.JSON // {x: 20, y: 0, z: 0}

.array

Returns the X, Y and Z axis values as an array. .array[0] contains the X axis, .array[1] the Y axis and .array[2] the Z axis.

coords.array // [x, y, z]

.reset()

Resets all of the X, Y and Z values to 0.

coords.reset()

.rlt(x, y, z)

Set the relativity of the current coordinates from the provided coordinate set perpective.

coords.rlt(10, 20, 30)

.rltJSON

Get the relativity set as an object.

coords.rltJSON // {x: 1, y: 2, z: 3}

.rltArray

Get the relativity set as an array.

coords.rltArray // [x, y, z]

.getRltAngle(set)

Get the angle of 2 coordinate set values. set is the 2 axies which should be used for calculation, can be xy, yz or zx.

coords.getRltAngle("xy")

CoordChunk

CoordChunk is another feature of JSCoord. Its basically an Array of Sets with some extra functions. When creating a CoordChunk instance, you can pass a parameter to set the maximum size of the set.

const { CoordChunk } = require("jscoord")

Or if you use Typescript/Webpack:

import { CoordChunk } from "jscoord";

Then, to create a new instance:

let chunk = new CoordChunk(10)

Properties

.limit

Maximum length of chunk. Do NOT modify this variable, it can break your coordinate set.

chunk.limit

.sets

Array in which Sets are stored. Do NOT modify this variable, it can break your coordinate set.

chunk.sets

Methods

.addSet(coords)

Add a Set to the Chunk. coords can be an Array with coordinate values ([x, y, z]) or a JSCoord instance. You can not have 2 of the same coordinate sets in the same chunk.

chunk.addSet(new JSCoord(100, 100, 100))

.getSet(coords)

Find a Set by coordinates. Throws if Set could not be found.

chunk.getSet([100, 100, 100])

.delSet(coords)

Delete a Set from the Chunk. coords can be an Array with coordinate values or a JSCoord instance. Throws if Set could not be found.

chunk.delSet([100, 100, 100])