clockey 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,160 @@
1
- ## Clockey
1
+ # Clockey
2
2
 
3
- API-first time utilities for backend developers
3
+ Beautiful, tiny utilities for working with current time and date in Node.js with ready-to-use API response wrappers for servers and lambdas.
4
+
5
+ ---
6
+
7
+ ## ✨ Highlights
8
+
9
+ - Minimal, dependency-free TypeScript helpers for time & date.
10
+ - Small API response wrappers returning a consistent `{ success, code, msg, ... }` shape for easy use in Express or serverless handlers.
11
+ - Works with CommonJS and ES Modules.
12
+
13
+ ---
14
+
15
+ ## 💿 Installation
16
+
17
+ ```bash
18
+ npm install clockey
19
+ ```
20
+
21
+ ---
22
+
23
+ ## ⚙️ Quick Examples
24
+
25
+ CommonJS:
26
+
27
+ ```js
28
+ const { formatCurrentTime, currentHour24Str } = require("clockey");
29
+ console.log(formatCurrentTime());
30
+ console.log(currentHour24Str()); // '09'
31
+ ```
32
+
33
+ ESM / TypeScript:
34
+
35
+ ```ts
36
+ import { getCurrentTimeResponse } from "clockey/response/timeResponse";
37
+ console.log(getCurrentTimeResponse());
38
+ ```
39
+
40
+ Express example (route):
41
+
42
+ ```js
43
+ const express = require("express");
44
+ const { getCurrentTimeResponse } = require("clockey/response/timeResponse");
45
+ const app = express();
46
+
47
+ app.get("/api/time", (req, res) => res.json(getCurrentTimeResponse()));
48
+ app.listen(3000);
49
+ ```
50
+
51
+ ---
52
+
53
+ ## 📚 Methods (Quick usage)
54
+
55
+ Below are grouped, easy-to-read tables for the package exports. Each table shows usage and what the function returns.
56
+
57
+ ### ⏱️ Time helpers
58
+
59
+ | Name | Example | Returns |
60
+ | --------------------- | --------------------- | ------------------------------------------------------------------------- | ------- |
61
+ | `formatCurrentTime()` | `formatCurrentTime()` | Full object: numbers, padded strings, `timeAsString24` / `timeAsString12` |
62
+ | `currentHour()` | `currentHour()` | `{ hour24, hour12, hour24Str, hour12Str }` |
63
+ | `currentMinute()` | `currentMinute()` | `{ minute, minuteStr }` |
64
+ | `currentSecond()` | `currentSecond()` | `{ second, secondStr }` |
65
+ | `currentHour24Str()` | `currentHour24Str()` | `'09'` (string) |
66
+ | `currentHour12Str()` | `currentHour12Str()` | `'09'` (string) |
67
+ | `currentMinuteStr()` | `currentMinuteStr()` | `'05'` (string) |
68
+ | `currentSecondStr()` | `currentSecondStr()` | `'07'` (string) |
69
+ | `currentPeriod()` | `currentPeriod()` | `{ period: 'AM' | 'PM' }` |
70
+
71
+ ### 🧾 Time response helpers
72
+
73
+ | Name | Example | Returns |
74
+ | ------------------------------- | ------------------------------- | ------------------------------------------------------------------- |
75
+ | `getCurrentTime()` | `getCurrentTime()` | `{ timeAsString12, timeAsString24 }` |
76
+ | `getCurrentTimeResponse()` | `getCurrentTimeResponse()` | `{ success, code, msg, data }` where `data` = `formatCurrentTime()` |
77
+ | `getCurrentHr()` | `getCurrentHr()` | returns `currentHour()` |
78
+ | `getCurrenHrResponse()` | `getCurrenHrResponse()` | `{ success, code, msg, hour }` |
79
+ | `getCurrentMinute()` | `getCurrentMinute()` | returns `currentMinute()` |
80
+ | `getCurrentMinuteResponse()` | `getCurrentMinuteResponse()` | `{ success, code, msg, minute }` |
81
+ | `getCurrentSecond()` | `getCurrentSecond()` | returns `currentSecond()` |
82
+ | `getCurrentSecondResponse()` | `getCurrentSecondResponse()` | `{ success, code, msg, second }` |
83
+ | `getCurrentHour24Str()` | `getCurrentHour24Str()` | string |
84
+ | `getCurrentHour24StrResponse()` | `getCurrentHour24StrResponse()` | `{ success, code, msg, value }` |
85
+ | `getCurrentHour12Str()` | `getCurrentHour12Str()` | string |
86
+ | `getCurrentHour12StrResponse()` | `getCurrentHour12StrResponse()` | `{ success, code, msg, value }` |
87
+ | `getCurrentMinuteStr()` | `getCurrentMinuteStr()` | string |
88
+ | `getCurrentMinuteStrResponse()` | `getCurrentMinuteStrResponse()` | `{ success, code, msg, value }` |
89
+ | `getCurrentSecondStr()` | `getCurrentSecondStr()` | string |
90
+ | `getCurrentSecondStrResponse()` | `getCurrentSecondStrResponse()` | `{ success, code, msg, value }` |
91
+ | `getCurrentPeriod()` | `getCurrentPeriod()` | `{ period }` |
92
+ | `getCurrentPeriodResponse()` | `getCurrentPeriodResponse()` | `{ success, code, msg, period }` |
93
+
94
+ ### 📅 Date helpers
95
+
96
+ | Name | Example | Returns |
97
+ | --------------------- | --------------------- | ------------------------------------------------------- |
98
+ | `formatCurrentDate()` | `formatCurrentDate()` | `{ date: { yr, month, day, date, ordinal, fullDate } }` |
99
+ | `currentYear()` | `currentYear()` | `2025` (number) |
100
+ | `currentMonth()` | `currentMonth()` | `{ monthNumber, monthName, monthStr }` |
101
+ | `currentDay()` | `currentDay()` | `{ dayIndex, dayName }` |
102
+ | `currentDateNumber()` | `currentDateNumber()` | `{ date, dateStr }` |
103
+ | `currentOrdinal()` | `currentOrdinal()` | `{ ordinal }` |
104
+ | `currentFullDate()` | `currentFullDate()` | `{ fullDate }` |
105
+
106
+ ### 🗂 Date response helpers
107
+
108
+ | Name | Example | Returns |
109
+ | -------------------------------- | -------------------------------- | ------------------------------------------------------ |
110
+ | `getCurrentDate()` | `getCurrentDate()` | `ClockeyDateResponse` (`{ success, code, msg, data }`) |
111
+ | `getCurrentYearResponse()` | `getCurrentYearResponse()` | `{ success, code, msg, value }` |
112
+ | `getCurrentMonthResponse()` | `getCurrentMonthResponse()` | `{ success, code, msg, value }` |
113
+ | `getCurrentDayResponse()` | `getCurrentDayResponse()` | `{ success, code, msg, value }` |
114
+ | `getCurrentDateNumberResponse()` | `getCurrentDateNumberResponse()` | `{ success, code, msg, value }` |
115
+ | `getCurrentOrdinalResponse()` | `getCurrentOrdinalResponse()` | `{ success, code, msg, value }` |
116
+ | `getCurrentFullDateResponse()` | `getCurrentFullDateResponse()` | `{ success, code, msg, value }` |
117
+
118
+ ---
119
+
120
+ ## ✅ Response shapes
121
+
122
+ Success (example):
123
+
124
+ ```json
125
+ {
126
+ "success": true,
127
+ "code": 200,
128
+ "msg": "Current time fetched successfully",
129
+ "data": {
130
+ /* payload */
131
+ }
132
+ }
133
+ ```
134
+
135
+ String-only helper responses use `value`:
136
+
137
+ ```json
138
+ {
139
+ "success": true,
140
+ "code": 200,
141
+ "msg": "Current hour string fetched",
142
+ "value": "09"
143
+ }
144
+ ```
145
+
146
+ ---
147
+
148
+ ## 🤝 Contributing
149
+
150
+ PRs welcome. Keep changes small and add tests for functional changes.
151
+
152
+ ---
153
+
154
+ ## 🌐 Links & socials
155
+
156
+ - GitHub: https://github.com/yasasbanukaofficial
157
+ - NPM: https://www.npmjs.com/~yasasbanukaofficial
158
+ - LinkedIn: https://www.linkedin.com/in/yasasbanukagunasena/
159
+
160
+ ---
@@ -0,0 +1,194 @@
1
+ interface TimeData {
2
+ hr24: number;
3
+ hr12: number;
4
+ min: number;
5
+ sec: number;
6
+ period: "AM" | "PM" | string;
7
+ timeAsString24: string;
8
+ timeAsString12: string;
9
+ }
10
+
11
+ interface ClockeyTimeResponse {
12
+ success: boolean;
13
+ code: number;
14
+ msg: string;
15
+ data: TimeData;
16
+ }
17
+
18
+ declare function getCurrentTime(): {
19
+ timeAsString12: string;
20
+ timeAsString24: string;
21
+ };
22
+ declare function getCurrentTimeResponse(): ClockeyTimeResponse;
23
+ declare function getCurrentHr(): {
24
+ hour24: number;
25
+ hour12: number;
26
+ hour24Str: string;
27
+ hour12Str: string;
28
+ };
29
+ declare function getCurrenHrResponse(): {
30
+ success: boolean;
31
+ code: number;
32
+ msg: string;
33
+ hour: {
34
+ hour24: number;
35
+ hour12: number;
36
+ hour24Str: string;
37
+ hour12Str: string;
38
+ };
39
+ };
40
+ declare function getCurrentMinute(): {
41
+ minute: number;
42
+ minuteStr: string;
43
+ };
44
+ declare function getCurrentMinuteResponse(): {
45
+ success: boolean;
46
+ code: number;
47
+ msg: string;
48
+ minute: {
49
+ minute: number;
50
+ minuteStr: string;
51
+ };
52
+ };
53
+ declare function getCurrentSecond(): {
54
+ second: number;
55
+ secondStr: string;
56
+ };
57
+ declare function getCurrentSecondResponse(): {
58
+ success: boolean;
59
+ code: number;
60
+ msg: string;
61
+ second: {
62
+ second: number;
63
+ secondStr: string;
64
+ };
65
+ };
66
+ declare function getCurrentHour24Str(): string;
67
+ declare function getCurrentHour24StrResponse(): {
68
+ success: boolean;
69
+ code: number;
70
+ msg: string;
71
+ value: string;
72
+ };
73
+ declare function getCurrentHour12Str(): string;
74
+ declare function getCurrentHour12StrResponse(): {
75
+ success: boolean;
76
+ code: number;
77
+ msg: string;
78
+ value: string;
79
+ };
80
+ declare function getCurrentMinuteStr(): string;
81
+ declare function getCurrentMinuteStrResponse(): {
82
+ success: boolean;
83
+ code: number;
84
+ msg: string;
85
+ value: string;
86
+ };
87
+ declare function getCurrentSecondStr(): string;
88
+ declare function getCurrentSecondStrResponse(): {
89
+ success: boolean;
90
+ code: number;
91
+ msg: string;
92
+ value: string;
93
+ };
94
+ declare function getCurrentPeriod(): {
95
+ period: string;
96
+ };
97
+ declare function getCurrentPeriodResponse(): {
98
+ success: boolean;
99
+ code: number;
100
+ msg: string;
101
+ period: {
102
+ period: string;
103
+ };
104
+ };
105
+
106
+ interface DateData {
107
+ yr: number;
108
+ month: string;
109
+ day: string;
110
+ date: number;
111
+ ordinal: string;
112
+ fullDate: string;
113
+ }
114
+
115
+ interface ClockeyDateResponse {
116
+ success: boolean;
117
+ code: number;
118
+ msg: string;
119
+ data: DateData;
120
+ }
121
+
122
+ declare function getCurrentDate(): ClockeyDateResponse;
123
+ declare function getCurrentYear(): number;
124
+ declare function getCurrentYearResponse(): {
125
+ success: boolean;
126
+ code: number;
127
+ msg: string;
128
+ value: number;
129
+ };
130
+ declare function getCurrentMonth(): {
131
+ monthNumber: number;
132
+ monthName: string;
133
+ monthStr: string;
134
+ };
135
+ declare function getCurrentMonthResponse(): {
136
+ success: boolean;
137
+ code: number;
138
+ msg: string;
139
+ value: {
140
+ monthNumber: number;
141
+ monthName: string;
142
+ monthStr: string;
143
+ };
144
+ };
145
+ declare function getCurrentDay(): {
146
+ dayIndex: number;
147
+ dayName: string;
148
+ };
149
+ declare function getCurrentDayResponse(): {
150
+ success: boolean;
151
+ code: number;
152
+ msg: string;
153
+ value: {
154
+ dayIndex: number;
155
+ dayName: string;
156
+ };
157
+ };
158
+ declare function getCurrentDateNumber(): {
159
+ date: number;
160
+ dateStr: string;
161
+ };
162
+ declare function getCurrentDateNumberResponse(): {
163
+ success: boolean;
164
+ code: number;
165
+ msg: string;
166
+ value: {
167
+ date: number;
168
+ dateStr: string;
169
+ };
170
+ };
171
+ declare function getCurrentOrdinal(): {
172
+ ordinal: string;
173
+ };
174
+ declare function getCurrentOrdinalResponse(): {
175
+ success: boolean;
176
+ code: number;
177
+ msg: string;
178
+ value: {
179
+ ordinal: string;
180
+ };
181
+ };
182
+ declare function getCurrentFullDate(): {
183
+ fullDate: string;
184
+ };
185
+ declare function getCurrentFullDateResponse(): {
186
+ success: boolean;
187
+ code: number;
188
+ msg: string;
189
+ value: {
190
+ fullDate: string;
191
+ };
192
+ };
193
+
194
+ export { getCurrenHrResponse, getCurrentDate, getCurrentDateNumber, getCurrentDateNumberResponse, getCurrentDay, getCurrentDayResponse, getCurrentFullDate, getCurrentFullDateResponse, getCurrentHour12Str, getCurrentHour12StrResponse, getCurrentHour24Str, getCurrentHour24StrResponse, getCurrentHr, getCurrentMinute, getCurrentMinuteResponse, getCurrentMinuteStr, getCurrentMinuteStrResponse, getCurrentMonth, getCurrentMonthResponse, getCurrentOrdinal, getCurrentOrdinalResponse, getCurrentPeriod, getCurrentPeriodResponse, getCurrentSecond, getCurrentSecondResponse, getCurrentSecondStr, getCurrentSecondStrResponse, getCurrentTime, getCurrentTimeResponse, getCurrentYear, getCurrentYearResponse };
@@ -0,0 +1,194 @@
1
+ interface TimeData {
2
+ hr24: number;
3
+ hr12: number;
4
+ min: number;
5
+ sec: number;
6
+ period: "AM" | "PM" | string;
7
+ timeAsString24: string;
8
+ timeAsString12: string;
9
+ }
10
+
11
+ interface ClockeyTimeResponse {
12
+ success: boolean;
13
+ code: number;
14
+ msg: string;
15
+ data: TimeData;
16
+ }
17
+
18
+ declare function getCurrentTime(): {
19
+ timeAsString12: string;
20
+ timeAsString24: string;
21
+ };
22
+ declare function getCurrentTimeResponse(): ClockeyTimeResponse;
23
+ declare function getCurrentHr(): {
24
+ hour24: number;
25
+ hour12: number;
26
+ hour24Str: string;
27
+ hour12Str: string;
28
+ };
29
+ declare function getCurrenHrResponse(): {
30
+ success: boolean;
31
+ code: number;
32
+ msg: string;
33
+ hour: {
34
+ hour24: number;
35
+ hour12: number;
36
+ hour24Str: string;
37
+ hour12Str: string;
38
+ };
39
+ };
40
+ declare function getCurrentMinute(): {
41
+ minute: number;
42
+ minuteStr: string;
43
+ };
44
+ declare function getCurrentMinuteResponse(): {
45
+ success: boolean;
46
+ code: number;
47
+ msg: string;
48
+ minute: {
49
+ minute: number;
50
+ minuteStr: string;
51
+ };
52
+ };
53
+ declare function getCurrentSecond(): {
54
+ second: number;
55
+ secondStr: string;
56
+ };
57
+ declare function getCurrentSecondResponse(): {
58
+ success: boolean;
59
+ code: number;
60
+ msg: string;
61
+ second: {
62
+ second: number;
63
+ secondStr: string;
64
+ };
65
+ };
66
+ declare function getCurrentHour24Str(): string;
67
+ declare function getCurrentHour24StrResponse(): {
68
+ success: boolean;
69
+ code: number;
70
+ msg: string;
71
+ value: string;
72
+ };
73
+ declare function getCurrentHour12Str(): string;
74
+ declare function getCurrentHour12StrResponse(): {
75
+ success: boolean;
76
+ code: number;
77
+ msg: string;
78
+ value: string;
79
+ };
80
+ declare function getCurrentMinuteStr(): string;
81
+ declare function getCurrentMinuteStrResponse(): {
82
+ success: boolean;
83
+ code: number;
84
+ msg: string;
85
+ value: string;
86
+ };
87
+ declare function getCurrentSecondStr(): string;
88
+ declare function getCurrentSecondStrResponse(): {
89
+ success: boolean;
90
+ code: number;
91
+ msg: string;
92
+ value: string;
93
+ };
94
+ declare function getCurrentPeriod(): {
95
+ period: string;
96
+ };
97
+ declare function getCurrentPeriodResponse(): {
98
+ success: boolean;
99
+ code: number;
100
+ msg: string;
101
+ period: {
102
+ period: string;
103
+ };
104
+ };
105
+
106
+ interface DateData {
107
+ yr: number;
108
+ month: string;
109
+ day: string;
110
+ date: number;
111
+ ordinal: string;
112
+ fullDate: string;
113
+ }
114
+
115
+ interface ClockeyDateResponse {
116
+ success: boolean;
117
+ code: number;
118
+ msg: string;
119
+ data: DateData;
120
+ }
121
+
122
+ declare function getCurrentDate(): ClockeyDateResponse;
123
+ declare function getCurrentYear(): number;
124
+ declare function getCurrentYearResponse(): {
125
+ success: boolean;
126
+ code: number;
127
+ msg: string;
128
+ value: number;
129
+ };
130
+ declare function getCurrentMonth(): {
131
+ monthNumber: number;
132
+ monthName: string;
133
+ monthStr: string;
134
+ };
135
+ declare function getCurrentMonthResponse(): {
136
+ success: boolean;
137
+ code: number;
138
+ msg: string;
139
+ value: {
140
+ monthNumber: number;
141
+ monthName: string;
142
+ monthStr: string;
143
+ };
144
+ };
145
+ declare function getCurrentDay(): {
146
+ dayIndex: number;
147
+ dayName: string;
148
+ };
149
+ declare function getCurrentDayResponse(): {
150
+ success: boolean;
151
+ code: number;
152
+ msg: string;
153
+ value: {
154
+ dayIndex: number;
155
+ dayName: string;
156
+ };
157
+ };
158
+ declare function getCurrentDateNumber(): {
159
+ date: number;
160
+ dateStr: string;
161
+ };
162
+ declare function getCurrentDateNumberResponse(): {
163
+ success: boolean;
164
+ code: number;
165
+ msg: string;
166
+ value: {
167
+ date: number;
168
+ dateStr: string;
169
+ };
170
+ };
171
+ declare function getCurrentOrdinal(): {
172
+ ordinal: string;
173
+ };
174
+ declare function getCurrentOrdinalResponse(): {
175
+ success: boolean;
176
+ code: number;
177
+ msg: string;
178
+ value: {
179
+ ordinal: string;
180
+ };
181
+ };
182
+ declare function getCurrentFullDate(): {
183
+ fullDate: string;
184
+ };
185
+ declare function getCurrentFullDateResponse(): {
186
+ success: boolean;
187
+ code: number;
188
+ msg: string;
189
+ value: {
190
+ fullDate: string;
191
+ };
192
+ };
193
+
194
+ export { getCurrenHrResponse, getCurrentDate, getCurrentDateNumber, getCurrentDateNumberResponse, getCurrentDay, getCurrentDayResponse, getCurrentFullDate, getCurrentFullDateResponse, getCurrentHour12Str, getCurrentHour12StrResponse, getCurrentHour24Str, getCurrentHour24StrResponse, getCurrentHr, getCurrentMinute, getCurrentMinuteResponse, getCurrentMinuteStr, getCurrentMinuteStrResponse, getCurrentMonth, getCurrentMonthResponse, getCurrentOrdinal, getCurrentOrdinalResponse, getCurrentPeriod, getCurrentPeriodResponse, getCurrentSecond, getCurrentSecondResponse, getCurrentSecondStr, getCurrentSecondStrResponse, getCurrentTime, getCurrentTimeResponse, getCurrentYear, getCurrentYearResponse };