Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: IE support #6

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dist/percent-round.esm.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/**
* percent-round
* Generated: 2021-01-26
* Generated: 2021-04-29
* Version: 2.2.0
* Copyright 2020 Vivien Anglesio
* License : MIT
*/

function percentRound(ipt, precision = 0) {
function percentRound(ipt, precision) {
if (!precision) {
precision = 0;
}
if (!Array.isArray(ipt)) {
throw new Error('percentRound input should be an Array');
}
Expand Down
7 changes: 5 additions & 2 deletions dist/percent-round.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* percent-round
* Generated: 2021-01-26
* Generated: 2021-04-29
* Version: 2.2.0
* Copyright 2020 Vivien Anglesio
* License : MIT
Expand All @@ -12,7 +12,10 @@
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.percentRound = factory());
}(this, (function () { 'use strict';

function percentRound(ipt, precision = 0) {
function percentRound(ipt, precision) {
if (!precision) {
precision = 0;
}
if (!Array.isArray(ipt)) {
throw new Error('percentRound input should be an Array');
}
Expand Down
4 changes: 2 additions & 2 deletions dist/percent-round.min.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* percent-round
* Generated: 2021-01-26
* Generated: 2021-04-29
* Version: 2.2.0
* Copyright 2020 Vivien Anglesio
* License : MIT
*/

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).percentRound=t()}(this,(function(){"use strict";function e(e,t=0){if(!Array.isArray(e))throw new Error("percentRound input should be an Array");const n=e.slice(),r=e.length,o=new Array(r);let f=0;for(let e=r-1;e>=0;e--)"string"==typeof n[e]&&(n[e]=Number.parseFloat(n[e])),f+=1*n[e];if(isNaN(f))throw new Error("percentRound invalid input");if(0===f)o.fill(0);else{const e=Math.pow(10,t);let i=0;for(let t=r-1;t>=0;t--)n[t]=100*n[t]/f,i+=o[t]=Math.round(n[t]*e)/e;if(100!==i){const t=i-100,f=1/e;let l=Math.round(Math.abs(t/f));const a=new Array(r);for(let e=0;e<r;e++)a[e]=Math.abs(o[e]-n[e]);for(;l>0;){let e=0,t=a[0];for(let n=1;n<r;n++)t<a[n]&&(e=n,t=a[n]);i>100?o[e]-=f:o[e]+=f,a[e]-=f,l--}}}return o}return e.default=e,e}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).percentRound=t()}(this,(function(){"use strict";function e(e,t){if(t||(t=0),!Array.isArray(e))throw new Error("percentRound input should be an Array");const n=e.slice(),r=e.length,o=new Array(r);let f=0;for(let e=r-1;e>=0;e--)"string"==typeof n[e]&&(n[e]=Number.parseFloat(n[e])),f+=1*n[e];if(isNaN(f))throw new Error("percentRound invalid input");if(0===f)o.fill(0);else{const e=Math.pow(10,t);let i=0;for(let t=r-1;t>=0;t--)n[t]=100*n[t]/f,i+=o[t]=Math.round(n[t]*e)/e;if(100!==i){const t=i-100,f=1/e;let l=Math.round(Math.abs(t/f));const a=new Array(r);for(let e=0;e<r;e++)a[e]=Math.abs(o[e]-n[e]);for(;l>0;){let e=0,t=a[0];for(let n=1;n<r;n++)t<a[n]&&(e=n,t=a[n]);i>100?o[e]-=f:o[e]+=f,a[e]-=f,l--}}}return o}return e.default=e,e}));
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export default function percentRound(ipt, precision = 0) {
export default function percentRound(ipt, precision) {
if (!precision) {
precision = 0;
}
if (!Array.isArray(ipt)) {
throw new Error('percentRound input should be an Array');
}
Expand Down