@sapphire/duration 1.0.1-next.574299a.0
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/CHANGELOG.md +0 -0
- package/README.md +119 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.global.js +210 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +218 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +187 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +68 -0
package/CHANGELOG.md
ADDED
|
File without changes
|
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
# @sapphire/duration
|
|
6
|
+
|
|
7
|
+
**Duration utilities for JavaScript.**
|
|
8
|
+
|
|
9
|
+
[](https://github.com/sapphiredev/utilities/blob/main/LICENSE.md)
|
|
10
|
+
[](https://codecov.io/gh/sapphiredev/utilities)
|
|
11
|
+
[](https://bundlephobia.com/result?p=@sapphire/duration)
|
|
12
|
+
[](https://www.npmjs.com/package/@sapphire/duration)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
**Table of Contents**
|
|
17
|
+
|
|
18
|
+
- [Features](#features)
|
|
19
|
+
- [Installation](#installation)
|
|
20
|
+
- [Usage](#usage)
|
|
21
|
+
- [Basic Usage](#basic-usage)
|
|
22
|
+
- [Buy us some doughnuts](#buy-us-some-doughnuts)
|
|
23
|
+
- [Contributors β¨](#contributors-%E2%9C%A8)
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- Written in TypeScript
|
|
28
|
+
- Bundled with esbuild so it can be used in NodeJS and browsers
|
|
29
|
+
- Offers CommonJS, ESM and UMD bundles
|
|
30
|
+
- Fully tested
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
You can use the following command to install this package, or replace `npm install` with your package manager of choice.
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
npm install @sapphire/duration
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Buy us some doughnuts
|
|
41
|
+
|
|
42
|
+
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
|
|
43
|
+
|
|
44
|
+
We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
|
|
45
|
+
|
|
46
|
+
| Donate With | Address |
|
|
47
|
+
| :-------------: | :-------------------------------------------------: |
|
|
48
|
+
| Open Collective | [Click Here](https://sapphirejs.dev/opencollective) |
|
|
49
|
+
| Ko-fi | [Click Here](https://sapphirejs.dev/kofi) |
|
|
50
|
+
| Patreon | [Click Here](https://sapphirejs.dev/patreon) |
|
|
51
|
+
| PayPal | [Click Here](https://sapphirejs.dev/paypal) |
|
|
52
|
+
|
|
53
|
+
## Contributors β¨
|
|
54
|
+
|
|
55
|
+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
56
|
+
|
|
57
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
58
|
+
<!-- prettier-ignore-start -->
|
|
59
|
+
<!-- markdownlint-disable -->
|
|
60
|
+
<table>
|
|
61
|
+
<tr>
|
|
62
|
+
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Code">π»</a> <a href="#infra-favna" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#projectManagement-favna" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Documentation">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Tests">β οΈ</a></td>
|
|
63
|
+
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura RomΓ‘n</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Code">π»</a> <a href="#projectManagement-kyranet" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Akyranet" title="Reviewed Pull Requests">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Tests">β οΈ</a></td>
|
|
64
|
+
<td align="center"><a href="https://github.com/PyroTechniac"><img src="https://avatars2.githubusercontent.com/u/39341355?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gryffon Bellish</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3APyroTechniac" title="Reviewed Pull Requests">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Tests">β οΈ</a></td>
|
|
65
|
+
<td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars3.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3Avladfrangu" title="Bug reports">π</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Avladfrangu" title="Reviewed Pull Requests">π</a> <a href="#userTesting-vladfrangu" title="User Testing">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Tests">β οΈ</a></td>
|
|
66
|
+
<td align="center"><a href="https://github.com/Stitch07"><img src="https://avatars0.githubusercontent.com/u/29275227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stitch07</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Code">π»</a> <a href="#projectManagement-Stitch07" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Tests">β οΈ</a></td>
|
|
67
|
+
<td align="center"><a href="https://github.com/apps/depfu"><img src="https://avatars3.githubusercontent.com/in/715?v=4?s=100" width="100px;" alt=""/><br /><sub><b>depfu[bot]</b></sub></a><br /><a href="#maintenance-depfu[bot]" title="Maintenance">π§</a></td>
|
|
68
|
+
<td align="center"><a href="https://github.com/apps/allcontributors"><img src="https://avatars0.githubusercontent.com/in/23186?v=4?s=100" width="100px;" alt=""/><br /><sub><b>allcontributors[bot]</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=allcontributors[bot]" title="Documentation">π</a></td>
|
|
69
|
+
</tr>
|
|
70
|
+
<tr>
|
|
71
|
+
<td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars1.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Nytelife26" title="Documentation">π</a></td>
|
|
72
|
+
<td align="center"><a href="https://github.com/Alcremie"><img src="https://avatars0.githubusercontent.com/u/54785334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Lieder</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Alcremie" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AAlcremie" title="Bug reports">π</a></td>
|
|
73
|
+
<td align="center"><a href="https://github.com/RealShadowNova"><img src="https://avatars3.githubusercontent.com/u/46537907?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hezekiah Hendry</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=RealShadowNova" title="Code">π»</a> <a href="#tool-RealShadowNova" title="Tools">π§</a></td>
|
|
74
|
+
<td align="center"><a href="https://github.com/Vetlix"><img src="https://avatars.githubusercontent.com/u/31412314?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vetlix</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Vetlix" title="Code">π»</a></td>
|
|
75
|
+
<td align="center"><a href="https://github.com/ethamitc"><img src="https://avatars.githubusercontent.com/u/27776796?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ethan Mitchell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ethamitc" title="Documentation">π</a></td>
|
|
76
|
+
<td align="center"><a href="https://github.com/noftaly"><img src="https://avatars.githubusercontent.com/u/34779161?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Elliot</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=noftaly" title="Code">π»</a></td>
|
|
77
|
+
<td align="center"><a href="https://jurien.dev"><img src="https://avatars.githubusercontent.com/u/5418114?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jurien Hamaker</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=jurienhamaker" title="Code">π»</a></td>
|
|
78
|
+
</tr>
|
|
79
|
+
<tr>
|
|
80
|
+
<td align="center"><a href="https://fanoulis.dev/"><img src="https://avatars.githubusercontent.com/u/38255093?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Charalampos Fanoulis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=cfanoulis" title="Documentation">π</a></td>
|
|
81
|
+
<td align="center"><a href="https://github.com/apps/dependabot"><img src="https://avatars.githubusercontent.com/in/29110?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dependabot[bot]</b></sub></a><br /><a href="#maintenance-dependabot[bot]" title="Maintenance">π§</a></td>
|
|
82
|
+
<td align="center"><a href="https://kaname.netlify.app/"><img src="https://avatars.githubusercontent.com/u/56084970?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kaname</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kaname-png" title="Code">π»</a></td>
|
|
83
|
+
<td align="center"><a href="https://github.com/nandhagk"><img src="https://avatars.githubusercontent.com/u/62976649?v=4?s=100" width="100px;" alt=""/><br /><sub><b>nandhagk</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/issues?q=author%3Anandhagk" title="Bug reports">π</a></td>
|
|
84
|
+
<td align="center"><a href="https://megatank58.me/"><img src="https://avatars.githubusercontent.com/u/51410502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>megatank58</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=megatank58" title="Code">π»</a></td>
|
|
85
|
+
<td align="center"><a href="https://github.com/UndiedGamer"><img src="https://avatars.githubusercontent.com/u/84702365?v=4?s=100" width="100px;" alt=""/><br /><sub><b>UndiedGamer</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=UndiedGamer" title="Code">π»</a></td>
|
|
86
|
+
<td align="center"><a href="https://github.com/Lioness100"><img src="https://avatars.githubusercontent.com/u/65814829?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lioness100</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Documentation">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Code">π»</a></td>
|
|
87
|
+
</tr>
|
|
88
|
+
<tr>
|
|
89
|
+
<td align="center"><a href="https://gitlab.com/DavidPH/"><img src="https://avatars.githubusercontent.com/u/44669930?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=DavidPHH" title="Code">π»</a></td>
|
|
90
|
+
<td align="center"><a href="https://github.com/apps/renovate"><img src="https://avatars.githubusercontent.com/in/2740?v=4?s=100" width="100px;" alt=""/><br /><sub><b>renovate[bot]</b></sub></a><br /><a href="#maintenance-renovate[bot]" title="Maintenance">π§</a></td>
|
|
91
|
+
<td align="center"><a href="https://renovate.whitesourcesoftware.com/"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">π§</a></td>
|
|
92
|
+
<td align="center"><a href="https://fc5570.me/"><img src="https://avatars.githubusercontent.com/u/68158483?v=4?s=100" width="100px;" alt=""/><br /><sub><b>FC</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=FC5570" title="Code">π»</a></td>
|
|
93
|
+
<td align="center"><a href="https://github.com/Tokipudi"><img src="https://avatars.githubusercontent.com/u/29551076?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JΓ©rΓ©my de Saint Denis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Tokipudi" title="Code">π»</a></td>
|
|
94
|
+
<td align="center"><a href="https://github.com/ItsMrCube"><img src="https://avatars.githubusercontent.com/u/25201357?v=4?s=100" width="100px;" alt=""/><br /><sub><b>MrCube</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ItsMrCube" title="Code">π»</a></td>
|
|
95
|
+
<td align="center"><a href="https://github.com/bitomic"><img src="https://avatars.githubusercontent.com/u/35199700?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bitomic</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=bitomic" title="Code">π»</a></td>
|
|
96
|
+
</tr>
|
|
97
|
+
<tr>
|
|
98
|
+
<td align="center"><a href="https://c43721.dev/"><img src="https://avatars.githubusercontent.com/u/55610086?v=4?s=100" width="100px;" alt=""/><br /><sub><b>c43721</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=c43721" title="Code">π»</a></td>
|
|
99
|
+
<td align="center"><a href="https://commandtechno.com/"><img src="https://avatars.githubusercontent.com/u/68407783?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Commandtechno</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Commandtechno" title="Code">π»</a></td>
|
|
100
|
+
<td align="center"><a href="https://github.com/dhruv-kaushikk"><img src="https://avatars.githubusercontent.com/u/73697546?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=dhruv-kaushikk" title="Code">π»</a></td>
|
|
101
|
+
<td align="center"><a href="https://axis.moe/"><img src="https://avatars.githubusercontent.com/u/54381371?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=axisiscool" title="Code">π»</a></td>
|
|
102
|
+
<td align="center"><a href="https://github.com/imranbarbhuiya"><img src="https://avatars.githubusercontent.com/u/74945038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Parbez</b></sub></a><br /><a href="#maintenance-imranbarbhuiya" title="Maintenance">π§</a></td>
|
|
103
|
+
<td align="center"><a href="https://github.com/NotKaskus"><img src="https://avatars.githubusercontent.com/u/75168528?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Paul Andrew</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=NotKaskus" title="Documentation">π</a></td>
|
|
104
|
+
<td align="center"><a href="https://linktr.ee/mzato0001"><img src="https://avatars.githubusercontent.com/u/62367547?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mzato</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Mzato0001" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AMzato0001" title="Bug reports">π</a></td>
|
|
105
|
+
</tr>
|
|
106
|
+
<tr>
|
|
107
|
+
<td align="center"><a href="https://github.com/MajesticString"><img src="https://avatars.githubusercontent.com/u/66224939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harry Allen</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=MajesticString" title="Documentation">π</a></td>
|
|
108
|
+
<td align="center"><a href="https://github.com/EvolutionX-10"><img src="https://avatars.githubusercontent.com/u/85353424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Evo</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=EvolutionX-10" title="Code">π»</a></td>
|
|
109
|
+
<td align="center"><a href="https://enes.ovh/"><img src="https://avatars.githubusercontent.com/u/61084101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Enes GenΓ§</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=enxg" title="Code">π»</a></td>
|
|
110
|
+
<td align="center"><a href="https://github.com/muchnameless"><img src="https://avatars.githubusercontent.com/u/12682826?v=4?s=100" width="100px;" alt=""/><br /><sub><b>muchnameless</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=muchnameless" title="Code">π»</a></td>
|
|
111
|
+
</tr>
|
|
112
|
+
</table>
|
|
113
|
+
|
|
114
|
+
<!-- markdownlint-restore -->
|
|
115
|
+
<!-- prettier-ignore-end -->
|
|
116
|
+
|
|
117
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
118
|
+
|
|
119
|
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Display the duration
|
|
3
|
+
* @param duration The duration in milliseconds to parse and display
|
|
4
|
+
* @param assets The language assets
|
|
5
|
+
*/
|
|
6
|
+
declare class DurationFormatter {
|
|
7
|
+
units: DurationFormatAssetsTime;
|
|
8
|
+
constructor(units?: DurationFormatAssetsTime);
|
|
9
|
+
format(duration: number, precision?: number, { left: leftSeparator, right: rightSeparator }?: DurationFormatSeparators): string;
|
|
10
|
+
}
|
|
11
|
+
interface DurationFormatSeparators {
|
|
12
|
+
left?: string;
|
|
13
|
+
right?: string;
|
|
14
|
+
}
|
|
15
|
+
interface DurationFormatAssetsUnit extends Record<number, string> {
|
|
16
|
+
DEFAULT: string;
|
|
17
|
+
}
|
|
18
|
+
interface DurationFormatAssetsTime {
|
|
19
|
+
[TimeTypes.Second]: DurationFormatAssetsUnit;
|
|
20
|
+
[TimeTypes.Minute]: DurationFormatAssetsUnit;
|
|
21
|
+
[TimeTypes.Hour]: DurationFormatAssetsUnit;
|
|
22
|
+
[TimeTypes.Day]: DurationFormatAssetsUnit;
|
|
23
|
+
[TimeTypes.Week]: DurationFormatAssetsUnit;
|
|
24
|
+
[TimeTypes.Month]: DurationFormatAssetsUnit;
|
|
25
|
+
[TimeTypes.Year]: DurationFormatAssetsUnit;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare enum Time {
|
|
29
|
+
Millisecond = 1,
|
|
30
|
+
Second = 1000,
|
|
31
|
+
Minute = 60000,
|
|
32
|
+
Hour = 3600000,
|
|
33
|
+
Day = 86400000,
|
|
34
|
+
Month = 2628000000,
|
|
35
|
+
Year = 31536000000
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The supported time types
|
|
39
|
+
*/
|
|
40
|
+
declare enum TimeTypes {
|
|
41
|
+
Second = "second",
|
|
42
|
+
Minute = "minute",
|
|
43
|
+
Hour = "hour",
|
|
44
|
+
Day = "day",
|
|
45
|
+
Week = "week",
|
|
46
|
+
Month = "month",
|
|
47
|
+
Year = "year"
|
|
48
|
+
}
|
|
49
|
+
declare const DEFAULT_UNITS: DurationFormatAssetsTime;
|
|
50
|
+
declare const DEFAULT_SEPARATORS: DurationFormatSeparators;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Converts duration strings into ms and future dates
|
|
54
|
+
*/
|
|
55
|
+
declare class Duration {
|
|
56
|
+
/**
|
|
57
|
+
* The offset
|
|
58
|
+
*/
|
|
59
|
+
offset: number;
|
|
60
|
+
/**
|
|
61
|
+
* Create a new Duration instance
|
|
62
|
+
* @param pattern The string to parse
|
|
63
|
+
*/
|
|
64
|
+
constructor(pattern: string);
|
|
65
|
+
/**
|
|
66
|
+
* Get the date from now
|
|
67
|
+
*/
|
|
68
|
+
get fromNow(): Date;
|
|
69
|
+
/**
|
|
70
|
+
* Get the date from
|
|
71
|
+
* @param date The Date instance to get the date from
|
|
72
|
+
*/
|
|
73
|
+
dateFrom(date: Date): Date;
|
|
74
|
+
/**
|
|
75
|
+
* The RegExp used for the pattern parsing
|
|
76
|
+
*/
|
|
77
|
+
private static readonly kPatternRegex;
|
|
78
|
+
/**
|
|
79
|
+
* The RegExp used for removing commas
|
|
80
|
+
*/
|
|
81
|
+
private static readonly kCommaRegex;
|
|
82
|
+
/**
|
|
83
|
+
* The RegExp used for replacing a/an with 1
|
|
84
|
+
*/
|
|
85
|
+
private static readonly kAanRegex;
|
|
86
|
+
/**
|
|
87
|
+
* Parse the pattern
|
|
88
|
+
* @param pattern The pattern to parse
|
|
89
|
+
*/
|
|
90
|
+
private static parse;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { DEFAULT_SEPARATORS, DEFAULT_UNITS, Duration, DurationFormatAssetsTime, DurationFormatAssetsUnit, DurationFormatSeparators, DurationFormatter, Time, TimeTypes };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var SapphireDuration = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __publicField = (obj, key, value) => {
|
|
23
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/index.ts
|
|
28
|
+
var src_exports = {};
|
|
29
|
+
__export(src_exports, {
|
|
30
|
+
DEFAULT_SEPARATORS: () => DEFAULT_SEPARATORS,
|
|
31
|
+
DEFAULT_UNITS: () => DEFAULT_UNITS,
|
|
32
|
+
Duration: () => Duration,
|
|
33
|
+
DurationFormatter: () => DurationFormatter,
|
|
34
|
+
Time: () => Time,
|
|
35
|
+
TimeTypes: () => TimeTypes
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// src/lib/constants.ts
|
|
39
|
+
var Time = /* @__PURE__ */ ((Time2) => {
|
|
40
|
+
Time2[Time2["Millisecond"] = 1] = "Millisecond";
|
|
41
|
+
Time2[Time2["Second"] = 1e3] = "Second";
|
|
42
|
+
Time2[Time2["Minute"] = 6e4] = "Minute";
|
|
43
|
+
Time2[Time2["Hour"] = 36e5] = "Hour";
|
|
44
|
+
Time2[Time2["Day"] = 864e5] = "Day";
|
|
45
|
+
Time2[Time2["Month"] = 2628e6] = "Month";
|
|
46
|
+
Time2[Time2["Year"] = 31536e6] = "Year";
|
|
47
|
+
return Time2;
|
|
48
|
+
})(Time || {});
|
|
49
|
+
var TimeTypes = /* @__PURE__ */ ((TimeTypes2) => {
|
|
50
|
+
TimeTypes2["Second"] = "second";
|
|
51
|
+
TimeTypes2["Minute"] = "minute";
|
|
52
|
+
TimeTypes2["Hour"] = "hour";
|
|
53
|
+
TimeTypes2["Day"] = "day";
|
|
54
|
+
TimeTypes2["Week"] = "week";
|
|
55
|
+
TimeTypes2["Month"] = "month";
|
|
56
|
+
TimeTypes2["Year"] = "year";
|
|
57
|
+
return TimeTypes2;
|
|
58
|
+
})(TimeTypes || {});
|
|
59
|
+
var DEFAULT_UNITS = {
|
|
60
|
+
["year" /* Year */]: {
|
|
61
|
+
1: "year",
|
|
62
|
+
DEFAULT: "years"
|
|
63
|
+
},
|
|
64
|
+
["month" /* Month */]: {
|
|
65
|
+
1: "month",
|
|
66
|
+
DEFAULT: "months"
|
|
67
|
+
},
|
|
68
|
+
["week" /* Week */]: {
|
|
69
|
+
1: "week",
|
|
70
|
+
DEFAULT: "weeks"
|
|
71
|
+
},
|
|
72
|
+
["day" /* Day */]: {
|
|
73
|
+
1: "day",
|
|
74
|
+
DEFAULT: "days"
|
|
75
|
+
},
|
|
76
|
+
["hour" /* Hour */]: {
|
|
77
|
+
1: "hour",
|
|
78
|
+
DEFAULT: "hours"
|
|
79
|
+
},
|
|
80
|
+
["minute" /* Minute */]: {
|
|
81
|
+
1: "minute",
|
|
82
|
+
DEFAULT: "minutes"
|
|
83
|
+
},
|
|
84
|
+
["second" /* Second */]: {
|
|
85
|
+
1: "second",
|
|
86
|
+
DEFAULT: "seconds"
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var DEFAULT_SEPARATORS = {
|
|
90
|
+
left: " ",
|
|
91
|
+
right: " "
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/lib/Duration.ts
|
|
95
|
+
var tokens = /* @__PURE__ */ new Map([
|
|
96
|
+
["nanosecond", 1 / 1e6],
|
|
97
|
+
["nanoseconds", 1 / 1e6],
|
|
98
|
+
["ns", 1 / 1e6],
|
|
99
|
+
["millisecond", 1],
|
|
100
|
+
["milliseconds", 1],
|
|
101
|
+
["ms", 1],
|
|
102
|
+
["second", 1e3],
|
|
103
|
+
["seconds", 1e3],
|
|
104
|
+
["sec", 1e3],
|
|
105
|
+
["secs", 1e3],
|
|
106
|
+
["s", 1e3],
|
|
107
|
+
["minute", 1e3 * 60],
|
|
108
|
+
["minutes", 1e3 * 60],
|
|
109
|
+
["min", 1e3 * 60],
|
|
110
|
+
["mins", 1e3 * 60],
|
|
111
|
+
["m", 1e3 * 60],
|
|
112
|
+
["hour", 1e3 * 60 * 60],
|
|
113
|
+
["hours", 1e3 * 60 * 60],
|
|
114
|
+
["hr", 1e3 * 60 * 60],
|
|
115
|
+
["hrs", 1e3 * 60 * 60],
|
|
116
|
+
["h", 1e3 * 60 * 60],
|
|
117
|
+
["day", 1e3 * 60 * 60 * 24],
|
|
118
|
+
["days", 1e3 * 60 * 60 * 24],
|
|
119
|
+
["d", 1e3 * 60 * 60 * 24],
|
|
120
|
+
["week", 1e3 * 60 * 60 * 24 * 7],
|
|
121
|
+
["weeks", 1e3 * 60 * 60 * 24 * 7],
|
|
122
|
+
["wk", 1e3 * 60 * 60 * 24 * 7],
|
|
123
|
+
["wks", 1e3 * 60 * 60 * 24 * 7],
|
|
124
|
+
["w", 1e3 * 60 * 60 * 24 * 7],
|
|
125
|
+
["month", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
126
|
+
["months", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
127
|
+
["b", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
128
|
+
["mo", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
129
|
+
["year", 1e3 * 60 * 60 * 24 * 365.25],
|
|
130
|
+
["years", 1e3 * 60 * 60 * 24 * 365.25],
|
|
131
|
+
["yr", 1e3 * 60 * 60 * 24 * 365.25],
|
|
132
|
+
["yrs", 1e3 * 60 * 60 * 24 * 365.25],
|
|
133
|
+
["y", 1e3 * 60 * 60 * 24 * 365.25]
|
|
134
|
+
]);
|
|
135
|
+
var _Duration = class {
|
|
136
|
+
constructor(pattern) {
|
|
137
|
+
__publicField(this, "offset");
|
|
138
|
+
this.offset = _Duration.parse(pattern.toLowerCase());
|
|
139
|
+
}
|
|
140
|
+
get fromNow() {
|
|
141
|
+
return this.dateFrom(new Date());
|
|
142
|
+
}
|
|
143
|
+
dateFrom(date) {
|
|
144
|
+
return new Date(date.getTime() + this.offset);
|
|
145
|
+
}
|
|
146
|
+
static parse(pattern) {
|
|
147
|
+
let result = 0;
|
|
148
|
+
let valid = false;
|
|
149
|
+
pattern.replace(_Duration.kCommaRegex, "").replace(_Duration.kAanRegex, "1").replace(_Duration.kPatternRegex, (_, i, units) => {
|
|
150
|
+
const token = tokens.get(units);
|
|
151
|
+
if (token !== void 0) {
|
|
152
|
+
result += Number(i) * token;
|
|
153
|
+
valid = true;
|
|
154
|
+
}
|
|
155
|
+
return "";
|
|
156
|
+
});
|
|
157
|
+
return valid ? result : NaN;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
var Duration = _Duration;
|
|
161
|
+
__name(Duration, "Duration");
|
|
162
|
+
__publicField(Duration, "kPatternRegex", /(-?\d*\.?\d+(?:e[-+]?\d+)?)\s*([a-zΞΌ]*)/gi);
|
|
163
|
+
__publicField(Duration, "kCommaRegex", /,/g);
|
|
164
|
+
__publicField(Duration, "kAanRegex", /\ban?\b/gi);
|
|
165
|
+
|
|
166
|
+
// src/lib/DurationFormatter.ts
|
|
167
|
+
var kTimeDurations = [
|
|
168
|
+
["year" /* Year */, 31536e6],
|
|
169
|
+
["month" /* Month */, 2628e6],
|
|
170
|
+
["week" /* Week */, 1e3 * 60 * 60 * 24 * 7],
|
|
171
|
+
["day" /* Day */, 1e3 * 60 * 60 * 24],
|
|
172
|
+
["hour" /* Hour */, 1e3 * 60 * 60],
|
|
173
|
+
["minute" /* Minute */, 1e3 * 60],
|
|
174
|
+
["second" /* Second */, 1e3]
|
|
175
|
+
];
|
|
176
|
+
var DurationFormatter = class {
|
|
177
|
+
constructor(units = DEFAULT_UNITS) {
|
|
178
|
+
this.units = units;
|
|
179
|
+
}
|
|
180
|
+
format(duration, precision = 7, {
|
|
181
|
+
left: leftSeparator = DEFAULT_SEPARATORS.left,
|
|
182
|
+
right: rightSeparator = DEFAULT_SEPARATORS.right
|
|
183
|
+
} = DEFAULT_SEPARATORS) {
|
|
184
|
+
const output = [];
|
|
185
|
+
const negative = duration < 0;
|
|
186
|
+
if (negative)
|
|
187
|
+
duration *= -1;
|
|
188
|
+
for (const [type, timeDuration] of kTimeDurations) {
|
|
189
|
+
const division = duration / timeDuration;
|
|
190
|
+
if (division < 1)
|
|
191
|
+
continue;
|
|
192
|
+
const floored = Math.floor(division);
|
|
193
|
+
duration -= floored * timeDuration;
|
|
194
|
+
output.push(addUnit(floored, this.units[type], leftSeparator));
|
|
195
|
+
if (output.length >= precision)
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
return `${negative ? "-" : ""}${output.join(rightSeparator) || addUnit(0, this.units.second, leftSeparator)}`;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
__name(DurationFormatter, "DurationFormatter");
|
|
202
|
+
function addUnit(time, unit, separator) {
|
|
203
|
+
if (Reflect.has(unit, time))
|
|
204
|
+
return `${time}${separator}${Reflect.get(unit, time)}`;
|
|
205
|
+
return `${time}${separator}${unit.DEFAULT}`;
|
|
206
|
+
}
|
|
207
|
+
__name(addUnit, "addUnit");
|
|
208
|
+
return __toCommonJS(src_exports);
|
|
209
|
+
})();
|
|
210
|
+
//# sourceMappingURL=index.global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/constants.ts","../src/lib/Duration.ts","../src/lib/DurationFormatter.ts"],"sourcesContent":["export * from './lib/constants';\nexport * from './lib/Duration';\nexport * from './lib/DurationFormatter';\n","import type { DurationFormatAssetsTime, DurationFormatSeparators } from './DurationFormatter';\n\nexport enum Time {\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = 1000 * 60,\n\tHour = 1000 * 60 * 60,\n\tDay = 1000 * 60 * 60 * 24,\n\tMonth = 1000 * 60 * 60 * 24 * (365 / 12),\n\tYear = 1000 * 60 * 60 * 24 * 365\n}\n\n/**\n * The supported time types\n */\nexport enum TimeTypes {\n\tSecond = 'second',\n\tMinute = 'minute',\n\tHour = 'hour',\n\tDay = 'day',\n\tWeek = 'week',\n\tMonth = 'month',\n\tYear = 'year'\n}\n\nexport const DEFAULT_UNITS: DurationFormatAssetsTime = {\n\t[TimeTypes.Year]: {\n\t\t1: 'year',\n\t\tDEFAULT: 'years'\n\t},\n\t[TimeTypes.Month]: {\n\t\t1: 'month',\n\t\tDEFAULT: 'months'\n\t},\n\t[TimeTypes.Week]: {\n\t\t1: 'week',\n\t\tDEFAULT: 'weeks'\n\t},\n\t[TimeTypes.Day]: {\n\t\t1: 'day',\n\t\tDEFAULT: 'days'\n\t},\n\t[TimeTypes.Hour]: {\n\t\t1: 'hour',\n\t\tDEFAULT: 'hours'\n\t},\n\t[TimeTypes.Minute]: {\n\t\t1: 'minute',\n\t\tDEFAULT: 'minutes'\n\t},\n\t[TimeTypes.Second]: {\n\t\t1: 'second',\n\t\tDEFAULT: 'seconds'\n\t}\n};\n\nexport const DEFAULT_SEPARATORS: DurationFormatSeparators = {\n\tleft: ' ',\n\tright: ' '\n};\n","/* eslint-disable @typescript-eslint/restrict-plus-operands */\nconst tokens = new Map([\n\t['nanosecond', 1 / 1e6],\n\t['nanoseconds', 1 / 1e6],\n\t['ns', 1 / 1e6],\n\n\t['millisecond', 1],\n\t['milliseconds', 1],\n\t['ms', 1],\n\n\t['second', 1000],\n\t['seconds', 1000],\n\t['sec', 1000],\n\t['secs', 1000],\n\t['s', 1000],\n\n\t['minute', 1000 * 60],\n\t['minutes', 1000 * 60],\n\t['min', 1000 * 60],\n\t['mins', 1000 * 60],\n\t['m', 1000 * 60],\n\n\t['hour', 1000 * 60 * 60],\n\t['hours', 1000 * 60 * 60],\n\t['hr', 1000 * 60 * 60],\n\t['hrs', 1000 * 60 * 60],\n\t['h', 1000 * 60 * 60],\n\n\t['day', 1000 * 60 * 60 * 24],\n\t['days', 1000 * 60 * 60 * 24],\n\t['d', 1000 * 60 * 60 * 24],\n\n\t['week', 1000 * 60 * 60 * 24 * 7],\n\t['weeks', 1000 * 60 * 60 * 24 * 7],\n\t['wk', 1000 * 60 * 60 * 24 * 7],\n\t['wks', 1000 * 60 * 60 * 24 * 7],\n\t['w', 1000 * 60 * 60 * 24 * 7],\n\n\t['month', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\t['months', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\t['b', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\t['mo', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\n\t['year', 1000 * 60 * 60 * 24 * 365.25],\n\t['years', 1000 * 60 * 60 * 24 * 365.25],\n\t['yr', 1000 * 60 * 60 * 24 * 365.25],\n\t['yrs', 1000 * 60 * 60 * 24 * 365.25],\n\t['y', 1000 * 60 * 60 * 24 * 365.25]\n]);\n\n/**\n * Converts duration strings into ms and future dates\n */\nexport class Duration {\n\t/**\n\t * The offset\n\t */\n\tpublic offset: number;\n\n\t/**\n\t * Create a new Duration instance\n\t * @param pattern The string to parse\n\t */\n\tpublic constructor(pattern: string) {\n\t\tthis.offset = Duration.parse(pattern.toLowerCase());\n\t}\n\n\t/**\n\t * Get the date from now\n\t */\n\tpublic get fromNow(): Date {\n\t\treturn this.dateFrom(new Date());\n\t}\n\n\t/**\n\t * Get the date from\n\t * @param date The Date instance to get the date from\n\t */\n\tpublic dateFrom(date: Date): Date {\n\t\treturn new Date(date.getTime() + this.offset);\n\t}\n\n\t/**\n\t * The RegExp used for the pattern parsing\n\t */\n\tprivate static readonly kPatternRegex = /(-?\\d*\\.?\\d+(?:e[-+]?\\d+)?)\\s*([a-zΞΌ]*)/gi;\n\n\t/**\n\t * The RegExp used for removing commas\n\t */\n\tprivate static readonly kCommaRegex = /,/g;\n\n\t/**\n\t * The RegExp used for replacing a/an with 1\n\t */\n\tprivate static readonly kAanRegex = /\\ban?\\b/gi;\n\n\t/**\n\t * Parse the pattern\n\t * @param pattern The pattern to parse\n\t */\n\tprivate static parse(pattern: string): number {\n\t\tlet result = 0;\n\t\tlet valid = false;\n\n\t\tpattern\n\t\t\t// ignore commas\n\t\t\t.replace(Duration.kCommaRegex, '')\n\t\t\t// a / an = 1\n\t\t\t.replace(Duration.kAanRegex, '1')\n\t\t\t// do math\n\t\t\t.replace(Duration.kPatternRegex, (_, i, units) => {\n\t\t\t\tconst token = tokens.get(units);\n\t\t\t\tif (token !== undefined) {\n\t\t\t\t\tresult += Number(i) * token;\n\t\t\t\t\tvalid = true;\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t});\n\n\t\treturn valid ? result : NaN;\n\t}\n}\n","import { DEFAULT_SEPARATORS, DEFAULT_UNITS, TimeTypes } from './constants';\n\n/**\n * The duration of each time type in milliseconds\n */\nconst kTimeDurations: readonly [TimeTypes, number][] = [\n\t[TimeTypes.Year, 31536000000],\n\t// 29.53059 days is the official duration of a month: https://en.wikipedia.org/wiki/Month\n\t[TimeTypes.Month, 2628000000],\n\t[TimeTypes.Week, 1000 * 60 * 60 * 24 * 7],\n\t[TimeTypes.Day, 1000 * 60 * 60 * 24],\n\t[TimeTypes.Hour, 1000 * 60 * 60],\n\t[TimeTypes.Minute, 1000 * 60],\n\t[TimeTypes.Second, 1000]\n];\n\n/**\n * Display the duration\n * @param duration The duration in milliseconds to parse and display\n * @param assets The language assets\n */\nexport class DurationFormatter {\n\tpublic constructor(public units: DurationFormatAssetsTime = DEFAULT_UNITS) {}\n\n\tpublic format(\n\t\tduration: number,\n\t\tprecision = 7,\n\t\t{\n\t\t\tleft: leftSeparator = DEFAULT_SEPARATORS.left,\n\t\t\tright: rightSeparator = DEFAULT_SEPARATORS.right\n\t\t}: DurationFormatSeparators = DEFAULT_SEPARATORS\n\t) {\n\t\tconst output: string[] = [];\n\t\tconst negative = duration < 0;\n\t\tif (negative) duration *= -1;\n\n\t\tfor (const [type, timeDuration] of kTimeDurations) {\n\t\t\tconst division = duration / timeDuration;\n\t\t\tif (division < 1) continue;\n\n\t\t\tconst floored = Math.floor(division);\n\t\t\tduration -= floored * timeDuration;\n\t\t\toutput.push(addUnit(floored, this.units[type], leftSeparator!));\n\n\t\t\t// If the output has enough precision, break\n\t\t\tif (output.length >= precision) break;\n\t\t}\n\n\t\treturn `${negative ? '-' : ''}${output.join(rightSeparator) || addUnit(0, this.units.second, leftSeparator!)}`;\n\t}\n}\n\n/**\n * Adds an unit, if non zero\n * @param time The duration of said unit\n * @param unit The unit language assets\n */\nfunction addUnit(time: number, unit: DurationFormatAssetsUnit, separator: string) {\n\tif (Reflect.has(unit, time)) return `${time}${separator}${Reflect.get(unit, time)}`;\n\treturn `${time}${separator}${unit.DEFAULT}`;\n}\n\nexport interface DurationFormatSeparators {\n\tleft?: string;\n\tright?: string;\n}\n\nexport interface DurationFormatAssetsUnit extends Record<number, string> {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tDEFAULT: string;\n}\n\nexport interface DurationFormatAssetsTime {\n\t[TimeTypes.Second]: DurationFormatAssetsUnit;\n\t[TimeTypes.Minute]: DurationFormatAssetsUnit;\n\t[TimeTypes.Hour]: DurationFormatAssetsUnit;\n\t[TimeTypes.Day]: DurationFormatAssetsUnit;\n\t[TimeTypes.Week]: DurationFormatAssetsUnit;\n\t[TimeTypes.Month]: DurationFormatAssetsUnit;\n\t[TimeTypes.Year]: DurationFormatAssetsUnit;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,MAAK,OAAL,kBAAKA,UAAL;AACN,IAAAA,YAAA,iBAAc,KAAd;AACA,IAAAA,YAAA,YAAS,OAAT;AACA,IAAAA,YAAA,YAAS,OAAT;AACA,IAAAA,YAAA,UAAO,QAAP;AACA,IAAAA,YAAA,SAAM,SAAN;AACA,IAAAA,YAAA,WAAQ,UAAR;AACA,IAAAA,YAAA,UAAO,WAAP;AAPW,WAAAA;AAAA,KAAA;AAaL,MAAK,YAAL,kBAAKC,eAAL;AACN,IAAAA,WAAA,YAAS;AACT,IAAAA,WAAA,YAAS;AACT,IAAAA,WAAA,UAAO;AACP,IAAAA,WAAA,SAAM;AACN,IAAAA,WAAA,UAAO;AACP,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B;AACD,YAAM,SAAmB,CAAC;AAC1B,YAAM,WAAW,WAAW;AAC5B,UAAI;AAAU,oBAAY;AAE1B,iBAAW,CAAC,MAAM,YAAY,KAAK,gBAAgB;AAClD,cAAM,WAAW,WAAW;AAC5B,YAAI,WAAW;AAAG;AAElB,cAAM,UAAU,KAAK,MAAM,QAAQ;AACnC,oBAAY,UAAU;AACtB,eAAO,KAAK,QAAQ,SAAS,KAAK,MAAM,OAAO,aAAc,CAAC;AAG9D,YAAI,OAAO,UAAU;AAAW;AAAA,MACjC;AAEA,aAAO,GAAG,WAAW,MAAM,KAAK,OAAO,KAAK,cAAc,KAAK,QAAQ,GAAG,KAAK,MAAM,QAAQ,aAAc;AAAA,IAC5G;AAAA,EACD;AA7Ba;AAoCb,WAAS,QAAQ,MAAc,MAAgC,WAAmB;AACjF,QAAI,QAAQ,IAAI,MAAM,IAAI;AAAG,aAAO,GAAG,OAAO,YAAY,QAAQ,IAAI,MAAM,IAAI;AAChF,WAAO,GAAG,OAAO,YAAY,KAAK;AAAA,EACnC;AAHS;","names":["Time","TimeTypes"]}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __publicField = (obj, key, value) => {
|
|
23
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/index.ts
|
|
28
|
+
var src_exports = {};
|
|
29
|
+
__export(src_exports, {
|
|
30
|
+
DEFAULT_SEPARATORS: () => DEFAULT_SEPARATORS,
|
|
31
|
+
DEFAULT_UNITS: () => DEFAULT_UNITS,
|
|
32
|
+
Duration: () => Duration,
|
|
33
|
+
DurationFormatter: () => DurationFormatter,
|
|
34
|
+
Time: () => Time,
|
|
35
|
+
TimeTypes: () => TimeTypes
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
|
|
39
|
+
// src/lib/constants.ts
|
|
40
|
+
var Time = /* @__PURE__ */ ((Time2) => {
|
|
41
|
+
Time2[Time2["Millisecond"] = 1] = "Millisecond";
|
|
42
|
+
Time2[Time2["Second"] = 1e3] = "Second";
|
|
43
|
+
Time2[Time2["Minute"] = 6e4] = "Minute";
|
|
44
|
+
Time2[Time2["Hour"] = 36e5] = "Hour";
|
|
45
|
+
Time2[Time2["Day"] = 864e5] = "Day";
|
|
46
|
+
Time2[Time2["Month"] = 2628e6] = "Month";
|
|
47
|
+
Time2[Time2["Year"] = 31536e6] = "Year";
|
|
48
|
+
return Time2;
|
|
49
|
+
})(Time || {});
|
|
50
|
+
var TimeTypes = /* @__PURE__ */ ((TimeTypes2) => {
|
|
51
|
+
TimeTypes2["Second"] = "second";
|
|
52
|
+
TimeTypes2["Minute"] = "minute";
|
|
53
|
+
TimeTypes2["Hour"] = "hour";
|
|
54
|
+
TimeTypes2["Day"] = "day";
|
|
55
|
+
TimeTypes2["Week"] = "week";
|
|
56
|
+
TimeTypes2["Month"] = "month";
|
|
57
|
+
TimeTypes2["Year"] = "year";
|
|
58
|
+
return TimeTypes2;
|
|
59
|
+
})(TimeTypes || {});
|
|
60
|
+
var DEFAULT_UNITS = {
|
|
61
|
+
["year" /* Year */]: {
|
|
62
|
+
1: "year",
|
|
63
|
+
DEFAULT: "years"
|
|
64
|
+
},
|
|
65
|
+
["month" /* Month */]: {
|
|
66
|
+
1: "month",
|
|
67
|
+
DEFAULT: "months"
|
|
68
|
+
},
|
|
69
|
+
["week" /* Week */]: {
|
|
70
|
+
1: "week",
|
|
71
|
+
DEFAULT: "weeks"
|
|
72
|
+
},
|
|
73
|
+
["day" /* Day */]: {
|
|
74
|
+
1: "day",
|
|
75
|
+
DEFAULT: "days"
|
|
76
|
+
},
|
|
77
|
+
["hour" /* Hour */]: {
|
|
78
|
+
1: "hour",
|
|
79
|
+
DEFAULT: "hours"
|
|
80
|
+
},
|
|
81
|
+
["minute" /* Minute */]: {
|
|
82
|
+
1: "minute",
|
|
83
|
+
DEFAULT: "minutes"
|
|
84
|
+
},
|
|
85
|
+
["second" /* Second */]: {
|
|
86
|
+
1: "second",
|
|
87
|
+
DEFAULT: "seconds"
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var DEFAULT_SEPARATORS = {
|
|
91
|
+
left: " ",
|
|
92
|
+
right: " "
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/lib/Duration.ts
|
|
96
|
+
var tokens = /* @__PURE__ */ new Map([
|
|
97
|
+
["nanosecond", 1 / 1e6],
|
|
98
|
+
["nanoseconds", 1 / 1e6],
|
|
99
|
+
["ns", 1 / 1e6],
|
|
100
|
+
["millisecond", 1],
|
|
101
|
+
["milliseconds", 1],
|
|
102
|
+
["ms", 1],
|
|
103
|
+
["second", 1e3],
|
|
104
|
+
["seconds", 1e3],
|
|
105
|
+
["sec", 1e3],
|
|
106
|
+
["secs", 1e3],
|
|
107
|
+
["s", 1e3],
|
|
108
|
+
["minute", 1e3 * 60],
|
|
109
|
+
["minutes", 1e3 * 60],
|
|
110
|
+
["min", 1e3 * 60],
|
|
111
|
+
["mins", 1e3 * 60],
|
|
112
|
+
["m", 1e3 * 60],
|
|
113
|
+
["hour", 1e3 * 60 * 60],
|
|
114
|
+
["hours", 1e3 * 60 * 60],
|
|
115
|
+
["hr", 1e3 * 60 * 60],
|
|
116
|
+
["hrs", 1e3 * 60 * 60],
|
|
117
|
+
["h", 1e3 * 60 * 60],
|
|
118
|
+
["day", 1e3 * 60 * 60 * 24],
|
|
119
|
+
["days", 1e3 * 60 * 60 * 24],
|
|
120
|
+
["d", 1e3 * 60 * 60 * 24],
|
|
121
|
+
["week", 1e3 * 60 * 60 * 24 * 7],
|
|
122
|
+
["weeks", 1e3 * 60 * 60 * 24 * 7],
|
|
123
|
+
["wk", 1e3 * 60 * 60 * 24 * 7],
|
|
124
|
+
["wks", 1e3 * 60 * 60 * 24 * 7],
|
|
125
|
+
["w", 1e3 * 60 * 60 * 24 * 7],
|
|
126
|
+
["month", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
127
|
+
["months", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
128
|
+
["b", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
129
|
+
["mo", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
130
|
+
["year", 1e3 * 60 * 60 * 24 * 365.25],
|
|
131
|
+
["years", 1e3 * 60 * 60 * 24 * 365.25],
|
|
132
|
+
["yr", 1e3 * 60 * 60 * 24 * 365.25],
|
|
133
|
+
["yrs", 1e3 * 60 * 60 * 24 * 365.25],
|
|
134
|
+
["y", 1e3 * 60 * 60 * 24 * 365.25]
|
|
135
|
+
]);
|
|
136
|
+
var _Duration = class {
|
|
137
|
+
constructor(pattern) {
|
|
138
|
+
__publicField(this, "offset");
|
|
139
|
+
this.offset = _Duration.parse(pattern.toLowerCase());
|
|
140
|
+
}
|
|
141
|
+
get fromNow() {
|
|
142
|
+
return this.dateFrom(new Date());
|
|
143
|
+
}
|
|
144
|
+
dateFrom(date) {
|
|
145
|
+
return new Date(date.getTime() + this.offset);
|
|
146
|
+
}
|
|
147
|
+
static parse(pattern) {
|
|
148
|
+
let result = 0;
|
|
149
|
+
let valid = false;
|
|
150
|
+
pattern.replace(_Duration.kCommaRegex, "").replace(_Duration.kAanRegex, "1").replace(_Duration.kPatternRegex, (_, i, units) => {
|
|
151
|
+
const token = tokens.get(units);
|
|
152
|
+
if (token !== void 0) {
|
|
153
|
+
result += Number(i) * token;
|
|
154
|
+
valid = true;
|
|
155
|
+
}
|
|
156
|
+
return "";
|
|
157
|
+
});
|
|
158
|
+
return valid ? result : NaN;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var Duration = _Duration;
|
|
162
|
+
__name(Duration, "Duration");
|
|
163
|
+
__publicField(Duration, "kPatternRegex", /(-?\d*\.?\d+(?:e[-+]?\d+)?)\s*([a-zΞΌ]*)/gi);
|
|
164
|
+
__publicField(Duration, "kCommaRegex", /,/g);
|
|
165
|
+
__publicField(Duration, "kAanRegex", /\ban?\b/gi);
|
|
166
|
+
|
|
167
|
+
// src/lib/DurationFormatter.ts
|
|
168
|
+
var kTimeDurations = [
|
|
169
|
+
["year" /* Year */, 31536e6],
|
|
170
|
+
["month" /* Month */, 2628e6],
|
|
171
|
+
["week" /* Week */, 1e3 * 60 * 60 * 24 * 7],
|
|
172
|
+
["day" /* Day */, 1e3 * 60 * 60 * 24],
|
|
173
|
+
["hour" /* Hour */, 1e3 * 60 * 60],
|
|
174
|
+
["minute" /* Minute */, 1e3 * 60],
|
|
175
|
+
["second" /* Second */, 1e3]
|
|
176
|
+
];
|
|
177
|
+
var DurationFormatter = class {
|
|
178
|
+
constructor(units = DEFAULT_UNITS) {
|
|
179
|
+
this.units = units;
|
|
180
|
+
}
|
|
181
|
+
format(duration, precision = 7, {
|
|
182
|
+
left: leftSeparator = DEFAULT_SEPARATORS.left,
|
|
183
|
+
right: rightSeparator = DEFAULT_SEPARATORS.right
|
|
184
|
+
} = DEFAULT_SEPARATORS) {
|
|
185
|
+
const output = [];
|
|
186
|
+
const negative = duration < 0;
|
|
187
|
+
if (negative)
|
|
188
|
+
duration *= -1;
|
|
189
|
+
for (const [type, timeDuration] of kTimeDurations) {
|
|
190
|
+
const division = duration / timeDuration;
|
|
191
|
+
if (division < 1)
|
|
192
|
+
continue;
|
|
193
|
+
const floored = Math.floor(division);
|
|
194
|
+
duration -= floored * timeDuration;
|
|
195
|
+
output.push(addUnit(floored, this.units[type], leftSeparator));
|
|
196
|
+
if (output.length >= precision)
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
return `${negative ? "-" : ""}${output.join(rightSeparator) || addUnit(0, this.units.second, leftSeparator)}`;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
__name(DurationFormatter, "DurationFormatter");
|
|
203
|
+
function addUnit(time, unit, separator) {
|
|
204
|
+
if (Reflect.has(unit, time))
|
|
205
|
+
return `${time}${separator}${Reflect.get(unit, time)}`;
|
|
206
|
+
return `${time}${separator}${unit.DEFAULT}`;
|
|
207
|
+
}
|
|
208
|
+
__name(addUnit, "addUnit");
|
|
209
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
210
|
+
0 && (module.exports = {
|
|
211
|
+
DEFAULT_SEPARATORS,
|
|
212
|
+
DEFAULT_UNITS,
|
|
213
|
+
Duration,
|
|
214
|
+
DurationFormatter,
|
|
215
|
+
Time,
|
|
216
|
+
TimeTypes
|
|
217
|
+
});
|
|
218
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/constants.ts","../src/lib/Duration.ts","../src/lib/DurationFormatter.ts"],"sourcesContent":["export * from './lib/constants';\nexport * from './lib/Duration';\nexport * from './lib/DurationFormatter';\n","import type { DurationFormatAssetsTime, DurationFormatSeparators } from './DurationFormatter';\n\nexport enum Time {\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = 1000 * 60,\n\tHour = 1000 * 60 * 60,\n\tDay = 1000 * 60 * 60 * 24,\n\tMonth = 1000 * 60 * 60 * 24 * (365 / 12),\n\tYear = 1000 * 60 * 60 * 24 * 365\n}\n\n/**\n * The supported time types\n */\nexport enum TimeTypes {\n\tSecond = 'second',\n\tMinute = 'minute',\n\tHour = 'hour',\n\tDay = 'day',\n\tWeek = 'week',\n\tMonth = 'month',\n\tYear = 'year'\n}\n\nexport const DEFAULT_UNITS: DurationFormatAssetsTime = {\n\t[TimeTypes.Year]: {\n\t\t1: 'year',\n\t\tDEFAULT: 'years'\n\t},\n\t[TimeTypes.Month]: {\n\t\t1: 'month',\n\t\tDEFAULT: 'months'\n\t},\n\t[TimeTypes.Week]: {\n\t\t1: 'week',\n\t\tDEFAULT: 'weeks'\n\t},\n\t[TimeTypes.Day]: {\n\t\t1: 'day',\n\t\tDEFAULT: 'days'\n\t},\n\t[TimeTypes.Hour]: {\n\t\t1: 'hour',\n\t\tDEFAULT: 'hours'\n\t},\n\t[TimeTypes.Minute]: {\n\t\t1: 'minute',\n\t\tDEFAULT: 'minutes'\n\t},\n\t[TimeTypes.Second]: {\n\t\t1: 'second',\n\t\tDEFAULT: 'seconds'\n\t}\n};\n\nexport const DEFAULT_SEPARATORS: DurationFormatSeparators = {\n\tleft: ' ',\n\tright: ' '\n};\n","/* eslint-disable @typescript-eslint/restrict-plus-operands */\nconst tokens = new Map([\n\t['nanosecond', 1 / 1e6],\n\t['nanoseconds', 1 / 1e6],\n\t['ns', 1 / 1e6],\n\n\t['millisecond', 1],\n\t['milliseconds', 1],\n\t['ms', 1],\n\n\t['second', 1000],\n\t['seconds', 1000],\n\t['sec', 1000],\n\t['secs', 1000],\n\t['s', 1000],\n\n\t['minute', 1000 * 60],\n\t['minutes', 1000 * 60],\n\t['min', 1000 * 60],\n\t['mins', 1000 * 60],\n\t['m', 1000 * 60],\n\n\t['hour', 1000 * 60 * 60],\n\t['hours', 1000 * 60 * 60],\n\t['hr', 1000 * 60 * 60],\n\t['hrs', 1000 * 60 * 60],\n\t['h', 1000 * 60 * 60],\n\n\t['day', 1000 * 60 * 60 * 24],\n\t['days', 1000 * 60 * 60 * 24],\n\t['d', 1000 * 60 * 60 * 24],\n\n\t['week', 1000 * 60 * 60 * 24 * 7],\n\t['weeks', 1000 * 60 * 60 * 24 * 7],\n\t['wk', 1000 * 60 * 60 * 24 * 7],\n\t['wks', 1000 * 60 * 60 * 24 * 7],\n\t['w', 1000 * 60 * 60 * 24 * 7],\n\n\t['month', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\t['months', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\t['b', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\t['mo', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\n\t['year', 1000 * 60 * 60 * 24 * 365.25],\n\t['years', 1000 * 60 * 60 * 24 * 365.25],\n\t['yr', 1000 * 60 * 60 * 24 * 365.25],\n\t['yrs', 1000 * 60 * 60 * 24 * 365.25],\n\t['y', 1000 * 60 * 60 * 24 * 365.25]\n]);\n\n/**\n * Converts duration strings into ms and future dates\n */\nexport class Duration {\n\t/**\n\t * The offset\n\t */\n\tpublic offset: number;\n\n\t/**\n\t * Create a new Duration instance\n\t * @param pattern The string to parse\n\t */\n\tpublic constructor(pattern: string) {\n\t\tthis.offset = Duration.parse(pattern.toLowerCase());\n\t}\n\n\t/**\n\t * Get the date from now\n\t */\n\tpublic get fromNow(): Date {\n\t\treturn this.dateFrom(new Date());\n\t}\n\n\t/**\n\t * Get the date from\n\t * @param date The Date instance to get the date from\n\t */\n\tpublic dateFrom(date: Date): Date {\n\t\treturn new Date(date.getTime() + this.offset);\n\t}\n\n\t/**\n\t * The RegExp used for the pattern parsing\n\t */\n\tprivate static readonly kPatternRegex = /(-?\\d*\\.?\\d+(?:e[-+]?\\d+)?)\\s*([a-zΞΌ]*)/gi;\n\n\t/**\n\t * The RegExp used for removing commas\n\t */\n\tprivate static readonly kCommaRegex = /,/g;\n\n\t/**\n\t * The RegExp used for replacing a/an with 1\n\t */\n\tprivate static readonly kAanRegex = /\\ban?\\b/gi;\n\n\t/**\n\t * Parse the pattern\n\t * @param pattern The pattern to parse\n\t */\n\tprivate static parse(pattern: string): number {\n\t\tlet result = 0;\n\t\tlet valid = false;\n\n\t\tpattern\n\t\t\t// ignore commas\n\t\t\t.replace(Duration.kCommaRegex, '')\n\t\t\t// a / an = 1\n\t\t\t.replace(Duration.kAanRegex, '1')\n\t\t\t// do math\n\t\t\t.replace(Duration.kPatternRegex, (_, i, units) => {\n\t\t\t\tconst token = tokens.get(units);\n\t\t\t\tif (token !== undefined) {\n\t\t\t\t\tresult += Number(i) * token;\n\t\t\t\t\tvalid = true;\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t});\n\n\t\treturn valid ? result : NaN;\n\t}\n}\n","import { DEFAULT_SEPARATORS, DEFAULT_UNITS, TimeTypes } from './constants';\n\n/**\n * The duration of each time type in milliseconds\n */\nconst kTimeDurations: readonly [TimeTypes, number][] = [\n\t[TimeTypes.Year, 31536000000],\n\t// 29.53059 days is the official duration of a month: https://en.wikipedia.org/wiki/Month\n\t[TimeTypes.Month, 2628000000],\n\t[TimeTypes.Week, 1000 * 60 * 60 * 24 * 7],\n\t[TimeTypes.Day, 1000 * 60 * 60 * 24],\n\t[TimeTypes.Hour, 1000 * 60 * 60],\n\t[TimeTypes.Minute, 1000 * 60],\n\t[TimeTypes.Second, 1000]\n];\n\n/**\n * Display the duration\n * @param duration The duration in milliseconds to parse and display\n * @param assets The language assets\n */\nexport class DurationFormatter {\n\tpublic constructor(public units: DurationFormatAssetsTime = DEFAULT_UNITS) {}\n\n\tpublic format(\n\t\tduration: number,\n\t\tprecision = 7,\n\t\t{\n\t\t\tleft: leftSeparator = DEFAULT_SEPARATORS.left,\n\t\t\tright: rightSeparator = DEFAULT_SEPARATORS.right\n\t\t}: DurationFormatSeparators = DEFAULT_SEPARATORS\n\t) {\n\t\tconst output: string[] = [];\n\t\tconst negative = duration < 0;\n\t\tif (negative) duration *= -1;\n\n\t\tfor (const [type, timeDuration] of kTimeDurations) {\n\t\t\tconst division = duration / timeDuration;\n\t\t\tif (division < 1) continue;\n\n\t\t\tconst floored = Math.floor(division);\n\t\t\tduration -= floored * timeDuration;\n\t\t\toutput.push(addUnit(floored, this.units[type], leftSeparator!));\n\n\t\t\t// If the output has enough precision, break\n\t\t\tif (output.length >= precision) break;\n\t\t}\n\n\t\treturn `${negative ? '-' : ''}${output.join(rightSeparator) || addUnit(0, this.units.second, leftSeparator!)}`;\n\t}\n}\n\n/**\n * Adds an unit, if non zero\n * @param time The duration of said unit\n * @param unit The unit language assets\n */\nfunction addUnit(time: number, unit: DurationFormatAssetsUnit, separator: string) {\n\tif (Reflect.has(unit, time)) return `${time}${separator}${Reflect.get(unit, time)}`;\n\treturn `${time}${separator}${unit.DEFAULT}`;\n}\n\nexport interface DurationFormatSeparators {\n\tleft?: string;\n\tright?: string;\n}\n\nexport interface DurationFormatAssetsUnit extends Record<number, string> {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tDEFAULT: string;\n}\n\nexport interface DurationFormatAssetsTime {\n\t[TimeTypes.Second]: DurationFormatAssetsUnit;\n\t[TimeTypes.Minute]: DurationFormatAssetsUnit;\n\t[TimeTypes.Hour]: DurationFormatAssetsUnit;\n\t[TimeTypes.Day]: DurationFormatAssetsUnit;\n\t[TimeTypes.Week]: DurationFormatAssetsUnit;\n\t[TimeTypes.Month]: DurationFormatAssetsUnit;\n\t[TimeTypes.Year]: DurationFormatAssetsUnit;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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AC5B,oBAAiB,MAAO,KAAK,KAAK,KAAK,CAAC;AAAA,EACxC,kBAAgB,MAAO,KAAK,KAAK,EAAE;AAAA,EACnC,oBAAiB,MAAO,KAAK,EAAE;AAAA,EAC/B,wBAAmB,MAAO,EAAE;AAAA,EAC5B,wBAAmB,GAAI;AACxB;AAOO,IAAM,oBAAN,MAAwB;AAAA,EACvB,YAAmB,QAAkC,eAAe;AAAjD;AAAA,EAAkD;AAAA,EAErE,OACN,UACA,YAAY,GACZ;AAAA,IACC,MAAM,gBAAgB,mBAAmB;AAAA,IACzC,OAAO,iBAAiB,mBAAmB;AAAA,EAC5C,IAA8B,oBAC7B;AACD,UAAM,SAAmB,CAAC;AAC1B,UAAM,WAAW,WAAW;AAC5B,QAAI;AAAU,kBAAY;AAE1B,eAAW,CAAC,MAAM,YAAY,KAAK,gBAAgB;AAClD,YAAM,WAAW,WAAW;AAC5B,UAAI,WAAW;AAAG;AAElB,YAAM,UAAU,KAAK,MAAM,QAAQ;AACnC,kBAAY,UAAU;AACtB,aAAO,KAAK,QAAQ,SAAS,KAAK,MAAM,OAAO,aAAc,CAAC;AAG9D,UAAI,OAAO,UAAU;AAAW;AAAA,IACjC;AAEA,WAAO,GAAG,WAAW,MAAM,KAAK,OAAO,KAAK,cAAc,KAAK,QAAQ,GAAG,KAAK,MAAM,QAAQ,aAAc;AAAA,EAC5G;AACD;AA7Ba;AAoCb,SAAS,QAAQ,MAAc,MAAgC,WAAmB;AACjF,MAAI,QAAQ,IAAI,MAAM,IAAI;AAAG,WAAO,GAAG,OAAO,YAAY,QAAQ,IAAI,MAAM,IAAI;AAChF,SAAO,GAAG,OAAO,YAAY,KAAK;AACnC;AAHS;","names":["Time","TimeTypes"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/lib/constants.ts
|
|
10
|
+
var Time = /* @__PURE__ */ ((Time2) => {
|
|
11
|
+
Time2[Time2["Millisecond"] = 1] = "Millisecond";
|
|
12
|
+
Time2[Time2["Second"] = 1e3] = "Second";
|
|
13
|
+
Time2[Time2["Minute"] = 6e4] = "Minute";
|
|
14
|
+
Time2[Time2["Hour"] = 36e5] = "Hour";
|
|
15
|
+
Time2[Time2["Day"] = 864e5] = "Day";
|
|
16
|
+
Time2[Time2["Month"] = 2628e6] = "Month";
|
|
17
|
+
Time2[Time2["Year"] = 31536e6] = "Year";
|
|
18
|
+
return Time2;
|
|
19
|
+
})(Time || {});
|
|
20
|
+
var TimeTypes = /* @__PURE__ */ ((TimeTypes2) => {
|
|
21
|
+
TimeTypes2["Second"] = "second";
|
|
22
|
+
TimeTypes2["Minute"] = "minute";
|
|
23
|
+
TimeTypes2["Hour"] = "hour";
|
|
24
|
+
TimeTypes2["Day"] = "day";
|
|
25
|
+
TimeTypes2["Week"] = "week";
|
|
26
|
+
TimeTypes2["Month"] = "month";
|
|
27
|
+
TimeTypes2["Year"] = "year";
|
|
28
|
+
return TimeTypes2;
|
|
29
|
+
})(TimeTypes || {});
|
|
30
|
+
var DEFAULT_UNITS = {
|
|
31
|
+
["year" /* Year */]: {
|
|
32
|
+
1: "year",
|
|
33
|
+
DEFAULT: "years"
|
|
34
|
+
},
|
|
35
|
+
["month" /* Month */]: {
|
|
36
|
+
1: "month",
|
|
37
|
+
DEFAULT: "months"
|
|
38
|
+
},
|
|
39
|
+
["week" /* Week */]: {
|
|
40
|
+
1: "week",
|
|
41
|
+
DEFAULT: "weeks"
|
|
42
|
+
},
|
|
43
|
+
["day" /* Day */]: {
|
|
44
|
+
1: "day",
|
|
45
|
+
DEFAULT: "days"
|
|
46
|
+
},
|
|
47
|
+
["hour" /* Hour */]: {
|
|
48
|
+
1: "hour",
|
|
49
|
+
DEFAULT: "hours"
|
|
50
|
+
},
|
|
51
|
+
["minute" /* Minute */]: {
|
|
52
|
+
1: "minute",
|
|
53
|
+
DEFAULT: "minutes"
|
|
54
|
+
},
|
|
55
|
+
["second" /* Second */]: {
|
|
56
|
+
1: "second",
|
|
57
|
+
DEFAULT: "seconds"
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var DEFAULT_SEPARATORS = {
|
|
61
|
+
left: " ",
|
|
62
|
+
right: " "
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/lib/Duration.ts
|
|
66
|
+
var tokens = /* @__PURE__ */ new Map([
|
|
67
|
+
["nanosecond", 1 / 1e6],
|
|
68
|
+
["nanoseconds", 1 / 1e6],
|
|
69
|
+
["ns", 1 / 1e6],
|
|
70
|
+
["millisecond", 1],
|
|
71
|
+
["milliseconds", 1],
|
|
72
|
+
["ms", 1],
|
|
73
|
+
["second", 1e3],
|
|
74
|
+
["seconds", 1e3],
|
|
75
|
+
["sec", 1e3],
|
|
76
|
+
["secs", 1e3],
|
|
77
|
+
["s", 1e3],
|
|
78
|
+
["minute", 1e3 * 60],
|
|
79
|
+
["minutes", 1e3 * 60],
|
|
80
|
+
["min", 1e3 * 60],
|
|
81
|
+
["mins", 1e3 * 60],
|
|
82
|
+
["m", 1e3 * 60],
|
|
83
|
+
["hour", 1e3 * 60 * 60],
|
|
84
|
+
["hours", 1e3 * 60 * 60],
|
|
85
|
+
["hr", 1e3 * 60 * 60],
|
|
86
|
+
["hrs", 1e3 * 60 * 60],
|
|
87
|
+
["h", 1e3 * 60 * 60],
|
|
88
|
+
["day", 1e3 * 60 * 60 * 24],
|
|
89
|
+
["days", 1e3 * 60 * 60 * 24],
|
|
90
|
+
["d", 1e3 * 60 * 60 * 24],
|
|
91
|
+
["week", 1e3 * 60 * 60 * 24 * 7],
|
|
92
|
+
["weeks", 1e3 * 60 * 60 * 24 * 7],
|
|
93
|
+
["wk", 1e3 * 60 * 60 * 24 * 7],
|
|
94
|
+
["wks", 1e3 * 60 * 60 * 24 * 7],
|
|
95
|
+
["w", 1e3 * 60 * 60 * 24 * 7],
|
|
96
|
+
["month", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
97
|
+
["months", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
98
|
+
["b", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
99
|
+
["mo", 1e3 * 60 * 60 * 24 * (365.25 / 12)],
|
|
100
|
+
["year", 1e3 * 60 * 60 * 24 * 365.25],
|
|
101
|
+
["years", 1e3 * 60 * 60 * 24 * 365.25],
|
|
102
|
+
["yr", 1e3 * 60 * 60 * 24 * 365.25],
|
|
103
|
+
["yrs", 1e3 * 60 * 60 * 24 * 365.25],
|
|
104
|
+
["y", 1e3 * 60 * 60 * 24 * 365.25]
|
|
105
|
+
]);
|
|
106
|
+
var _Duration = class {
|
|
107
|
+
constructor(pattern) {
|
|
108
|
+
__publicField(this, "offset");
|
|
109
|
+
this.offset = _Duration.parse(pattern.toLowerCase());
|
|
110
|
+
}
|
|
111
|
+
get fromNow() {
|
|
112
|
+
return this.dateFrom(new Date());
|
|
113
|
+
}
|
|
114
|
+
dateFrom(date) {
|
|
115
|
+
return new Date(date.getTime() + this.offset);
|
|
116
|
+
}
|
|
117
|
+
static parse(pattern) {
|
|
118
|
+
let result = 0;
|
|
119
|
+
let valid = false;
|
|
120
|
+
pattern.replace(_Duration.kCommaRegex, "").replace(_Duration.kAanRegex, "1").replace(_Duration.kPatternRegex, (_, i, units) => {
|
|
121
|
+
const token = tokens.get(units);
|
|
122
|
+
if (token !== void 0) {
|
|
123
|
+
result += Number(i) * token;
|
|
124
|
+
valid = true;
|
|
125
|
+
}
|
|
126
|
+
return "";
|
|
127
|
+
});
|
|
128
|
+
return valid ? result : NaN;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
var Duration = _Duration;
|
|
132
|
+
__name(Duration, "Duration");
|
|
133
|
+
__publicField(Duration, "kPatternRegex", /(-?\d*\.?\d+(?:e[-+]?\d+)?)\s*([a-zΞΌ]*)/gi);
|
|
134
|
+
__publicField(Duration, "kCommaRegex", /,/g);
|
|
135
|
+
__publicField(Duration, "kAanRegex", /\ban?\b/gi);
|
|
136
|
+
|
|
137
|
+
// src/lib/DurationFormatter.ts
|
|
138
|
+
var kTimeDurations = [
|
|
139
|
+
["year" /* Year */, 31536e6],
|
|
140
|
+
["month" /* Month */, 2628e6],
|
|
141
|
+
["week" /* Week */, 1e3 * 60 * 60 * 24 * 7],
|
|
142
|
+
["day" /* Day */, 1e3 * 60 * 60 * 24],
|
|
143
|
+
["hour" /* Hour */, 1e3 * 60 * 60],
|
|
144
|
+
["minute" /* Minute */, 1e3 * 60],
|
|
145
|
+
["second" /* Second */, 1e3]
|
|
146
|
+
];
|
|
147
|
+
var DurationFormatter = class {
|
|
148
|
+
constructor(units = DEFAULT_UNITS) {
|
|
149
|
+
this.units = units;
|
|
150
|
+
}
|
|
151
|
+
format(duration, precision = 7, {
|
|
152
|
+
left: leftSeparator = DEFAULT_SEPARATORS.left,
|
|
153
|
+
right: rightSeparator = DEFAULT_SEPARATORS.right
|
|
154
|
+
} = DEFAULT_SEPARATORS) {
|
|
155
|
+
const output = [];
|
|
156
|
+
const negative = duration < 0;
|
|
157
|
+
if (negative)
|
|
158
|
+
duration *= -1;
|
|
159
|
+
for (const [type, timeDuration] of kTimeDurations) {
|
|
160
|
+
const division = duration / timeDuration;
|
|
161
|
+
if (division < 1)
|
|
162
|
+
continue;
|
|
163
|
+
const floored = Math.floor(division);
|
|
164
|
+
duration -= floored * timeDuration;
|
|
165
|
+
output.push(addUnit(floored, this.units[type], leftSeparator));
|
|
166
|
+
if (output.length >= precision)
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
return `${negative ? "-" : ""}${output.join(rightSeparator) || addUnit(0, this.units.second, leftSeparator)}`;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
__name(DurationFormatter, "DurationFormatter");
|
|
173
|
+
function addUnit(time, unit, separator) {
|
|
174
|
+
if (Reflect.has(unit, time))
|
|
175
|
+
return `${time}${separator}${Reflect.get(unit, time)}`;
|
|
176
|
+
return `${time}${separator}${unit.DEFAULT}`;
|
|
177
|
+
}
|
|
178
|
+
__name(addUnit, "addUnit");
|
|
179
|
+
export {
|
|
180
|
+
DEFAULT_SEPARATORS,
|
|
181
|
+
DEFAULT_UNITS,
|
|
182
|
+
Duration,
|
|
183
|
+
DurationFormatter,
|
|
184
|
+
Time,
|
|
185
|
+
TimeTypes
|
|
186
|
+
};
|
|
187
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/constants.ts","../src/lib/Duration.ts","../src/lib/DurationFormatter.ts"],"sourcesContent":["import type { DurationFormatAssetsTime, DurationFormatSeparators } from './DurationFormatter';\n\nexport enum Time {\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = 1000 * 60,\n\tHour = 1000 * 60 * 60,\n\tDay = 1000 * 60 * 60 * 24,\n\tMonth = 1000 * 60 * 60 * 24 * (365 / 12),\n\tYear = 1000 * 60 * 60 * 24 * 365\n}\n\n/**\n * The supported time types\n */\nexport enum TimeTypes {\n\tSecond = 'second',\n\tMinute = 'minute',\n\tHour = 'hour',\n\tDay = 'day',\n\tWeek = 'week',\n\tMonth = 'month',\n\tYear = 'year'\n}\n\nexport const DEFAULT_UNITS: DurationFormatAssetsTime = {\n\t[TimeTypes.Year]: {\n\t\t1: 'year',\n\t\tDEFAULT: 'years'\n\t},\n\t[TimeTypes.Month]: {\n\t\t1: 'month',\n\t\tDEFAULT: 'months'\n\t},\n\t[TimeTypes.Week]: {\n\t\t1: 'week',\n\t\tDEFAULT: 'weeks'\n\t},\n\t[TimeTypes.Day]: {\n\t\t1: 'day',\n\t\tDEFAULT: 'days'\n\t},\n\t[TimeTypes.Hour]: {\n\t\t1: 'hour',\n\t\tDEFAULT: 'hours'\n\t},\n\t[TimeTypes.Minute]: {\n\t\t1: 'minute',\n\t\tDEFAULT: 'minutes'\n\t},\n\t[TimeTypes.Second]: {\n\t\t1: 'second',\n\t\tDEFAULT: 'seconds'\n\t}\n};\n\nexport const DEFAULT_SEPARATORS: DurationFormatSeparators = {\n\tleft: ' ',\n\tright: ' '\n};\n","/* eslint-disable @typescript-eslint/restrict-plus-operands */\nconst tokens = new Map([\n\t['nanosecond', 1 / 1e6],\n\t['nanoseconds', 1 / 1e6],\n\t['ns', 1 / 1e6],\n\n\t['millisecond', 1],\n\t['milliseconds', 1],\n\t['ms', 1],\n\n\t['second', 1000],\n\t['seconds', 1000],\n\t['sec', 1000],\n\t['secs', 1000],\n\t['s', 1000],\n\n\t['minute', 1000 * 60],\n\t['minutes', 1000 * 60],\n\t['min', 1000 * 60],\n\t['mins', 1000 * 60],\n\t['m', 1000 * 60],\n\n\t['hour', 1000 * 60 * 60],\n\t['hours', 1000 * 60 * 60],\n\t['hr', 1000 * 60 * 60],\n\t['hrs', 1000 * 60 * 60],\n\t['h', 1000 * 60 * 60],\n\n\t['day', 1000 * 60 * 60 * 24],\n\t['days', 1000 * 60 * 60 * 24],\n\t['d', 1000 * 60 * 60 * 24],\n\n\t['week', 1000 * 60 * 60 * 24 * 7],\n\t['weeks', 1000 * 60 * 60 * 24 * 7],\n\t['wk', 1000 * 60 * 60 * 24 * 7],\n\t['wks', 1000 * 60 * 60 * 24 * 7],\n\t['w', 1000 * 60 * 60 * 24 * 7],\n\n\t['month', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\t['months', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\t['b', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\t['mo', 1000 * 60 * 60 * 24 * (365.25 / 12)],\n\n\t['year', 1000 * 60 * 60 * 24 * 365.25],\n\t['years', 1000 * 60 * 60 * 24 * 365.25],\n\t['yr', 1000 * 60 * 60 * 24 * 365.25],\n\t['yrs', 1000 * 60 * 60 * 24 * 365.25],\n\t['y', 1000 * 60 * 60 * 24 * 365.25]\n]);\n\n/**\n * Converts duration strings into ms and future dates\n */\nexport class Duration {\n\t/**\n\t * The offset\n\t */\n\tpublic offset: number;\n\n\t/**\n\t * Create a new Duration instance\n\t * @param pattern The string to parse\n\t */\n\tpublic constructor(pattern: string) {\n\t\tthis.offset = Duration.parse(pattern.toLowerCase());\n\t}\n\n\t/**\n\t * Get the date from now\n\t */\n\tpublic get fromNow(): Date {\n\t\treturn this.dateFrom(new Date());\n\t}\n\n\t/**\n\t * Get the date from\n\t * @param date The Date instance to get the date from\n\t */\n\tpublic dateFrom(date: Date): Date {\n\t\treturn new Date(date.getTime() + this.offset);\n\t}\n\n\t/**\n\t * The RegExp used for the pattern parsing\n\t */\n\tprivate static readonly kPatternRegex = /(-?\\d*\\.?\\d+(?:e[-+]?\\d+)?)\\s*([a-zΞΌ]*)/gi;\n\n\t/**\n\t * The RegExp used for removing commas\n\t */\n\tprivate static readonly kCommaRegex = /,/g;\n\n\t/**\n\t * The RegExp used for replacing a/an with 1\n\t */\n\tprivate static readonly kAanRegex = /\\ban?\\b/gi;\n\n\t/**\n\t * Parse the pattern\n\t * @param pattern The pattern to parse\n\t */\n\tprivate static parse(pattern: string): number {\n\t\tlet result = 0;\n\t\tlet valid = false;\n\n\t\tpattern\n\t\t\t// ignore commas\n\t\t\t.replace(Duration.kCommaRegex, '')\n\t\t\t// a / an = 1\n\t\t\t.replace(Duration.kAanRegex, '1')\n\t\t\t// do math\n\t\t\t.replace(Duration.kPatternRegex, (_, i, units) => {\n\t\t\t\tconst token = tokens.get(units);\n\t\t\t\tif (token !== undefined) {\n\t\t\t\t\tresult += Number(i) * token;\n\t\t\t\t\tvalid = true;\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t});\n\n\t\treturn valid ? result : NaN;\n\t}\n}\n","import { DEFAULT_SEPARATORS, DEFAULT_UNITS, TimeTypes } from './constants';\n\n/**\n * The duration of each time type in milliseconds\n */\nconst kTimeDurations: readonly [TimeTypes, number][] = [\n\t[TimeTypes.Year, 31536000000],\n\t// 29.53059 days is the official duration of a month: https://en.wikipedia.org/wiki/Month\n\t[TimeTypes.Month, 2628000000],\n\t[TimeTypes.Week, 1000 * 60 * 60 * 24 * 7],\n\t[TimeTypes.Day, 1000 * 60 * 60 * 24],\n\t[TimeTypes.Hour, 1000 * 60 * 60],\n\t[TimeTypes.Minute, 1000 * 60],\n\t[TimeTypes.Second, 1000]\n];\n\n/**\n * Display the duration\n * @param duration The duration in milliseconds to parse and display\n * @param assets The language assets\n */\nexport class DurationFormatter {\n\tpublic constructor(public units: DurationFormatAssetsTime = DEFAULT_UNITS) {}\n\n\tpublic format(\n\t\tduration: number,\n\t\tprecision = 7,\n\t\t{\n\t\t\tleft: leftSeparator = DEFAULT_SEPARATORS.left,\n\t\t\tright: rightSeparator = DEFAULT_SEPARATORS.right\n\t\t}: DurationFormatSeparators = DEFAULT_SEPARATORS\n\t) {\n\t\tconst output: string[] = [];\n\t\tconst negative = duration < 0;\n\t\tif (negative) duration *= -1;\n\n\t\tfor (const [type, timeDuration] of kTimeDurations) {\n\t\t\tconst division = duration / timeDuration;\n\t\t\tif (division < 1) continue;\n\n\t\t\tconst floored = Math.floor(division);\n\t\t\tduration -= floored * timeDuration;\n\t\t\toutput.push(addUnit(floored, this.units[type], leftSeparator!));\n\n\t\t\t// If the output has enough precision, break\n\t\t\tif (output.length >= precision) break;\n\t\t}\n\n\t\treturn `${negative ? '-' : ''}${output.join(rightSeparator) || addUnit(0, this.units.second, leftSeparator!)}`;\n\t}\n}\n\n/**\n * Adds an unit, if non zero\n * @param time The duration of said unit\n * @param unit The unit language assets\n */\nfunction addUnit(time: number, unit: DurationFormatAssetsUnit, separator: string) {\n\tif (Reflect.has(unit, time)) return `${time}${separator}${Reflect.get(unit, time)}`;\n\treturn `${time}${separator}${unit.DEFAULT}`;\n}\n\nexport interface DurationFormatSeparators {\n\tleft?: string;\n\tright?: string;\n}\n\nexport interface DurationFormatAssetsUnit extends Record<number, string> {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tDEFAULT: string;\n}\n\nexport interface DurationFormatAssetsTime {\n\t[TimeTypes.Second]: DurationFormatAssetsUnit;\n\t[TimeTypes.Minute]: DurationFormatAssetsUnit;\n\t[TimeTypes.Hour]: DurationFormatAssetsUnit;\n\t[TimeTypes.Day]: DurationFormatAssetsUnit;\n\t[TimeTypes.Week]: DurationFormatAssetsUnit;\n\t[TimeTypes.Month]: DurationFormatAssetsUnit;\n\t[TimeTypes.Year]: DurationFormatAssetsUnit;\n}\n"],"mappings":";;;;;;;;;AAEO,IAAK,OAAL,kBAAKA,UAAL;AACN,EAAAA,YAAA,iBAAc,KAAd;AACA,EAAAA,YAAA,YAAS,OAAT;AACA,EAAAA,YAAA,YAAS,OAAT;AACA,EAAAA,YAAA,UAAO,QAAP;AACA,EAAAA,YAAA,SAAM,SAAN;AACA,EAAAA,YAAA,WAAQ,UAAR;AACA,EAAAA,YAAA,UAAO,WAAP;AAPW,SAAAA;AAAA,GAAA;AAaL,IAAK,YAAL,kBAAKC,eAAL;AACN,EAAAA,WAAA,YAAS;AACT,EAAAA,WAAA,YAAS;AACT,EAAAA,WAAA,UAAO;AACP,EAAAA,WAAA,SAAM;AACN,EAAAA,WAAA,UAAO;AACP,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,UAAO;AAPI,SAAAA;AAAA,GAAA;AAUL,IAAM,gBAA0C;AAAA,EACtD,CAAC,oBAAiB;AAAA,IACjB,GAAG;AAAA,IACH,SAAS;AAAA,EACV;AAAA,EACA,CAAC,sBAAkB;AAAA,IAClB,GAAG;AAAA,IACH,SAAS;AAAA,EACV;AAAA,EACA,CAAC,oBAAiB;AAAA,IACjB,GAAG;AAAA,IACH,SAAS;AAAA,EACV;AAAA,EACA,CAAC,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AW,MAAM,KAAK,OAAO,KAAK,cAAc,KAAK,QAAQ,GAAG,KAAK,MAAM,QAAQ,aAAc;AAAA,EAC5G;AACD;AA7Ba;AAoCb,SAAS,QAAQ,MAAc,MAAgC,WAAmB;AACjF,MAAI,QAAQ,IAAI,MAAM,IAAI;AAAG,WAAO,GAAG,OAAO,YAAY,QAAQ,IAAI,MAAM,IAAI;AAChF,SAAO,GAAG,OAAO,YAAY,KAAK;AACnC;AAHS;","names":["Time","TimeTypes"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sapphire/duration",
|
|
3
|
+
"version": "1.0.1-next.574299a.0",
|
|
4
|
+
"description": "A time duration utility library for JavaScript.",
|
|
5
|
+
"author": "@sapphire",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.mjs",
|
|
9
|
+
"browser": "dist/index.global.js",
|
|
10
|
+
"unpkg": "dist/index.global.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/duration",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"docs": "typedoc-json-parser",
|
|
24
|
+
"prepack": "yarn build",
|
|
25
|
+
"bump": "cliff-jumper",
|
|
26
|
+
"check-update": "cliff-jumper --dry-run"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/sapphiredev/utilities.git",
|
|
31
|
+
"directory": "packages/duration"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/**/*.js*",
|
|
35
|
+
"dist/**/*.mjs*",
|
|
36
|
+
"dist/**/*.d*"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=v14.0.0",
|
|
40
|
+
"npm": ">=7.0.0"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"@sapphire/duration",
|
|
44
|
+
"duration",
|
|
45
|
+
"bot",
|
|
46
|
+
"typescript",
|
|
47
|
+
"ts",
|
|
48
|
+
"yarn",
|
|
49
|
+
"discord",
|
|
50
|
+
"sapphire",
|
|
51
|
+
"standalone"
|
|
52
|
+
],
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/sapphiredev/utilities/issues"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@favware/cliff-jumper": "^1.8.7",
|
|
61
|
+
"@vitest/coverage-c8": "^0.23.4",
|
|
62
|
+
"tsup": "^6.2.3",
|
|
63
|
+
"typedoc": "^0.23.14",
|
|
64
|
+
"typedoc-json-parser": "^4.0.0",
|
|
65
|
+
"typescript": "^4.8.3",
|
|
66
|
+
"vitest": "^0.23.4"
|
|
67
|
+
}
|
|
68
|
+
}
|