Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mod-loop

hughsk50MIT0.0.2

A workaround for using negative numbers with JS's modulo operator

modulus, negative, numbers

readme

mod-loop

JavaScript's modulo operator (%) doesn't handle negative numbers nicely - here's something general to work around the issue.

Installation

npm install mod-loop

Usage

require('mod-loop')(x, y)

Returns x % y, for both positive and negative and negative numbers.

var mod = require('mod-loop')

mod(+100, 10) // 0
mod(-100, 10) // 0
mod(-105, 10) // 5
mod(-102, 10) // 8