map connections between cells in a 2D grid


030.1.339 months ago5 years agoMinified + gzip package size for @mitchallen/connection-grid in KB



Map connections between cells in a 2D grid.


You must use npm 2.7.0 or higher because of the scoped package name.

$ npm init
$ npm install @mitchallen/connection-grid --save


"use strict";
let gridFactory = require("@mitchallen/connection-grid");
let xSize = 5;
let ySize = 6;

let grid = gridFactory.Square({ x: xSize, y: ySize });

Browser Usage:

You can reference a minimized client version inside an HTML script tag using one of these URL's:


    <!DOCTYPE html>
        <meta charset="utf-8">
        <title>Connection-Grid Example</title>
        <meta name="description" content="Connection Grid Example">
        <script src="https://unpkg.com/@mitchallen/connection-grid@0.1.33/dist/connection-grid.min.js"></script>
          var factory = window.MitchAllen.ConnectionGrid;
          var xSize = 10, ySize = 5;
          var sg = factory.Square( { x: xSize, y: ySize } );
        <h1>Connection Grid Example</h1>


To test, go to the root folder and type (sans $):

$ npm test

Run all tests using nodemon:

$ npm run test-nodemon

Run suites using nodemon:

$ npm run test-square
$ npm run test-hexagon
$ npm run test-triangle
$ npm run test-circle



In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

Version History

Version 0.1.28

  • replaced modules/square.js with @mitchallen/connection-grid-square

Version 0.1.27

  • square now uses @mitchallen/grid-square

Version 0.1.26

  • Replaced modules/base.js with @mitchallen/connection-grid-core

Version 0.1.25

  • Browser now must use window.MitchAllen.ConnectionGrid.

Version 0.1.24

  • Updated CDN URL

Version 0.1.23

  • Added client example

Version 0.1.22

  • Changed client window name to 'ConnectionGrid'

Version 0.1.21

  • Added client distribution

Version 0.1.20

  • updated to latest grid

Version 0.1.19

  • Updated documentation for connection directions
  • Removed unused code

Version 0.1.18

  • Refactored Circle.getNeighbor
  • Fixed bug in Circle.getNeighbor

Version 0.1.17

  • Add connectsAny method

Version 0.1.16

  • Cirlce.getNeighbor with CW for last cell in ring now wraps properly

Version 0.1.15

  • Added Triangle method

Version 0.1.14

  • Fixed bug in isDir
  • Fixed Circle direction mapp

Version 0.1.13

  • Refactored code base and tests

Version 0.1.12

  • Added tests for Circle

Version 0.1.11

  • Added Hexagon and Circle methods

Version 0.1.10

  • now uses @mitchallen/grid 0.1.10

Version 0.1.9

  • now uses @mitchallen/grid 0.1.9
  • changed internal use of grid.create to grid.Square
  • added Square method to replace create method
  • added test suites for Square method
  • create method now generates deprecation warning

Version 0.1.8

  • now uses @mitchallen/grid 0.1.8
  • added experimental Hexagon method

Version 0.1.7

  • now uses @mitchallen/grid 0.1.7
  • x and y values that are missing or less than 0 will be normalized to 0
  • updated tests

Version 0.1.6

  • added replaced getDirMap function with dirMap property

Version 0.1.5

  • added getOppositeDir method

Version 0.1.5

  • added getOppositeDir method

Version 0.1.4

  • added mask and isMasked methods

Version 0.1.3

  • now uses @mitchallen/grid 0.1.6

Version 0.1.2

  • added connects method

Version 0.1.1

  • fixed bug in hasConnections

Version 0.1.0

  • initial release

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.