@jithinp96/time-converter 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/README.md ADDED
File without changes
@@ -0,0 +1,9 @@
1
+ type ConvertUtcToTimezoneParams = {
2
+ utcDate: string | Date;
3
+ timezone: string;
4
+ locale?: string;
5
+ options?: Intl.DateTimeFormatOptions;
6
+ };
7
+ declare const convertUtcToTimezone: ({ utcDate, timezone, locale, options, }: ConvertUtcToTimezoneParams) => string;
8
+
9
+ export { convertUtcToTimezone };
@@ -0,0 +1,9 @@
1
+ type ConvertUtcToTimezoneParams = {
2
+ utcDate: string | Date;
3
+ timezone: string;
4
+ locale?: string;
5
+ options?: Intl.DateTimeFormatOptions;
6
+ };
7
+ declare const convertUtcToTimezone: ({ utcDate, timezone, locale, options, }: ConvertUtcToTimezoneParams) => string;
8
+
9
+ export { convertUtcToTimezone };
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
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
+ convertUtcToTimezone: () => convertUtcToTimezone
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/utils/convertUtcToTimezone.ts
28
+ var convertUtcToTimezone = ({
29
+ utcDate,
30
+ timezone,
31
+ locale = "en-US",
32
+ options
33
+ }) => {
34
+ const date = new Date(utcDate);
35
+ if (isNaN(date.getTime())) {
36
+ throw new Error("Invalid UTC date provided");
37
+ }
38
+ try {
39
+ return new Intl.DateTimeFormat(locale, {
40
+ timeZone: timezone,
41
+ ...options
42
+ }).format(date);
43
+ } catch {
44
+ throw new Error("Invalid timezone provided");
45
+ }
46
+ };
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ convertUtcToTimezone
50
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,23 @@
1
+ // src/utils/convertUtcToTimezone.ts
2
+ var convertUtcToTimezone = ({
3
+ utcDate,
4
+ timezone,
5
+ locale = "en-US",
6
+ options
7
+ }) => {
8
+ const date = new Date(utcDate);
9
+ if (isNaN(date.getTime())) {
10
+ throw new Error("Invalid UTC date provided");
11
+ }
12
+ try {
13
+ return new Intl.DateTimeFormat(locale, {
14
+ timeZone: timezone,
15
+ ...options
16
+ }).format(date);
17
+ } catch {
18
+ throw new Error("Invalid timezone provided");
19
+ }
20
+ };
21
+ export {
22
+ convertUtcToTimezone
23
+ };
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@jithinp96/time-converter",
3
+ "version": "1.0.0",
4
+ "description": "Convert UTC dates into different timezones",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "files": ["dist"],
9
+ "scripts": {
10
+ "build": "tsup src/index.ts --format cjs,esm --dts",
11
+ "dev": "tsup src/index.ts --watch"
12
+ },
13
+ "keywords": [
14
+ "timezone",
15
+ "utc",
16
+ "date",
17
+ "time"
18
+ ],
19
+ "author": "Jithin",
20
+ "license": "MIT"
21
+ }