# @blade67/gridmatrix

> 2D Grid Matrix

Latest version **1.1.1** (published 2020-05-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install @blade67/gridmatrix
pnpm add @blade67/gridmatrix
yarn add @blade67/gridmatrix
bun add @blade67/gridmatrix
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2020-05-29 |
| First published | 2020-05-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maxime "Blade" Gabel |
| Maintainers | blade67 |
| Keywords | Grid, Matrix, 2D |

## Links

- npm: https://www.npmjs.com/package/@blade67/gridmatrix
- Repository: https://github.com/Blade67/GridMatrix
- Homepage: https://github.com/Blade67/GridMatrix#readme
- Issues: https://github.com/Blade67/GridMatrix/issues
- npm.io page: https://npm.io/package/@blade67/gridmatrix

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2020-05-29
- 1.1.0 — 2020-05-29
- 1.0.0 — 2020-05-27

## README

# **GridMatrix**

A simplified solution for 2D Arrays, Grids, Matrices or whatever you want to call them!

**Disclaimer**: This module was designed in a non-destructive way, meaning that if anything goes wrong, it tries to return `undefined` instead of an error. (if possible)

In case of issues or suggestions, please open an issue on the Github Repo: https://github.com/Blade67/GridMatrix

A minified version as also available for browser usage [here](https://github.com/Blade67/GridMatrix/blob/master/index.min.js).

## **Installation**

```
npm i @blade67/gridmatrix
```

## **Setup**

```js
const GridMatrix = require("@blade67/gridmatrix");

let grid = new GridMatrix({ width: 2, height: 2 });
// Output: [[null, null], [null, null]]
```

## **API**

## Propperties

-   **size**
    ```js
    <GridMatrix>.size
    // Output: { x: 2, y: 2}
    ```
-   **width**
    ```js
    <GridMatrix>.width
    // Output: 2
    ```
-   **height**
    ```js
    <GridMatrix>.height
    // Output: 2
    ```
-   **data**
    ```js
    <GridMatrix>.data
    // Output: [[null, null], [null, null]]
    ```
-   **options**
    ```js
    <GridMatrix>.options
    // Output: { allowOverflow: true, defaultValue: null }
    ```
-   **Directions** (Enum/Object: `{ North: 0, NorthEast: 1, East: 2, SouthEast: 3, South: 4, SouthWest: 5, West: 6, NorthWest: 7,

    ````js
    <GridMatrix>.Directions
    // Output: {
    // North: 0,
    // NorthEast: 1,
    // East: 2,
    // SouthEast: 3,
    // South: 4,
    // SouthWest: 5,
    // West: 6,
    // NorthWest: 7,
    // }

        <GridMatrix>.Directions.North
        // Output: 0
        ```

    }`)
    ````

## Methods

-   **setData**
    ```js
    <GridMatrix>.setData({ x: 0, y: 0}, "Node 0-0");
    // Output: "Node 0-0"
    ```
-   **getData**
    ```js
    <GridMatrix>.getData({ x: 0, y: 0});
    // Output: "Node 0-0"
    ```
-   **toArray**
    ```js
    <GridMatrix>.toArray();
    // Output: ["Node 0-0", null, null, null]
    ```
-   **getNeighbour**
    ```js
    <GridMatrix>.getNeighbour({ x: 0, y: 1 }, <GridMatrix>.Directions.North);
    // Output: "Node 0-0"
    ```
-   **getNext**
    ```js
    <GridMatrix>.getNext({ x: 1, y: 1 }, { wrap: true });
    // Output: "Node 0-0"
    // Output (wrap: false): undefined
    ```
-   **getPrevious**
    ```js
    <GridMatrix>.getPrevious({ x: 0, y: 0 }, { wrap: true });
    // Output: null
    // Output (wrap: false): undefined
    ```
-   **swap**
    ```js
    <GridMatrix>.swap({ x: 0, y: 0 }, { x: 1, y: 1 });
    // Output: [[null, null],[null, "Node 0-0"]]
    ```
-   **addRowBefore**
    ```js
    <GridMatrix>.addRowBefore(["a", "b"]);
    // Output: [["a", "b"],[null, null],[null, "Node 0-0"]]
    ```
-   **addRowAfter**
    ```js
    <GridMatrix>.addRowAfter(["a", "b"]);
    // Output: [[null, null],[null, "Node 0-0"],["a", "b"]]
    ```
-   **removeRow**
    ```js
    <GridMatrix>.removeRow(1);
    // Output: [[null, null],["a", "b"]]
    ```
-   **addColumnBefore**
    ```js
    <GridMatrix>.addColumnBefore(["a", "b"]);
    // Ouput: [["a", null, null],["b", null, "Node 0-0"]]
    ```
-   **addColumnAfter**
    ```js
    <GridMatrix>.addColumnAfter(["a", "b"]);
    // Ouput: [[null, null, "a"],[null, "Node 0-0", "b"]]
    ```
-   **removeColumn**
    ```js
    <GridMatrix>.removeColumn(2);
    // Output: [[null, null],[null, "Node 0-0"]]
    ```

---
_Source: https://npm.io/package/@blade67/gridmatrix · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
