@hestia-earth/utils 0.16.18 → 0.16.20

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/dist/date.d.ts CHANGED
@@ -56,3 +56,4 @@ export declare const hoursBefore: (date?: Date, hours?: number) => Date;
56
56
  * @returns New date.
57
57
  */
58
58
  export declare const minutesBefore: (date?: Date, minutes?: number) => Date;
59
+ export declare const duration: (timeInMs: number, includeMs?: boolean) => string;
package/dist/date.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.minutesBefore = exports.hoursBefore = exports.daysBefore = exports.monthsBefore = exports.diffInYears = exports.diffInDays = exports.dayMs = exports.hourMs = exports.minuteMs = exports.secondMs = void 0;
3
+ exports.duration = exports.minutesBefore = exports.hoursBefore = exports.daysBefore = exports.monthsBefore = exports.diffInYears = exports.diffInDays = exports.dayMs = exports.hourMs = exports.minuteMs = exports.secondMs = void 0;
4
4
  exports.secondMs = 1000;
5
5
  exports.minuteMs = 60 * exports.secondMs;
6
6
  exports.hourMs = 60 * exports.minuteMs;
@@ -94,3 +94,25 @@ var minutesBefore = function (date, minutes) {
94
94
  return newDate;
95
95
  };
96
96
  exports.minutesBefore = minutesBefore;
97
+ var parseTime = function (timeInMs) { return ({
98
+ milliseconds: Math.floor(timeInMs % 1000),
99
+ seconds: Math.floor((timeInMs / 1000) % 60),
100
+ minutes: Math.floor((timeInMs / (1000 * 60)) % 60),
101
+ hours: Math.floor((timeInMs / (1000 * 60 * 60)) % 24),
102
+ days: Math.floor(timeInMs / (1000 * 60 * 60 * 24))
103
+ }); };
104
+ var formatValue = function (value, suffix) { return (value ? "".concat(value).concat(suffix) : ''); };
105
+ var duration = function (timeInMs, includeMs) {
106
+ if (includeMs === void 0) { includeMs = false; }
107
+ var _a = parseTime(timeInMs), milliseconds = _a.milliseconds, seconds = _a.seconds, minutes = _a.minutes, hours = _a.hours, days = _a.days;
108
+ return [
109
+ formatValue(days, 'd'),
110
+ formatValue(hours, 'h'),
111
+ formatValue(minutes, 'm'),
112
+ formatValue(seconds, 's'),
113
+ includeMs ? formatValue(milliseconds, 'ms') : ''
114
+ ]
115
+ .filter(function (v) { return v !== ''; })
116
+ .join(' ');
117
+ };
118
+ exports.duration = duration;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/utils",
3
- "version": "0.16.18",
3
+ "version": "0.16.20",
4
4
  "description": "HESTIA Utils library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -11,8 +11,9 @@
11
11
  "build": "rm -rf dist && tsc -p tsconfig.dist.json",
12
12
  "lint": "eslint \"src/**/*.ts\"",
13
13
  "lint:fix": "npm run lint -- --fix",
14
- "test": "nyc mocha \"src/**/*.spec.ts\"",
15
- "test:watch": "npm run test -- --watch"
14
+ "test": "jest",
15
+ "test:watch": "jest --watch",
16
+ "test:coverage": "jest --coverage"
16
17
  },
17
18
  "repository": {
18
19
  "type": "git",
@@ -34,19 +35,14 @@
34
35
  "devDependencies": {
35
36
  "@hestia-earth/eslint-config": "^0.1.0",
36
37
  "@hestia-earth/glossary": "^0.44.0",
37
- "@types/chai": "^4.2.21",
38
- "@types/mocha": "^7.0.2",
38
+ "@types/jest": "^30.0.0",
39
39
  "@types/node": "^22.18.11",
40
- "@types/sinon": "^9.0.11",
41
40
  "@typescript-eslint/eslint-plugin": "^5.27.1",
42
41
  "@typescript-eslint/parser": "^5.27.1",
43
- "chai": "^4.3.4",
44
42
  "eslint": "^7.32.0",
45
43
  "eslint-plugin-jsdoc": "^30.7.13",
46
- "mocha": "^7.2.0",
47
- "nyc": "^15.1.0",
48
- "sinon": "^9.2.4",
49
- "source-map-support": "^0.5.19",
44
+ "jest": "^30.2.0",
45
+ "ts-jest": "^29.4.6",
50
46
  "ts-node": "^9.1.1",
51
47
  "typescript": "^5.9.3"
52
48
  },