Package Exports
- pad-ratio
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pad-ratio) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
pad-ratio
Pad or trim an array to sum up to a maximum value
Installing
Via NPM:
npm install pad-ratioUsage
// Node CommonJS
const padRatio = require('pad-ratio');
// Or Node ES6
import padRatio from 'pad-ratio';<!-- Or in the Browser -->
<script src="pad-ratio/dist/index.js"></script>Examples
padRatio([20, 30]); // [ 20, 30, 50 ]
padRatio([20, 30], 100); // [ 20, 30, 50 ]API
padRatio(array[, maximum[, options])
array: <HybridInput>maximum: <number> Default: 100options: <PadOptions>
Parse and pad array appending or trimming it till it's contents sum up to maximum. Operative controls go within the options object.
HybridInput: string|number|number[]
If HybridInput is a string, the value separators can be any of ,, :, ;, |.
PadOptions: Object
blot: <boolean> Whether or not to blot out indexes of zero values within the result array. Default:false
padRatio([-5, 8, 33, 0, 8, -44, 33], 100, {blot: true})
// [ 8, 33, 8, 33, 18 ]
padRatio([-5, 8, 33, 0, 8, -44, 33], 100, {blot: false})
// [ 0, 8, 33, 0, 8, 0, 33, 18 ]fixed: <number> Maximum number of digits after any decimal point within the array. Default:20
padRatio([3.54645, 28.83898755], 100, {fixed: 5})
// [ 3.54645, 28.83899, 67.61456 ]append: <boolean> Whether or not to append the top up value to array or to increment the delta to the last index of the array. Default:true
padRatio([20, 30, 40], 100, {append: true})
// [ 20, 30, 40, 10 ]
padRatio([20, 30, 40], 100, {append: false})
// [ 20, 30, 50 ]Development
Building
Feel free to clone, use in adherance to the license and perhaps send pull requests
git clone https://github.com/miraclx/pad-ratio.git
cd pad-ratio
npm install
# hack on code
npm test
npm run buildTesting
Tests are executed with Jest. To use it, simple run npm install, it will install
Jest and its dependencies in your project's node_modules directory followed by npm run build and finally npm test.
To run the tests:
npm install
npm run build
npm testLicense
Apache 2.0 © Miraculous Owonubi (@miraclx) <omiraculous@gmail.com>
