onomad 2.0.2 → 2.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.
package/README.md CHANGED
@@ -61,6 +61,26 @@ Komponenta automatski ažurira prikazan tekst svakih 60 sekundi. Možete prilago
61
61
  <TimeAgo :date="postDate" :update-interval="5000" />
62
62
  ```
63
63
 
64
+ ### Upotreba u Nuxt.js
65
+
66
+ U Nuxt projektima, komponenta automatski radi bez dodatne konfiguracije:
67
+
68
+ ```vue
69
+ <script setup lang="ts">
70
+ import { TimeAgo } from 'onomad/vue';
71
+
72
+ const postDate = new Date(Date.now() - 5 * 60 * 1000);
73
+ </script>
74
+
75
+ <template>
76
+ <div>
77
+ <p>Objavljeno <TimeAgo :date="postDate" /></p>
78
+ </div>
79
+ </template>
80
+ ```
81
+
82
+ Za server-side rendering (SSR), komponenta će prikazati inicijalno vreme, a zatim će nastaviti sa ažuriranjem na klijentskoj strani.
83
+
64
84
  ## API Referenca
65
85
 
66
86
  ### `timeago(time: Date): string`
@@ -0,0 +1,35 @@
1
+ <script setup lang="ts">
2
+ import { ref, onMounted, onUnmounted, watch } from 'vue';
3
+ import { timeago } from '../onomad';
4
+
5
+ const props = withDefaults(defineProps<{
6
+ date: Date | string;
7
+ updateInterval?: number;
8
+ }>(), {
9
+ updateInterval: 60000
10
+ });
11
+
12
+ const formattedTime = ref(timeago(new Date(props.date)));
13
+ let intervalId: ReturnType<typeof setInterval> | null = null;
14
+
15
+ const updateTime = () => {
16
+ formattedTime.value = timeago(new Date(props.date));
17
+ };
18
+
19
+ onMounted(() => {
20
+ intervalId = setInterval(updateTime, props.updateInterval);
21
+ });
22
+
23
+ onUnmounted(() => {
24
+ if (intervalId) {
25
+ clearInterval(intervalId);
26
+ }
27
+ });
28
+
29
+ // Update immediately if date prop changes
30
+ watch(() => props.date, updateTime);
31
+ </script>
32
+
33
+ <template>
34
+ <span>{{ formattedTime }}</span>
35
+ </template>
package/dist/vue/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/vue/TimeAgo.vue
2
- var TimeAgo_default = "./TimeAgo-2qmfkrw6.vue";
2
+ var TimeAgo_default = "./TimeAgo-ajdd20a8.vue";
3
3
  export {
4
4
  TimeAgo_default as TimeAgo
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onomad",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Time formatting optimized for Serbian language",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -12,14 +12,17 @@
12
12
  "types": "./dist/index.d.ts"
13
13
  },
14
14
  "./vue": {
15
- "import": "./dist/vue/index.js",
16
- "types": "./dist/vue/index.d.ts"
15
+ "import": "./src/vue/index.ts",
16
+ "types": "./src/vue/index.ts"
17
17
  }
18
18
  },
19
+ "files": [
20
+ "dist",
21
+ "src/vue"
22
+ ],
19
23
  "scripts": {
20
- "build": "bun run build:core && bun run build:vue && bun run build:types",
24
+ "build": "bun run build:core && bun run build:types",
21
25
  "build:core": "bun build src/index.ts --outdir dist --target node --sourcemap=external",
22
- "build:vue": "bun build src/vue/index.ts --outdir dist/vue --target node --sourcemap=external --external vue",
23
26
  "build:types": "tsc --project tsconfig.build.json",
24
27
  "test": "bun test",
25
28
  "prepublishOnly": "bun run build"
@@ -47,8 +50,5 @@
47
50
  "vue": {
48
51
  "optional": true
49
52
  }
50
- },
51
- "dependencies": {
52
- "onomad": "^2.0.1"
53
53
  }
54
54
  }
@@ -0,0 +1,35 @@
1
+ <script setup lang="ts">
2
+ import { ref, onMounted, onUnmounted, watch } from 'vue';
3
+ import { timeago } from 'onomad';
4
+
5
+ const props = withDefaults(defineProps<{
6
+ date: Date | string;
7
+ updateInterval?: number;
8
+ }>(), {
9
+ updateInterval: 60000
10
+ });
11
+
12
+ const formattedTime = ref(timeago(new Date(props.date)));
13
+ let intervalId: ReturnType<typeof setInterval> | null = null;
14
+
15
+ const updateTime = () => {
16
+ formattedTime.value = timeago(new Date(props.date));
17
+ };
18
+
19
+ onMounted(() => {
20
+ intervalId = setInterval(updateTime, props.updateInterval);
21
+ });
22
+
23
+ onUnmounted(() => {
24
+ if (intervalId) {
25
+ clearInterval(intervalId);
26
+ }
27
+ });
28
+
29
+ // Update immediately if date prop changes
30
+ watch(() => props.date, updateTime);
31
+ </script>
32
+
33
+ <template>
34
+ <span>{{ formattedTime }}</span>
35
+ </template>
@@ -0,0 +1,7 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ declare module "*.vue" {
4
+ import type { DefineComponent } from "vue";
5
+ const component: DefineComponent<{}, {}, any>;
6
+ export default component;
7
+ }
@@ -0,0 +1 @@
1
+ export { default as TimeAgo } from "./TimeAgo.vue";
@@ -1,48 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches: [main]
6
- pull_request:
7
- branches: [main]
8
-
9
- jobs:
10
- test:
11
- name: Test
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v4
15
-
16
- - name: Setup Bun
17
- uses: oven-sh/setup-bun@v1
18
- with:
19
- bun-version: latest
20
-
21
- - name: Install dependencies
22
- run: bun install
23
-
24
- - name: Run tests
25
- run: bun test
26
-
27
- - name: Build
28
- run: bun run build
29
-
30
- - name: Check TypeScript
31
- run: bunx tsc --noEmit
32
-
33
- lint:
34
- name: Lint
35
- runs-on: ubuntu-latest
36
- steps:
37
- - uses: actions/checkout@v4
38
-
39
- - name: Setup Bun
40
- uses: oven-sh/setup-bun@v1
41
- with:
42
- bun-version: latest
43
-
44
- - name: Install dependencies
45
- run: bun install
46
-
47
- - name: Check formatting
48
- run: bunx prettier --check "src/**/*.ts"