@vedanshshetti/zeit 1.2.0 → 1.3.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 +46 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/modules/greet/index.d.ts +3 -0
- package/dist/modules/greet/index.d.ts.map +1 -0
- package/dist/modules/greet/index.js +29 -0
- package/dist/modules/greet/index.js.map +1 -0
- package/dist/modules/greet/locales.d.ts +3 -0
- package/dist/modules/greet/locales.d.ts.map +1 -0
- package/dist/modules/greet/locales.js +2 -0
- package/dist/modules/greet/locales.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/src/modules/greet/index.ts +24 -0
- package/src/modules/greet/locales.ts +2 -0
package/README.md
CHANGED
|
@@ -21,13 +21,14 @@ const { zeit } = require("@vedanshshetti/zeit");
|
|
|
21
21
|
|
|
22
22
|
### Methods
|
|
23
23
|
|
|
24
|
-
The `zeit` object provides
|
|
24
|
+
The `zeit` object provides four main methods:
|
|
25
25
|
|
|
26
26
|
| Method | Description |
|
|
27
27
|
|--------|-------------|
|
|
28
28
|
| `zeit.now()` | Get the current date/time |
|
|
29
29
|
| `zeit.in()` | Get a future date/time |
|
|
30
30
|
| `zeit.before()` | Get a past date/time |
|
|
31
|
+
| `zeit.greet()` | Get a time-based greeting |
|
|
31
32
|
|
|
32
33
|
---
|
|
33
34
|
|
|
@@ -38,7 +39,7 @@ Gets the current date and time in various formats.
|
|
|
38
39
|
### Parameters
|
|
39
40
|
|
|
40
41
|
- **format** (required): One of:
|
|
41
|
-
- `"Unix
|
|
42
|
+
- `"Unix"` - Returns milliseconds since Unix epoch
|
|
42
43
|
- `"ISO 8601:1-2019 Extended"` - Returns ISO 8601 formatted string
|
|
43
44
|
- `"Human Readable"` - Returns a human-readable date string
|
|
44
45
|
- **timezone** (optional): `"UTC"` or `"Local Time"` (default: `"Local Time"`)
|
|
@@ -47,7 +48,7 @@ Gets the current date and time in various formats.
|
|
|
47
48
|
|
|
48
49
|
```typescript
|
|
49
50
|
// Get Unix epoch timestamp
|
|
50
|
-
const epoch = zeit.now("Unix
|
|
51
|
+
const epoch = zeit.now("Unix");
|
|
51
52
|
// => 1712345678901
|
|
52
53
|
|
|
53
54
|
// Get ISO 8601 string in local time
|
|
@@ -168,16 +169,57 @@ console.log(pastDate.toISOString());
|
|
|
168
169
|
|
|
169
170
|
---
|
|
170
171
|
|
|
172
|
+
## `zeit.greet()`
|
|
173
|
+
|
|
174
|
+
Returns a time-based greeting for a given name. The greeting changes based on the current time of day.
|
|
175
|
+
|
|
176
|
+
### Parameters
|
|
177
|
+
|
|
178
|
+
- **name** (required): The name to greet
|
|
179
|
+
- **language** (optional): `"English"` (default) or `"German"`
|
|
180
|
+
|
|
181
|
+
### Time-based Greetings
|
|
182
|
+
|
|
183
|
+
| Time Range | English | German |
|
|
184
|
+
|------------|---------|--------|
|
|
185
|
+
| 6:00 - 11:59 | Good Morning | Guten Morgen |
|
|
186
|
+
| 12:00 - 17:59 | Good Afternoon | Guten Tag |
|
|
187
|
+
| 18:00 - 20:59 | Good Evening | Guten Abend |
|
|
188
|
+
| 21:00 - 5:59 | Good Night | Gute Nacht |
|
|
189
|
+
|
|
190
|
+
### Examples
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
// English greeting (default)
|
|
194
|
+
const greeting1 = zeit.greet("Alice");
|
|
195
|
+
// => "Good Morning Alice" (if between 6am-12pm)
|
|
196
|
+
|
|
197
|
+
// English greeting explicit
|
|
198
|
+
const greeting2 = zeit.greet("Bob", "English");
|
|
199
|
+
// => "Good Afternoon Bob" (if between 12pm-6pm)
|
|
200
|
+
|
|
201
|
+
// German greeting
|
|
202
|
+
const greeting3 = zeit.greet("Anna", "German");
|
|
203
|
+
// => "Guten Morgen Anna" (if between 6am-12pm)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Return Value
|
|
207
|
+
|
|
208
|
+
Returns a string with the appropriate greeting based on the current time.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
171
212
|
## Type Safety
|
|
172
213
|
|
|
173
214
|
The library is fully typed with TypeScript:
|
|
174
215
|
|
|
175
216
|
```typescript
|
|
176
217
|
// All methods are type-safe
|
|
177
|
-
const epoch: number = zeit.now("Unix
|
|
218
|
+
const epoch: number = zeit.now("Unix");
|
|
178
219
|
const iso: string = zeit.now("ISO 8601:1-2019 Extended");
|
|
179
220
|
const date: Date = zeit.in("5 days");
|
|
180
221
|
const pastDate: Date = zeit.before("2 hours");
|
|
222
|
+
const greeting: string = zeit.greet("Alice");
|
|
181
223
|
|
|
182
224
|
// Invalid formats are caught at compile time
|
|
183
225
|
// @ts-expect-error - Invalid format
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import before from "./modules/before.js";
|
|
2
2
|
import inX from "./modules/in.js";
|
|
3
3
|
import now from "./modules/now.js";
|
|
4
|
+
import greet from "./modules/greet/index.js";
|
|
4
5
|
export declare const zeit: {
|
|
5
6
|
readonly in: typeof inX;
|
|
6
7
|
readonly before: typeof before;
|
|
7
8
|
readonly now: typeof now;
|
|
9
|
+
readonly greet: typeof greet;
|
|
8
10
|
};
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,GAAG,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,GAAG,MAAM,kBAAkB,CAAC;AACnC,OAAO,KAAK,MAAM,0BAA0B,CAAC;AAE7C,eAAO,MAAM,IAAI;;;;;CAKP,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import before from "./modules/before.js";
|
|
2
2
|
import inX from "./modules/in.js";
|
|
3
3
|
import now from "./modules/now.js";
|
|
4
|
+
import greet from "./modules/greet/index.js";
|
|
4
5
|
export const zeit = {
|
|
5
6
|
in: inX,
|
|
6
7
|
before,
|
|
7
|
-
now
|
|
8
|
+
now,
|
|
9
|
+
greet,
|
|
8
10
|
};
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,GAAG,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,GAAG,MAAM,kBAAkB,CAAC;AACnC,OAAO,KAAK,MAAM,0BAA0B,CAAC;AAE7C,MAAM,CAAC,MAAM,IAAI,GAAG;IAChB,EAAE,EAAE,GAAG;IACP,MAAM;IACN,GAAG;IACH,KAAK;CACC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { EnglishGreeting, GermanGreeting } from "./locales.js";
|
|
2
|
+
export default function greet<T extends string, L extends "English" | "German" = "English">(name: T, language?: L): `${L extends "English" ? EnglishGreeting : GermanGreeting} ${T}`;
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/greet/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGpE,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,GAAG,QAAQ,GAAG,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,GAC7G,GAAG,CAAC,SAAS,SAAS,GAAG,eAAe,GAAG,cAAc,IAAI,CAAC,EAAE,CAmBnE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export default function greet(name, language) {
|
|
2
|
+
const current = new Date().getHours();
|
|
3
|
+
let word;
|
|
4
|
+
switch (language ?? "English") {
|
|
5
|
+
case "English":
|
|
6
|
+
if (6 <= current && current < 12)
|
|
7
|
+
word = "Good Morning";
|
|
8
|
+
if (12 <= current && current < 18)
|
|
9
|
+
word = "Good Afternoon";
|
|
10
|
+
if (18 <= current && current < 21)
|
|
11
|
+
word = "Good Evening";
|
|
12
|
+
if (21 <= current && current < 24)
|
|
13
|
+
word = "Good Night";
|
|
14
|
+
break;
|
|
15
|
+
case "German":
|
|
16
|
+
if (6 <= current && current < 12)
|
|
17
|
+
word = "Guten Morgen";
|
|
18
|
+
if (12 <= current && current < 18)
|
|
19
|
+
word = "Guten Tag";
|
|
20
|
+
if (18 <= current && current < 21)
|
|
21
|
+
word = "Guten Abend";
|
|
22
|
+
if (21 <= current && current < 24)
|
|
23
|
+
word = "Gute Nacht";
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
return `${word} ${name}`;
|
|
27
|
+
}
|
|
28
|
+
;
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/greet/index.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,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AG,WAAW,GAAG,aAAa,GAAG,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locales.js","sourceRoot":"","sources":["../../../src/modules/greet/locales.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { EnglishGreeting, GermanGreeting } from "./locales.js";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export default function greet<T extends string, L extends "English" | "German" = "English">(name: T, language?: L):
|
|
5
|
+
`${L extends "English" ? EnglishGreeting : GermanGreeting} ${T}` {
|
|
6
|
+
const current = new Date().getHours();
|
|
7
|
+
let word;
|
|
8
|
+
switch (language ?? "English") {
|
|
9
|
+
case "English":
|
|
10
|
+
if (6 <= current && current < 12) word = "Good Morning";
|
|
11
|
+
if (12 <= current && current < 18) word = "Good Afternoon";
|
|
12
|
+
if (18 <= current && current < 21) word = "Good Evening";
|
|
13
|
+
if (21 <= current && current < 24) word = "Good Night";
|
|
14
|
+
break;
|
|
15
|
+
case "German":
|
|
16
|
+
if (6 <= current && current < 12) word = "Guten Morgen";
|
|
17
|
+
if (12 <= current && current < 18) word = "Guten Tag";
|
|
18
|
+
if (18 <= current && current < 21) word = "Guten Abend";
|
|
19
|
+
if (21 <= current && current < 24) word = "Gute Nacht";
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return `${word as L extends "English" ? EnglishGreeting : GermanGreeting} ${name}`;
|
|
24
|
+
};
|