ffg-utils
v1.0.1
Published
Simple utilities for speedy coding.
Downloads
3
Readme
input()
Gets input from the user
| type | name | description | | ------ | -------- | -------------------------------- | | string | question | Statement in front of the cursor |
Example
const {input} = require("ffg-utils");
input("How was your day? ").then(ans => { /* Stuff to do */ });
random()
Returns a random number between two values
| type | name | description | | ------ | -------- | ------------------------------------ | | Number | minimum | Minimum number of random (inclusive) | | Number | maximum | Maximum number of random (exclusive) |
Example
// Random number between 10 and 20
const {random} = require("ffg-utils");
var _num = random(10, 20);
choose()
Chooses a random value from arguments
| type | name | description | | -------- | -------- | ------------------------------------ | | anything | args... | Minimum number of random (inclusive) |
Example
// Chooses from arguments
const {choose} = require("ffg-utils");
var _foo = choose("Hello", "World", "!");
Grid
Grid object
Methods
| name | arguments | description | | ------------- | ---------------- | ---------------------------------------------------------- | | constructor | w, h, defaultval | Width, height and default value of all grid cells | | entry | x, y | Returns entry at grid (x, y) position | | value | x, y, ?val | Returns value at grid (x, y) position, value sets position | | swap | x1, y1, x2, y2 | Swaps two grid cells | | move | x, y, xinc, yinc | Increases given cell position by xinc and yinc |
Static methods
| name | arguments | description | | ------- | ----------------------- | ----------------------------------------------------------- | | fetch | index | Returns Grid from Grid.GRIDS at index | | entry | index, x, y | Returns entry at grid (x, y) position | | value | index, x, y, ?val | Returns value at grid (x, y) position, value sets position | | swap | index, x1, y1, x2, y2 | Swaps two grid cells | | move | index, x, y, xinc, yinc | Increases given cell position by xinc and yinc | | release | index | Sets the grid at index in Grid.GRIDS to null |
Variables
| type | name | description | | -------- | -------- | ------------------------------- | | Number | width | Width of grid | | Number | height | Height of grid | | Object | entries | Array of all grid cells | | Number | id | Index of the grid in Grid.GRIDS |
Static variables
| type | name | description | | -------- | ------ | ------------------------- | | Number | COUNT | Next index of Grid.GRIDS | | Object | GRIDS | Array of all Grids | | Number | SIZE | Length of Grid.GRIDS |
Example
// Create a 3x3 grid with default value 'apple'
const {Grid} = require("ffg-utils");
var _grid = new Grid(3, 3, "apple");
Vector
Vector object
Methods
| name | arguments | description | | ------------- | ---------------- | -------------------------------------- | | constructor | ?x, ?y, ?z | Creates a vector of x, y, and z (all optional, 0 by default) | | add | a | Adds a Number or Vector to this | | sub | a | Subtracts a Number or Vector from this | | mult | a | Multiplies a Number or Vector by this | | div | a | Divides this by a Number or Vector |
Static methods
| name | arguments | description | | ------ | --------- | ------------------------------------- | | fetch | index | Returns Vector from Vector.VECTORS at index | | release | index | Sets Vector.VECTORS at index to null | | add | index, a | Adds a Number or Vector to index at Vector.VECTORS | | sub | index, a | Subtracts a Number or Vector from index at Vector.VECTORS | | mult | index, a | Multiplies a Number or Vector by index at Vector.VECTORS | | div | index, a | Divides index at Vector.VECTORS by a Number or Vector |
Variables
| type | name | description | | -------- | -------- | ----------------------- | | Number | x | Value of x | | Number | y | Value of y | | Number | z | Value of z |
Static variables
| type | name | description | | -------- | -------- | ----------------------- | | Number | COUNT | Next index of Vector.VECTORS | | Object | VECTORS | Array of all Vectos | | Number | SIZE | Length of Vector.VECTORS |
Example
// Create a vector of (3, 5, 0)
const {Vector} = require("ffg-utils");
var _vec2 = new Vector(3, 5);