clockey 1.0.1 → 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 +159 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,160 @@
|
|
|
1
|
-
|
|
1
|
+
# Clockey ⏰
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
---
|