# grid-fns

> Functions for working with Grids

Latest version **0.0.1** (published 2023-12-10) · CC0-1.0 license · 0 weekly downloads

## Install

```sh
npm install grid-fns
pnpm add grid-fns
yarn add grid-fns
bun add grid-fns
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2023-12-10 |
| First published | 2023-12-10 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Daniel J. Dufour |
| Maintainers | danieljdufour |
| Keywords | grid, snap, unsnap |

## Links

- npm: https://www.npmjs.com/package/grid-fns
- Repository: https://github.com/DanielJDufour/grid-fns
- Homepage: https://github.com/DanielJDufour/grid-fns#readme
- Issues: https://github.com/DanielJDufour/grid-fns/issues
- npm.io page: https://npm.io/package/grid-fns

## 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

- 0.0.1 (latest) — 2023-12-10

## README

# grid-fns
Functions for working with Grids

## install
```sh
npm install grid-fns
```

## functions
- [calc_cell_size](#calc_cell_size)
- [prepare_snap](#prepare_snap)
- [prepare_unsnap](#prepare_unsnap)

## usage
### calc_cell_size
```js
import calc_cell_size from "grid-fns/calc_cell_size.js"

calc_cell_size([-180, -90, 180, 90], [1024, 768])
[0.3515625, 0.234375] // [cell width, cell height]
```

### prepare_snap
Snap a grid point to a cell and return the cell's id.
```js
import prepare_snap from "grid-fns/prepare_snap.js"

const snap = prepare_snap({ bbox: [-180, -90, 180, 90], size: [1024, 768] })

snap(-180, 90) // top-left corner
0

snap(180, 90) // top-right corner
1024

snap(179.999999999, -89.9999999999) // bottom-right cell
786431
```

### prepare_unsnap
Creates a function that returns a coordinate for a given cell id
```js
const unsnap = prepare_unsnap({ bbox: [-180, -90, 180, 90], size: [1024, 768] })
unsnap(0);
[-179.82421875, 89.8828125] // center of top-left cell

unsnap(1024)
[-179.82421875, 89.6484375] // center of top-right cell
```

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