@sswroom/sswr 1.5.5 → 1.6.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.
package/unit.js CHANGED
@@ -1,3 +1,5 @@
1
+ import * as math from "./math.js";
2
+
1
3
  export class UnitInfo
2
4
  {
3
5
  constructor(unit, symbol, name, ratio, scale)
@@ -216,6 +218,114 @@ export class Count
216
218
  {
217
219
  return fromValue * ApparentPower.getUnitRatio(fromUnit) / ApparentPower.getUnitRatio(toUnit);
218
220
  }
221
+
222
+ static wellFormat(val, nDecimal)
223
+ {
224
+ if (nDecimal == null || nDecimal < 1)
225
+ nDecimal = 2;
226
+ let lval = Math.log10(val);
227
+ if (lval < 0)
228
+ {
229
+ if (lval >= -2)
230
+ {
231
+ return math.roundToStr(val * 100, nDecimal)+"c";
232
+ }
233
+ else if (lval >= -3)
234
+ {
235
+ return math.roundToStr(val * 1000, nDecimal)+"m";
236
+ }
237
+ else if (lval >= -6)
238
+ {
239
+ return math.roundToStr(val * 1000000, nDecimal)+"u";
240
+ }
241
+ else if (lval >= -9)
242
+ {
243
+ return math.roundToStr(val * 1.0e9, nDecimal)+"n";
244
+ }
245
+ else if (lval >= -12)
246
+ {
247
+ return math.roundToStr(val * 1.0e12, nDecimal)+"p";
248
+ }
249
+ else if (lval >= -15)
250
+ {
251
+ return math.roundToStr(val * 1.0e15, nDecimal)+"f";
252
+ }
253
+ else if (lval >= -18)
254
+ {
255
+ return math.roundToStr(val * 1.0e18, nDecimal)+"a";
256
+ }
257
+ else if (lval >= -21)
258
+ {
259
+ return math.roundToStr(val * 1.0e21, nDecimal)+"z";
260
+ }
261
+ else
262
+ {
263
+ return math.roundToStr(val * 1.0e24, nDecimal)+"y";
264
+ }
265
+ }
266
+ else if (lval < 3)
267
+ {
268
+ return math.roundToStr(val, nDecimal);
269
+ }
270
+ else if (lval < 6)
271
+ {
272
+ return math.roundToStr(val / 1.0e3, nDecimal)+"k";
273
+ }
274
+ else if (lval < 9)
275
+ {
276
+ return math.roundToStr(val / 1.0e6, nDecimal)+"M";
277
+ }
278
+ else if (val < 12)
279
+ {
280
+ return math.roundToStr(val / 1.0e9, nDecimal)+"G";
281
+ }
282
+ else if (val < 15)
283
+ {
284
+ return math.roundToStr(val / 1.0e12, nDecimal)+"T";
285
+ }
286
+ else if (val < 18)
287
+ {
288
+ return math.roundToStr(val / 1.0e15, nDecimal)+"P";
289
+ }
290
+ else if (val < 21)
291
+ {
292
+ return math.roundToStr(val / 1.0e18, nDecimal)+"E";
293
+ }
294
+ else if (val < 24)
295
+ {
296
+ return math.roundToStr(val / 1.0e21, nDecimal)+"Z";
297
+ }
298
+ else
299
+ {
300
+ return math.roundToStr(val / 1.0e24, nDecimal)+"Y";
301
+ }
302
+ }
303
+
304
+ static wellFormatBin(val, nDecimal)
305
+ {
306
+ if (nDecimal == null || nDecimal < 1)
307
+ nDecimal = 2;
308
+ if (val < 1024)
309
+ {
310
+ return math.roundToStr(val, nDecimal);
311
+ }
312
+ else if (val < 1048576)
313
+ {
314
+ return math.roundToStr(val / 1024, nDecimal)+"Ki";
315
+ }
316
+ else if (val < 1073741824)
317
+ {
318
+ return math.roundToStr(val / 1048576, nDecimal)+"Mi";
319
+ }
320
+ else if (val < 1099511627776)
321
+ {
322
+ return math.roundToStr(val / 1073741824, nDecimal)+"Gi";
323
+ }
324
+ else
325
+ {
326
+ return math.roundToStr(val / 1099511627776, nDecimal)+"Ti";
327
+ }
328
+ }
219
329
  }
220
330
 
221
331
  export class Distance
package/web.d.ts CHANGED
@@ -24,6 +24,7 @@ export function mimeFromFileName(fileName: string): string;
24
24
  export function mimeFromExt(ext: string): string;
25
25
  export function getImageInfo(url: string): Promise<ImageInfo|null>;
26
26
  export function propertiesToHTML(prop: object): string;
27
+ export function getCacheSize(name: string): Promise<number>;
27
28
 
28
29
  declare class DialogButton
29
30
  {
package/web.js CHANGED
@@ -742,6 +742,23 @@ export function propertiesToHTML(prop)
742
742
  return ret.join("");
743
743
  }
744
744
 
745
+ export async function getCacheSize(name)
746
+ {
747
+ const cache = await caches.open(name);
748
+ const keys = await cache.keys();
749
+ let i;
750
+ let size = 0;
751
+ for (i in keys)
752
+ {
753
+ let resp = await cache.match(keys[i]);
754
+ if (resp)
755
+ {
756
+ size += (await resp.arrayBuffer()).byteLength;
757
+ }
758
+ }
759
+ return size;
760
+ }
761
+
745
762
  export class Dialog
746
763
  {
747
764
  constructor(content, options)