@monterosa/sdk-interact-kit 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { login as login$1, getConnect as getConnect$1, disconnect, unsubscribe as unsubscribe$1, send, ConnState, connect, subscribe as subscribe$1, onConnected } from '@monterosa/sdk-connect-kit';
2
- import { Emitter, memoizePromise, subscribe as subscribe$2, now, onTick, checkAvailability, setItem, getItem, createError } from '@monterosa/sdk-util';
2
+ import { Emitter, memoizePromise, subscribe as subscribe$2, now, onTick, checkAvailability, calculatePercentage, setItem, getItem, createError } from '@monterosa/sdk-util';
3
3
  import { getSdk } from '@monterosa/sdk-core';
4
4
 
5
5
  /*! *****************************************************************************
@@ -2175,57 +2175,6 @@ var ElementImpl = /** @class */ (function (_super) {
2175
2175
  return ElementImpl;
2176
2176
  }(Emitter));
2177
2177
 
2178
- /**
2179
- * @license
2180
- * calculate_percentage.ts
2181
- * interact-kit
2182
- *
2183
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-07
2184
- * Copyright © 2022 Monterosa. All rights reserved.
2185
- *
2186
- * More details on the license can be found at https://www.monterosa.co/sdk/license
2187
- */
2188
- var calculatePercentage = function (values) {
2189
- // Calculate sum of all votes
2190
- var sum = values.reduce(function (memo, value) { return memo + value; }, 0);
2191
- // create array of hashes
2192
- var results = values.map(function (value, idx) { return ({
2193
- idx: idx,
2194
- votes: value,
2195
- percentage: Math.round((100 * value) / sum) || 0,
2196
- }); });
2197
- // Sum them all up - this can be less, equal or greater than a 100%
2198
- var total = results.reduce(function (memo, _a) {
2199
- var percentage = _a.percentage;
2200
- return memo + percentage;
2201
- }, 0);
2202
- total = total || 100;
2203
- // Calculate number of percent that we are missing or that we need to lose
2204
- var delta = 100 - total;
2205
- var sign = delta >= 0 ? 1 : -1;
2206
- // Order all options by number of votes
2207
- results.sort(function (a, b) {
2208
- var result = sign * (b.votes - a.votes);
2209
- if (result !== 0) {
2210
- return result;
2211
- }
2212
- return sign * (a.idx - b.idx);
2213
- });
2214
- // If we have percents to lose then take one percent off lowest options
2215
- // If we are missing percents then add one percent to highest options
2216
- var i = 0;
2217
- while (delta !== 0) {
2218
- if (results[i].votes > 0) {
2219
- results[i].percentage += sign;
2220
- delta -= sign;
2221
- }
2222
- i++;
2223
- }
2224
- // Restore options order
2225
- results.sort(function (a, b) { return a.idx - b.idx; });
2226
- return results.map(function (item) { return item.percentage; });
2227
- };
2228
-
2229
2178
  /**
2230
2179
  * @license
2231
2180
  * factory.ts