Socket
Book a DemoInstallSign in
Socket

matrix-counter

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

matrix-counter

A simple iterator for counting along a matrix that contains varied numerical bases

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

matrixcounter

A simple iterator for counting along a matrix that contains varied numerical bases.

Purpose

MatrixCounter is a simple library for iterating and counting about a matrix that contains varied numerical bases for each index. Example use cases include constructing clocks (24 hour, 12 hour, binary), creating permutations from an array of strings, or reducing measurements of smaller units to larger units.

Installation

  npm install matrix-counter

Example Usage

import MatrixCounter from '../dist/index';

const d = new Date();
const clock = new MatrixCounter(
  [24, 60, 60], //numeric base
  [d.getHours(), d.getMinutes(), d.getSeconds()] //initial state
);

const format = n => n < 10 ? '0' + n : n;

// Worth noting that using setInterval to increment a clock is a pretty horrid idea
setInterval(() => {
  if (clock.hasNext()) {
    clock.next();
  } else {
    clock.reset();
  }
  const [ hours, minutes, seconds ] = clock.peek();
  console.log(`${format(hours)}:${format(minutes)}:${format(seconds)}`);
}, 1000);

Development

  $ make dependencies # install node modules, works with yarn
  
  $ make lint # lint code
  
  $ make test # test code
  
  $ make # build code

Todo

  • Hook up travis, coveralls, and beer pay :D
  • Add more tests
  • Add better docs
  • Release

Keywords

matrix

FAQs

Package last updated on 30 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts