@spacelyorg/common 1.0.7 → 1.0.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spacelyorg/common",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -14,8 +14,14 @@
14
14
  "url": "git+https://github.com/SpacelyOrg/contracts.git"
15
15
  },
16
16
  "exports": {
17
- ".": "./dist"
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ }
18
21
  },
22
+ "files": [
23
+ "dist"
24
+ ],
19
25
  "keywords": [],
20
26
  "author": "",
21
27
  "license": "ISC",
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './utils'
@@ -1,2 +0,0 @@
1
- export * from './ms.util'
2
- export * from './parse-boolean.util'
@@ -1,110 +0,0 @@
1
- const s = 1000
2
- const m = s * 60
3
- const h = m * 60
4
- const d = h * 24
5
- const w = d * 7
6
- const y = d * 365.25
7
-
8
- type Unit =
9
- | 'Years'
10
- | 'Year'
11
- | 'Yrs'
12
- | 'Yr'
13
- | 'y'
14
- | 'Weeks'
15
- | 'Week'
16
- | 'w'
17
- | 'Days'
18
- | 'Day'
19
- | 'd'
20
- | 'Hours'
21
- | 'Hour'
22
- | 'Hrs'
23
- | 'Hr'
24
- | 'h'
25
- | 'Minutes'
26
- | 'Minute'
27
- | 'Mins'
28
- | 'Min'
29
- | 'm'
30
- | 'Seconds'
31
- | 'Second'
32
- | 'Secs'
33
- | 'Sec'
34
- | 's'
35
- | 'Milliseconds'
36
- | 'Millisecond'
37
- | 'Msecs'
38
- | 'Msec'
39
- | 'ms'
40
-
41
- type UnitAnyCase = Unit | Uppercase<Unit> | Lowercase<Unit>
42
-
43
- export type StringValue =
44
- | `${number}`
45
- | `${number}${UnitAnyCase}`
46
- | `${number} ${UnitAnyCase}`
47
-
48
- export function ms(str: StringValue): number {
49
- if (typeof str !== 'string' || str.length === 0 || str.length > 100) {
50
- throw new Error(
51
- 'Value provided to ms() must be a string with length between 1 and 99'
52
- )
53
- }
54
- const match =
55
- /^(?<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(
56
- str
57
- )
58
-
59
- const groups = match?.groups as { value: string; type: string } | undefined
60
- if (!groups) {
61
- return NaN
62
- }
63
- const n = parseFloat(groups.value)
64
- const type: string = (groups.type || 'ms').toLowerCase() as Lowercase<Unit>
65
-
66
- switch (type) {
67
- case 'years':
68
- case 'year':
69
- case 'yrs':
70
- case 'yr':
71
- case 'y':
72
- return n * y
73
- case 'weeks':
74
- case 'week':
75
- case 'w':
76
- return n * w
77
- case 'days':
78
- case 'day':
79
- case 'd':
80
- return n * d
81
- case 'hours':
82
- case 'hour':
83
- case 'hrs':
84
- case 'hr':
85
- case 'h':
86
- return n * h
87
- case 'minutes':
88
- case 'minute':
89
- case 'mins':
90
- case 'min':
91
- case 'm':
92
- return n * m
93
- case 'seconds':
94
- case 'second':
95
- case 'secs':
96
- case 'sec':
97
- case 's':
98
- return n * s
99
- case 'milliseconds':
100
- case 'millisecond':
101
- case 'msecs':
102
- case 'msec':
103
- case 'ms':
104
- return n
105
- default:
106
- throw new Error(
107
- `Ошибка: единица времени ${type} была распознана, но не существует соответствующего случая. Пожалуйста, проверьте введенные данные`
108
- )
109
- }
110
- }
@@ -1,21 +0,0 @@
1
- export function parseBoolean(value: unknown): boolean {
2
- if (typeof value === 'boolean') {
3
- return value
4
- }
5
-
6
- if (typeof value === 'string') {
7
- const lowerValue = value.trim().toLowerCase()
8
-
9
- if (lowerValue === 'true') {
10
- return true
11
- }
12
-
13
- if (lowerValue === 'false') {
14
- return false
15
- }
16
- }
17
-
18
- throw new Error(
19
- `Не удалось преобразовать значение "${value}" в логическое значение`
20
- )
21
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "outDir": "dist"
6
- },
7
- "include": ["src/**/*"],
8
- "exclude": ["node_modules", "dist", "test"]
9
- }
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "target": "es2024",
5
- "strict": true,
6
- "esModuleInterop": true,
7
- "skipLibCheck": true,
8
- "forceConsistentCasingInFileNames": true,
9
- "strictNullChecks": false,
10
- "allowImportingTsExtensions": false
11
- }
12
- }