@1001-digital/layers.base 0.0.3 → 0.0.4

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.
@@ -0,0 +1,9 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(pnpm add:*)",
5
+ "Bash(pnpm install)",
6
+ "Bash(pnpm typecheck:*)"
7
+ ]
8
+ }
9
+ }
@@ -0,0 +1,63 @@
1
+ import { DateTime } from 'luxon'
2
+ import type { Ref } from 'vue'
3
+
4
+ let nowInterval: NodeJS.Timeout | undefined
5
+
6
+ export const useSeconds = () => {
7
+ const now = useState<number>('now', () => nowInSeconds())
8
+
9
+ if (import.meta.client && !nowInterval) {
10
+ nowInterval = setInterval(() => {
11
+ now.value = nowInSeconds()
12
+ }, 1000)
13
+ }
14
+
15
+ return now
16
+ }
17
+
18
+ export const useCountDown = (s: Ref<number | bigint>, showSecondsWithin: number = 60) => {
19
+ const duration = computed(() => Math.abs(Number(s.value)))
20
+
21
+ const seconds = computed(() => duration.value % 60)
22
+ const minutes = computed(() => Math.floor(duration.value / 60) % 60)
23
+ const hours = computed(() => Math.floor(duration.value / 60 / 60) % 24)
24
+ const days = computed(() => Math.floor(duration.value / 60 / 60 / 24))
25
+
26
+ const str = computed(() =>
27
+ [
28
+ days.value ? `${days.value}d` : null,
29
+ hours.value ? `${hours.value}h` : null,
30
+ minutes.value ? `${minutes.value}m` : null,
31
+ duration.value < showSecondsWithin && seconds.value ? `${seconds.value}s` : null,
32
+ ]
33
+ .filter((s) => !!s)
34
+ .join(' '),
35
+ )
36
+
37
+ return {
38
+ seconds,
39
+ minutes,
40
+ hours,
41
+ days,
42
+ str,
43
+ }
44
+ }
45
+
46
+ export const useSecondsAgo = (time: Ref<string | undefined>) => {
47
+ const ago = ref<string>()
48
+ const now = useSeconds()
49
+
50
+ watch(
51
+ now,
52
+ () => {
53
+ if (time.value) {
54
+ ago.value = DateTime.fromISO(time.value).toRelative({ style: 'short', locale: 'en' }) ?? undefined
55
+ }
56
+ },
57
+ {
58
+ immediate: true,
59
+ },
60
+ )
61
+
62
+ return ago
63
+ }
@@ -0,0 +1,20 @@
1
+ import { DateTime } from 'luxon'
2
+
3
+ export const delay = (ms: number): Promise<void> =>
4
+ new Promise((resolve) => setTimeout(resolve, ms))
5
+
6
+ export const daysInSeconds = (days: number): number => days * 60 * 60 * 24
7
+
8
+ export const nowInSeconds = (): number => Math.floor(Date.now() / 1000)
9
+
10
+ export const asUTCDate = (date: Date | null) =>
11
+ date
12
+ ? DateTime.utc(
13
+ date.getFullYear(),
14
+ date.getMonth() + 1,
15
+ date.getDate(),
16
+ date.getHours(),
17
+ date.getMinutes(),
18
+ date.getSeconds(),
19
+ )
20
+ : null
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@1001-digital/layers.base",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "main": "./nuxt.config.ts",
6
6
  "devDependencies": {
7
7
  "@iconify-json/lucide": "^1.2.81",
8
8
  "@iconify-json/simple-icons": "^1.2.63",
9
9
  "@nuxt/eslint": "latest",
10
+ "@types/luxon": "^3.6.2",
10
11
  "@types/node": "^24.10.1",
11
12
  "eslint": "^9.39.1",
12
13
  "nuxt": "^4.2.2",
@@ -15,6 +16,7 @@
15
16
  },
16
17
  "dependencies": {
17
18
  "@nuxt/icon": "^1.10.3",
19
+ "luxon": "^3.6.1",
18
20
  "modern-normalize": "^3.0.1",
19
21
  "reka-ui": "^2.6.1"
20
22
  },