@spacelyorg/common 1.0.0 → 1.0.2
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/package.json +4 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -17
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/ms.util.d.ts +0 -5
- package/dist/utils/ms.util.js +0 -63
- package/dist/utils/parse-boolean.util.d.ts +0 -1
- package/dist/utils/parse-boolean.util.js +0 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spacelyorg/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git+https://github.com/SpacelyOrg/contracts.git"
|
|
15
15
|
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./index.js"
|
|
18
|
+
},
|
|
16
19
|
"keywords": [],
|
|
17
20
|
"author": "",
|
|
18
21
|
"license": "ISC",
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './utils';
|
package/dist/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./utils"), exports);
|
package/dist/utils/index.d.ts
DELETED
package/dist/utils/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./ms.util"), exports);
|
|
18
|
-
__exportStar(require("./parse-boolean.util"), exports);
|
package/dist/utils/ms.util.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
type Unit = 'Years' | 'Year' | 'Yrs' | 'Yr' | 'y' | 'Weeks' | 'Week' | 'w' | 'Days' | 'Day' | 'd' | 'Hours' | 'Hour' | 'Hrs' | 'Hr' | 'h' | 'Minutes' | 'Minute' | 'Mins' | 'Min' | 'm' | 'Seconds' | 'Second' | 'Secs' | 'Sec' | 's' | 'Milliseconds' | 'Millisecond' | 'Msecs' | 'Msec' | 'ms';
|
|
2
|
-
type UnitAnyCase = Unit | Uppercase<Unit> | Lowercase<Unit>;
|
|
3
|
-
export type StringValue = `${number}` | `${number}${UnitAnyCase}` | `${number} ${UnitAnyCase}`;
|
|
4
|
-
export declare function ms(str: StringValue): number;
|
|
5
|
-
export {};
|
package/dist/utils/ms.util.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ms = ms;
|
|
4
|
-
const s = 1000;
|
|
5
|
-
const m = s * 60;
|
|
6
|
-
const h = m * 60;
|
|
7
|
-
const d = h * 24;
|
|
8
|
-
const w = d * 7;
|
|
9
|
-
const y = d * 365.25;
|
|
10
|
-
function ms(str) {
|
|
11
|
-
if (typeof str !== 'string' || str.length === 0 || str.length > 100) {
|
|
12
|
-
throw new Error('Value provided to ms() must be a string with length between 1 and 99');
|
|
13
|
-
}
|
|
14
|
-
const match = /^(?<value>-?(?:\d+)?\.?\d+ *(?<type>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?)$/i.exec(str);
|
|
15
|
-
const groups = match?.groups;
|
|
16
|
-
if (!groups) {
|
|
17
|
-
return NaN;
|
|
18
|
-
}
|
|
19
|
-
const n = parseFloat(groups.value);
|
|
20
|
-
const type = (groups.type || 'ms').toLowerCase();
|
|
21
|
-
switch (type) {
|
|
22
|
-
case 'years':
|
|
23
|
-
case 'year':
|
|
24
|
-
case 'yrs':
|
|
25
|
-
case 'yr':
|
|
26
|
-
case 'y':
|
|
27
|
-
return n * y;
|
|
28
|
-
case 'weeks':
|
|
29
|
-
case 'week':
|
|
30
|
-
case 'w':
|
|
31
|
-
return n * w;
|
|
32
|
-
case 'days':
|
|
33
|
-
case 'day':
|
|
34
|
-
case 'd':
|
|
35
|
-
return n * d;
|
|
36
|
-
case 'hours':
|
|
37
|
-
case 'hour':
|
|
38
|
-
case 'hrs':
|
|
39
|
-
case 'hr':
|
|
40
|
-
case 'h':
|
|
41
|
-
return n * h;
|
|
42
|
-
case 'minutes':
|
|
43
|
-
case 'minute':
|
|
44
|
-
case 'mins':
|
|
45
|
-
case 'min':
|
|
46
|
-
case 'm':
|
|
47
|
-
return n * m;
|
|
48
|
-
case 'seconds':
|
|
49
|
-
case 'second':
|
|
50
|
-
case 'secs':
|
|
51
|
-
case 'sec':
|
|
52
|
-
case 's':
|
|
53
|
-
return n * s;
|
|
54
|
-
case 'milliseconds':
|
|
55
|
-
case 'millisecond':
|
|
56
|
-
case 'msecs':
|
|
57
|
-
case 'msec':
|
|
58
|
-
case 'ms':
|
|
59
|
-
return n;
|
|
60
|
-
default:
|
|
61
|
-
throw new Error(`Ошибка: единица времени ${type} была распознана, но не существует соответствующего случая. Пожалуйста, проверьте введенные данные`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function parseBoolean(value: unknown): boolean;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseBoolean = parseBoolean;
|
|
4
|
-
function parseBoolean(value) {
|
|
5
|
-
if (typeof value === 'boolean') {
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
if (typeof value === 'string') {
|
|
9
|
-
const lowerValue = value.trim().toLowerCase();
|
|
10
|
-
if (lowerValue === 'true') {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
if (lowerValue === 'false') {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
throw new Error(`Не удалось преобразовать значение "${value}" в логическое значение`);
|
|
18
|
-
}
|