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 +20 -0
- package/dist/vue/TimeAgo-ajdd20a8.vue +35 -0
- package/dist/vue/index.js +1 -1
- package/package.json +8 -8
- package/src/vue/TimeAgo.vue +35 -0
- package/src/vue/env.d.ts +7 -0
- package/src/vue/index.ts +1 -0
- package/.github/workflows/ci.yml +0 -48
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onomad",
|
|
3
|
-
"version": "2.0.
|
|
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": "./
|
|
16
|
-
"types": "./
|
|
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:
|
|
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>
|
package/src/vue/env.d.ts
ADDED
package/src/vue/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as TimeAgo } from "./TimeAgo.vue";
|
package/.github/workflows/ci.yml
DELETED
|
@@ -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"
|