Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jscoord

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jscoord

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

  • 0.0.14
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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 :)

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)
.getMapJSON()

Get Map as Object.

coords.getMapJSON() // {x: 20, y: 0, z: 0}
.getMapArray()

Get Map as Array.

coords.getMapArray() // [x, y, z]
.getJSON()

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

coords.getJSON() // {x: 20, y: 0, z: 0}
.getArray()

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

coords.getArray() // [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)
.getRltJSON()

Get the relativity set as an object.

coords.getRltJSON() // {x: 1, y: 2, z: 3}
.getRltArray()

Get the relativity set as an array.

coords.getRltArray() // [x, y, z]

Keywords

FAQs

Package last updated on 02 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc