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

array-2d-js

v1.0.1

Published

Array2D is an auxiliary tool to create, manage and manipulate 2d arrays.

Downloads

9

Readme

Array2D

Array2D is an auxiliary tool to create, manage and manipulate 2d arrays. I made this component to help me develop board game prototypes. If you want to use this component, please! If you want to modify or expand this component, you are welcome to do so. See notes in contribution.

Installation

$ npm i Array2D --save

Usage

import Array2D from 'array-2d-js'

export default class Map extends Array2D {
  constructor (width, height) {
    super(width, height)
  }
}

or

import Array2D from 'array-2d-js'

const array2D = new Array2D(10, 10)

or

const Array2D = require("array-2d-js")

const array2D = new Array2D(10, 10)

API

constructor

Intitialize Array2D class.

Parameters

  • width Number Number corresponding with the width(column count) of the 2d array.
  • height Number Number corresponding with the height(row count) of the 2d array.

getColumn

Return the column of the given position.

Parameters

  • position Number Position for the column.

Returns Array Returns the column.

addColumn

Add the column at the given position.

Parameters

  • position Number Position for the column.

removeColumn

Remove the column at the given position.

Parameters

  • position Number Position for the column.

fillColumn

Executes the provided function once for each array element for column at given position.

Parameters

  • position Number Position for the column.
  • f function Fill function for the column.

clearColumn

Clear the column at the given position.

Parameters

  • position Number Position for the column.

condenseColumns

Condense the 2d array to the minimum by removing all the empty columns on the outside. This process is irreversible.

getRow

Get the row of the given position.

Parameters

  • position Number Position for the row.

Returns Array Returns the row.

addRow

Add the row at the given position.

Parameters

  • position Number Position for the row.

removeRow

Remove the row at the given position.

Parameters

  • position Number Position for the row.

fillRow

Executes the provided function once for each array element for row at given position.

Parameters

  • position Number Position for the row.
  • f function Fill function for the row.

clearRow

Clear the row at the given position.

Parameters

  • position Number Position for the row.

condenseRows

Condense the 2d array to the minimum by removing all the empty rows on the outside. This process is irreversible.

getPosition

Get the item of the given position.

Parameters

  • x Number Column position for in the 2d array.
  • y Number Row position for in the 2d array.

Returns any Returns the item.

fillPosition

Fill position with item

Parameters

  • x Number Column position for in the 2d array.
  • y Number Row position for in the 2d array.
  • item any Item for in the 2d array.

clearPosition

Clear given position

Parameters

  • x Number Column position for in the 2d array.
  • y Number Row position for in the 2d array.

findPosition

Find the postion for given item

Parameters

  • item any Item for which you want to find the position.

Returns any Item position.

forEach

Executes a provided function once for each 2d array element.

Parameters

  • f function Fill function for the 2d array.

condense

Condense the 2d array to the minimum by removing all the empty rows and columns on the outside. This process is irreversible.

array2D

Returns the 2d array.

Returns Array2D Returns the 2d array.

width

return the width(column count) of the 2d array.

Returns Number Returns the width of the 2d array.

height

return the height(row count) of the 2d array.

Returns Number Returns the height of the 2d array.

Contributing

Issues are welcome. The best way to report a problem is to reproduce it with a code example.

Pull requests are welcome. If you want to change the API, it's better to discuss it using an issue ticket.

License

Array2D is MIT licensed.