@sodiumlabs/duration 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sodiumlabs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ <div align="center">
2
+ <h1>@sodiumlabs/duration</h1>
3
+ <p>
4
+ <a href="https://discord.gg/8PDXWSHH7k"><img src="https://img.shields.io/badge/join_us-on_discord-5865F2?logo=discord&logoColor=white" alt="Discord server" /></a>
5
+ <a href="https://www.npmjs.com/package/@sodiumlabs/duration"><img src="https://img.shields.io/npm/v/@sodiumlabs/duration.svg?maxAge=3600" alt="npm version" /></a>
6
+ <a href="https://www.npmjs.com/package/@sodiumlabs/duration"><img src="https://img.shields.io/npm/dt/@sodiumlabs/duration.svg?maxAge=3600" alt="npm downloads" /></a>
7
+ <a href="https://github.com/sodium-labs/duration/commits/main"><img alt="Last commit" src="https://img.shields.io/github/last-commit/sodium-labs/duration?logo=github&logoColor=ffffff" /></a>
8
+ </p>
9
+ </div>
10
+
11
+ ## About
12
+
13
+ Time and duration utility package.
14
+
15
+ ## Installation
16
+
17
+ Node.js 18 or newer is required.
18
+
19
+ ```sh
20
+ npm install @sodiumlabs/duration
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```ts
26
+ import { Time } from "@sodiumlabs/duration";
27
+
28
+ setInterval(() => {
29
+ console.log("Called every 2 hours!");
30
+ }, Time.Hour * 2);
31
+ ```
32
+
33
+ ## Links
34
+
35
+ - [Documentation](https://docs.sodiumlabs.xyz/docs/packages/duration/stable)
36
+ - [Discord server](https://discord.gg/8PDXWSHH7k)
37
+ - [GitHub](https://github.com/sodium-labs/utilities/tree/main/packages/duration)
38
+ - [npm](https://npmjs.com/package/@sodiumlabs/duration)
39
+ - [Sodium Labs](https://sodiumlabs.xyz)
40
+
41
+ ## Help
42
+
43
+ Need help with the module? Ask on our [support server!](https://discord.gg/8PDXWSHH7k)
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Common time constants, expressed in milliseconds.
3
+ */
4
+ declare enum Time {
5
+ Nanosecond = 0.000001,
6
+ Microsecond = 0.001,
7
+ Millisecond = 1,
8
+ Second = 1000,
9
+ Minute = 60000,
10
+ Hour = 3600000,
11
+ Day = 86400000,
12
+ Week = 604800000,
13
+ /**
14
+ * 30 days
15
+ */
16
+ Month = 2592000000,
17
+ /**
18
+ * 365 days
19
+ */
20
+ Year = 31536000000,
21
+ /**
22
+ * Average month (365.25d / 12)
23
+ */
24
+ AverageMonth = 2629800000,
25
+ /**
26
+ * Average year (365.25d, accounting for leap years)
27
+ */
28
+ AverageYear = 31557600000
29
+ }
30
+ /**
31
+ * Common time constants, expressed in seconds.
32
+ */
33
+ declare enum TimeSeconds {
34
+ Nanosecond = 1e-9,
35
+ Microsecond = 0.000001,
36
+ Millisecond = 0.001,
37
+ Second = 1,
38
+ Minute = 60,
39
+ Hour = 3600,
40
+ Day = 86400,
41
+ Week = 604800,
42
+ /**
43
+ * 30 days
44
+ */
45
+ Month = 2592000,
46
+ /**
47
+ * 365 days
48
+ */
49
+ Year = 31536000,
50
+ /**
51
+ * Average month (365.25d / 12)
52
+ */
53
+ AverageMonth = 2629800,
54
+ /**
55
+ * Average year (365.25d, accounting for leap years)
56
+ */
57
+ AverageYear = 31557600
58
+ }
59
+
60
+ export { Time, TimeSeconds };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Common time constants, expressed in milliseconds.
3
+ */
4
+ declare enum Time {
5
+ Nanosecond = 0.000001,
6
+ Microsecond = 0.001,
7
+ Millisecond = 1,
8
+ Second = 1000,
9
+ Minute = 60000,
10
+ Hour = 3600000,
11
+ Day = 86400000,
12
+ Week = 604800000,
13
+ /**
14
+ * 30 days
15
+ */
16
+ Month = 2592000000,
17
+ /**
18
+ * 365 days
19
+ */
20
+ Year = 31536000000,
21
+ /**
22
+ * Average month (365.25d / 12)
23
+ */
24
+ AverageMonth = 2629800000,
25
+ /**
26
+ * Average year (365.25d, accounting for leap years)
27
+ */
28
+ AverageYear = 31557600000
29
+ }
30
+ /**
31
+ * Common time constants, expressed in seconds.
32
+ */
33
+ declare enum TimeSeconds {
34
+ Nanosecond = 1e-9,
35
+ Microsecond = 0.000001,
36
+ Millisecond = 0.001,
37
+ Second = 1,
38
+ Minute = 60,
39
+ Hour = 3600,
40
+ Day = 86400,
41
+ Week = 604800,
42
+ /**
43
+ * 30 days
44
+ */
45
+ Month = 2592000,
46
+ /**
47
+ * 365 days
48
+ */
49
+ Year = 31536000,
50
+ /**
51
+ * Average month (365.25d / 12)
52
+ */
53
+ AverageMonth = 2629800,
54
+ /**
55
+ * Average year (365.25d, accounting for leap years)
56
+ */
57
+ AverageYear = 31557600
58
+ }
59
+
60
+ export { Time, TimeSeconds };
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Time: () => Time,
24
+ TimeSeconds: () => TimeSeconds
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/constants.ts
29
+ var Time = /* @__PURE__ */ ((Time2) => {
30
+ Time2[Time2["Nanosecond"] = 1e-6] = "Nanosecond";
31
+ Time2[Time2["Microsecond"] = 1e-3] = "Microsecond";
32
+ Time2[Time2["Millisecond"] = 1] = "Millisecond";
33
+ Time2[Time2["Second"] = 1e3] = "Second";
34
+ Time2[Time2["Minute"] = 6e4] = "Minute";
35
+ Time2[Time2["Hour"] = 36e5] = "Hour";
36
+ Time2[Time2["Day"] = 864e5] = "Day";
37
+ Time2[Time2["Week"] = 6048e5] = "Week";
38
+ Time2[Time2["Month"] = 2592e6] = "Month";
39
+ Time2[Time2["Year"] = 31536e6] = "Year";
40
+ Time2[Time2["AverageMonth"] = 26298e5] = "AverageMonth";
41
+ Time2[Time2["AverageYear"] = 315576e5] = "AverageYear";
42
+ return Time2;
43
+ })(Time || {});
44
+ var TimeSeconds = /* @__PURE__ */ ((TimeSeconds2) => {
45
+ TimeSeconds2[TimeSeconds2["Nanosecond"] = 1e-9] = "Nanosecond";
46
+ TimeSeconds2[TimeSeconds2["Microsecond"] = 1e-6] = "Microsecond";
47
+ TimeSeconds2[TimeSeconds2["Millisecond"] = 1e-3] = "Millisecond";
48
+ TimeSeconds2[TimeSeconds2["Second"] = 1] = "Second";
49
+ TimeSeconds2[TimeSeconds2["Minute"] = 60] = "Minute";
50
+ TimeSeconds2[TimeSeconds2["Hour"] = 3600] = "Hour";
51
+ TimeSeconds2[TimeSeconds2["Day"] = 86400] = "Day";
52
+ TimeSeconds2[TimeSeconds2["Week"] = 604800] = "Week";
53
+ TimeSeconds2[TimeSeconds2["Month"] = 2592e3] = "Month";
54
+ TimeSeconds2[TimeSeconds2["Year"] = 31536e3] = "Year";
55
+ TimeSeconds2[TimeSeconds2["AverageMonth"] = 2629800] = "AverageMonth";
56
+ TimeSeconds2[TimeSeconds2["AverageYear"] = 31557600] = "AverageYear";
57
+ return TimeSeconds2;
58
+ })(TimeSeconds || {});
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ Time,
62
+ TimeSeconds
63
+ });
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/constants.ts"],"sourcesContent":["export * from \"./constants\";\n","/**\n * Common time constants, expressed in milliseconds.\n */\nexport enum Time {\n Nanosecond = 0.000_001,\n Microsecond = 0.001,\n Millisecond = 1,\n Second = 1_000,\n Minute = 60_000,\n Hour = 3_600_000,\n Day = 86_400_000,\n Week = 604_800_000,\n /**\n * 30 days\n */\n Month = 2_592_000_000,\n /**\n * 365 days\n */\n Year = 31_536_000_000,\n /**\n * Average month (365.25d / 12)\n */\n AverageMonth = 2_629_800_000,\n /**\n * Average year (365.25d, accounting for leap years)\n */\n AverageYear = 31_557_600_000,\n}\n\n/**\n * Common time constants, expressed in seconds.\n */\nexport enum TimeSeconds {\n Nanosecond = 0.000_000_001,\n Microsecond = 0.000_001,\n Millisecond = 0.001,\n Second = 1,\n Minute = 60,\n Hour = 3_600,\n Day = 86_400,\n Week = 604_800,\n /**\n * 30 days\n */\n Month = 2_592_000,\n /**\n * 365 days\n */\n Year = 31_536_000,\n /**\n * Average month (365.25d / 12)\n */\n AverageMonth = 2_629_800,\n /**\n * Average year (365.25d, accounting for leap years)\n */\n AverageYear = 31_557_600,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAK,OAAL,kBAAKA,UAAL;AACH,EAAAA,YAAA,gBAAa,QAAb;AACA,EAAAA,YAAA,iBAAc,QAAd;AACA,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,UAAO,UAAP;AAIA,EAAAA,YAAA,WAAQ,UAAR;AAIA,EAAAA,YAAA,UAAO,WAAP;AAIA,EAAAA,YAAA,kBAAe,WAAf;AAIA,EAAAA,YAAA,iBAAc,YAAd;AAxBQ,SAAAA;AAAA,GAAA;AA8BL,IAAK,cAAL,kBAAKC,iBAAL;AACH,EAAAA,0BAAA,gBAAa,QAAb;AACA,EAAAA,0BAAA,iBAAc,QAAd;AACA,EAAAA,0BAAA,iBAAc,QAAd;AACA,EAAAA,0BAAA,YAAS,KAAT;AACA,EAAAA,0BAAA,YAAS,MAAT;AACA,EAAAA,0BAAA,UAAO,QAAP;AACA,EAAAA,0BAAA,SAAM,SAAN;AACA,EAAAA,0BAAA,UAAO,UAAP;AAIA,EAAAA,0BAAA,WAAQ,UAAR;AAIA,EAAAA,0BAAA,UAAO,WAAP;AAIA,EAAAA,0BAAA,kBAAe,WAAf;AAIA,EAAAA,0BAAA,iBAAc,YAAd;AAxBQ,SAAAA;AAAA,GAAA;","names":["Time","TimeSeconds"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,36 @@
1
+ // src/constants.ts
2
+ var Time = /* @__PURE__ */ ((Time2) => {
3
+ Time2[Time2["Nanosecond"] = 1e-6] = "Nanosecond";
4
+ Time2[Time2["Microsecond"] = 1e-3] = "Microsecond";
5
+ Time2[Time2["Millisecond"] = 1] = "Millisecond";
6
+ Time2[Time2["Second"] = 1e3] = "Second";
7
+ Time2[Time2["Minute"] = 6e4] = "Minute";
8
+ Time2[Time2["Hour"] = 36e5] = "Hour";
9
+ Time2[Time2["Day"] = 864e5] = "Day";
10
+ Time2[Time2["Week"] = 6048e5] = "Week";
11
+ Time2[Time2["Month"] = 2592e6] = "Month";
12
+ Time2[Time2["Year"] = 31536e6] = "Year";
13
+ Time2[Time2["AverageMonth"] = 26298e5] = "AverageMonth";
14
+ Time2[Time2["AverageYear"] = 315576e5] = "AverageYear";
15
+ return Time2;
16
+ })(Time || {});
17
+ var TimeSeconds = /* @__PURE__ */ ((TimeSeconds2) => {
18
+ TimeSeconds2[TimeSeconds2["Nanosecond"] = 1e-9] = "Nanosecond";
19
+ TimeSeconds2[TimeSeconds2["Microsecond"] = 1e-6] = "Microsecond";
20
+ TimeSeconds2[TimeSeconds2["Millisecond"] = 1e-3] = "Millisecond";
21
+ TimeSeconds2[TimeSeconds2["Second"] = 1] = "Second";
22
+ TimeSeconds2[TimeSeconds2["Minute"] = 60] = "Minute";
23
+ TimeSeconds2[TimeSeconds2["Hour"] = 3600] = "Hour";
24
+ TimeSeconds2[TimeSeconds2["Day"] = 86400] = "Day";
25
+ TimeSeconds2[TimeSeconds2["Week"] = 604800] = "Week";
26
+ TimeSeconds2[TimeSeconds2["Month"] = 2592e3] = "Month";
27
+ TimeSeconds2[TimeSeconds2["Year"] = 31536e3] = "Year";
28
+ TimeSeconds2[TimeSeconds2["AverageMonth"] = 2629800] = "AverageMonth";
29
+ TimeSeconds2[TimeSeconds2["AverageYear"] = 31557600] = "AverageYear";
30
+ return TimeSeconds2;
31
+ })(TimeSeconds || {});
32
+ export {
33
+ Time,
34
+ TimeSeconds
35
+ };
36
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Common time constants, expressed in milliseconds.\n */\nexport enum Time {\n Nanosecond = 0.000_001,\n Microsecond = 0.001,\n Millisecond = 1,\n Second = 1_000,\n Minute = 60_000,\n Hour = 3_600_000,\n Day = 86_400_000,\n Week = 604_800_000,\n /**\n * 30 days\n */\n Month = 2_592_000_000,\n /**\n * 365 days\n */\n Year = 31_536_000_000,\n /**\n * Average month (365.25d / 12)\n */\n AverageMonth = 2_629_800_000,\n /**\n * Average year (365.25d, accounting for leap years)\n */\n AverageYear = 31_557_600_000,\n}\n\n/**\n * Common time constants, expressed in seconds.\n */\nexport enum TimeSeconds {\n Nanosecond = 0.000_000_001,\n Microsecond = 0.000_001,\n Millisecond = 0.001,\n Second = 1,\n Minute = 60,\n Hour = 3_600,\n Day = 86_400,\n Week = 604_800,\n /**\n * 30 days\n */\n Month = 2_592_000,\n /**\n * 365 days\n */\n Year = 31_536_000,\n /**\n * Average month (365.25d / 12)\n */\n AverageMonth = 2_629_800,\n /**\n * Average year (365.25d, accounting for leap years)\n */\n AverageYear = 31_557_600,\n}\n"],"mappings":";AAGO,IAAK,OAAL,kBAAKA,UAAL;AACH,EAAAA,YAAA,gBAAa,QAAb;AACA,EAAAA,YAAA,iBAAc,QAAd;AACA,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,UAAO,UAAP;AAIA,EAAAA,YAAA,WAAQ,UAAR;AAIA,EAAAA,YAAA,UAAO,WAAP;AAIA,EAAAA,YAAA,kBAAe,WAAf;AAIA,EAAAA,YAAA,iBAAc,YAAd;AAxBQ,SAAAA;AAAA,GAAA;AA8BL,IAAK,cAAL,kBAAKC,iBAAL;AACH,EAAAA,0BAAA,gBAAa,QAAb;AACA,EAAAA,0BAAA,iBAAc,QAAd;AACA,EAAAA,0BAAA,iBAAc,QAAd;AACA,EAAAA,0BAAA,YAAS,KAAT;AACA,EAAAA,0BAAA,YAAS,MAAT;AACA,EAAAA,0BAAA,UAAO,QAAP;AACA,EAAAA,0BAAA,SAAM,SAAN;AACA,EAAAA,0BAAA,UAAO,UAAP;AAIA,EAAAA,0BAAA,WAAQ,UAAR;AAIA,EAAAA,0BAAA,UAAO,WAAP;AAIA,EAAAA,0BAAA,kBAAe,WAAf;AAIA,EAAAA,0BAAA,iBAAc,YAAd;AAxBQ,SAAAA;AAAA,GAAA;","names":["Time","TimeSeconds"]}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package.json",
3
+ "name": "@sodiumlabs/duration",
4
+ "version": "1.0.0",
5
+ "description": "Time and duration utility package",
6
+ "keywords": [
7
+ "duration",
8
+ "sodium",
9
+ "sodiumlabs",
10
+ "time",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://github.com/sodium-labs/utilities/tree/main/packages/duration",
14
+ "bugs": {
15
+ "url": "https://github.com/sodium-labs/utilities/issues"
16
+ },
17
+ "license": "MIT",
18
+ "author": "sodiumlabs",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/sodium-labs/utilities.git",
22
+ "directory": "packages/duration"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "main": "./dist/index.js",
28
+ "module": "./dist/index.mjs",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "require": {
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "import": {
37
+ "types": "./dist/index.d.mts",
38
+ "default": "./dist/index.mjs"
39
+ }
40
+ }
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "build:docs": "tsc -p tsconfig.docs.json",
45
+ "lint": "tsc --noEmit && oxlint && oxfmt --check",
46
+ "fmt": "oxfmt",
47
+ "docs": "npm run build:docs && api-extractor run --local"
48
+ },
49
+ "devDependencies": {
50
+ "@microsoft/api-extractor": "^7.55.2",
51
+ "tsup": "^8.5.1",
52
+ "typescript": "^5.9.3"
53
+ },
54
+ "engines": {
55
+ "node": ">=18"
56
+ }
57
+ }