@nka212bg/backend-utils 0.1.22 → 0.1.23
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/misc.js +42 -40
- package/package.json +1 -1
package/misc.js
CHANGED
|
@@ -113,31 +113,22 @@ exports.handlebars = ({ template, ...params } = {}) => {
|
|
|
113
113
|
return template;
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
-
exports.shortCount = (value,
|
|
116
|
+
exports.shortCount = (value, bites) => {
|
|
117
117
|
value = Number(value);
|
|
118
|
-
if (
|
|
118
|
+
if (!value) return "";
|
|
119
119
|
|
|
120
120
|
let units = {
|
|
121
|
-
trillion: "T",
|
|
122
|
-
billion: "B",
|
|
123
|
-
million: "M",
|
|
124
|
-
thousand: "K",
|
|
121
|
+
trillion: bites ? "tb" : "T",
|
|
122
|
+
billion: bites ? "gb" : "B",
|
|
123
|
+
million: bites ? "mb" : "M",
|
|
124
|
+
thousand: bites ? "kb" : "K",
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
thousand: " kb",
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (value > 1000000000000) return (value / 1000000000000).toFixed(1) + units.trillion;
|
|
137
|
-
if (value > 1000000000) return (value / 1000000000).toFixed(1) + units.billion;
|
|
138
|
-
if (value > 1000000) return (value / 1000000).toFixed(1) + units.million;
|
|
139
|
-
if (value > 1000) return (value / 1000).toFixed(1) + units.thousand;
|
|
140
|
-
return value + (type == "disk" ? " bites" : "");
|
|
127
|
+
if (value >= 1000000000000) return (value / 1000000000000).toFixed(1) + units.trillion;
|
|
128
|
+
if (value >= 1000000000) return (value / 1000000000).toFixed(1) + units.billion;
|
|
129
|
+
if (value >= 1000000) return (value / 1000000).toFixed(1) + units.million;
|
|
130
|
+
if (value >= 1000) return (value / 1000).toFixed(1) + units.thousand;
|
|
131
|
+
return value + (bites ? "bit" : "");
|
|
141
132
|
};
|
|
142
133
|
|
|
143
134
|
exports.saveFile = (file, destinationPath, callback) => {
|
|
@@ -385,26 +376,37 @@ exports.crypto = ({ salt, embedSalt } = {}) => {
|
|
|
385
376
|
}
|
|
386
377
|
};
|
|
387
378
|
|
|
388
|
-
exports.secToTime = (
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const
|
|
393
|
-
const
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
379
|
+
exports.secToTime = (sec) => {
|
|
380
|
+
sec = parseInt(sec);
|
|
381
|
+
if (!sec) return;
|
|
382
|
+
|
|
383
|
+
const SEC_IN_MIN = 60;
|
|
384
|
+
const SEC_IN_HOUR = 3600;
|
|
385
|
+
const SEC_IN_DAY = 86400;
|
|
386
|
+
const SEC_IN_MONTH = SEC_IN_DAY * 30.5;
|
|
387
|
+
const SEC_IN_YEAR = SEC_IN_MONTH * 12;
|
|
388
|
+
|
|
389
|
+
const years = Math.floor(sec / SEC_IN_YEAR);
|
|
390
|
+
sec %= SEC_IN_YEAR;
|
|
391
|
+
|
|
392
|
+
const months = Math.floor(sec / SEC_IN_MONTH);
|
|
393
|
+
sec %= SEC_IN_MONTH;
|
|
394
|
+
|
|
395
|
+
const days = Math.floor(sec / SEC_IN_DAY);
|
|
396
|
+
sec %= SEC_IN_DAY;
|
|
397
|
+
|
|
398
|
+
const hours = Math.floor(sec / SEC_IN_HOUR);
|
|
399
|
+
sec %= SEC_IN_HOUR;
|
|
400
|
+
|
|
401
|
+
const minutes = Math.floor(sec / SEC_IN_MIN);
|
|
402
|
+
const seconds = sec % SEC_IN_MIN;
|
|
403
|
+
|
|
404
|
+
if (years > 0) return `${years}y ${months}m ${days}d`;
|
|
405
|
+
if (months > 0) return `${months}m ${days}d ${hours}h`;
|
|
406
|
+
if (days > 0) return `${days}d ${hours}h`;
|
|
407
|
+
if (hours > 0) return `${hours}h ${String(minutes).padStart(2, "0")}min`;
|
|
408
|
+
|
|
409
|
+
return `${minutes}min ${String(seconds).padStart(2, "0")}s`;
|
|
408
410
|
};
|
|
409
411
|
|
|
410
412
|
exports.urlMetadata = async ({ url }) => {
|