onomad 2.0.3 → 3.0.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 +30 -10
- package/package.json +8 -8
- package/src/vue/TimeAgo.vue +44 -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
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
TypeScript/JavaScript biblioteka za prikaz vremena u formatu optimizovanom za srpski jezik (npr: "pre 5 minuta"). Radi u browseru i na serveru (node.js / deno / bun).
|
|
4
4
|
|
|
5
|
+
## Čemu sve ovo?
|
|
6
|
+
|
|
7
|
+
JavaScript već ima ugrađeni Intl API za formatiranje vremena, ali rezultati nisu u potpunosti prilagođeni srpskom jeziku. Evo poređenja:
|
|
8
|
+
|
|
9
|
+
| Intl.RelativeTimeFormat | Onomad |
|
|
10
|
+
|-------------------------|--------|
|
|
11
|
+
| pre 30 sekundi | malopre |
|
|
12
|
+
| pre 1 minut | pre minut |
|
|
13
|
+
| pre 5 minuta | pre 5 minuta |
|
|
14
|
+
| pre 30 minuta | pre pola sata |
|
|
15
|
+
| pre 1 sat | pre sat vremena |
|
|
16
|
+
| pre 24 sata | juče |
|
|
17
|
+
| pre 7 dana | pre nedelju dana |
|
|
18
|
+
| pre 30 dana | pre mesec dana |
|
|
19
|
+
| pre 365 dana | pre godinu dana |
|
|
20
|
+
|
|
21
|
+
Onomad koristi prirodnije izraze koji su uobičajeni u svakodnevnom srpskom jeziku, kao što su `malopre`, `juče`, `pre pola sata` i `pre nedelju dana`, umesto doslovnih brojčanih prikaza.
|
|
22
|
+
|
|
5
23
|
## Instalacija
|
|
6
24
|
|
|
7
25
|
```bash
|
|
@@ -33,14 +51,6 @@ console.log(timeago(lastWeek)); // "pre nedelju dana"
|
|
|
33
51
|
|
|
34
52
|
Onomad dolazi sa gotovom Vue komponentom koja automatski ažurira prikaz vremena.
|
|
35
53
|
|
|
36
|
-
#### Instalacija
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
npm install onomad vue
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
#### Upotreba komponente
|
|
43
|
-
|
|
44
54
|
```vue
|
|
45
55
|
<script setup lang="ts">
|
|
46
56
|
import { TimeAgo } from 'onomad/vue';
|
|
@@ -55,12 +65,22 @@ const postDate = new Date(Date.now() - 5 * 60 * 1000);
|
|
|
55
65
|
</template>
|
|
56
66
|
```
|
|
57
67
|
|
|
58
|
-
Komponenta automatski ažurira
|
|
68
|
+
Komponenta automatski ažurira prikazani tekst svakih 60 sekundi (podrazumevano). Možete prilagoditi interval ažuriranja u sekundama:
|
|
59
69
|
|
|
60
70
|
```vue
|
|
61
|
-
|
|
71
|
+
<!-- Ažuriraj na svakih 30 sekundi -->
|
|
72
|
+
<TimeAgo :date="postDate" :update-interval="120" />
|
|
62
73
|
```
|
|
63
74
|
|
|
75
|
+
Možete takođe kontrolisati kada se automatsko ažuriranje zaustavlja koristeći `max-age-update` prop. Ako je vreme starije od određenog praga (u sekundama), interval neće biti pokrenut (podrazumevano: bez ograničenja):
|
|
76
|
+
|
|
77
|
+
```vue
|
|
78
|
+
<!-- Samo ažuriraj ako je vreme mlađe od 1 sat (3600 sekundi) -->
|
|
79
|
+
<TimeAgo :date="postDate" :max-age-update="3600" />
|
|
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`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onomad",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
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,44 @@
|
|
|
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
|
+
maxAgeUpdate?: number;
|
|
9
|
+
}>(), {
|
|
10
|
+
updateInterval: 60,
|
|
11
|
+
maxAgeUpdate: Infinity
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const formattedTime = ref(timeago(new Date(props.date)));
|
|
15
|
+
let intervalId: ReturnType<typeof setInterval> | null = null;
|
|
16
|
+
|
|
17
|
+
const updateTime = () => {
|
|
18
|
+
formattedTime.value = timeago(new Date(props.date));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getAgeInMs = () => {
|
|
22
|
+
return Date.now() - new Date(props.date).getTime();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
onMounted(() => {
|
|
26
|
+
const ageInMs = getAgeInMs();
|
|
27
|
+
if (ageInMs <= props.maxAgeUpdate * 1000) {
|
|
28
|
+
intervalId = setInterval(updateTime, props.updateInterval * 1000);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
onUnmounted(() => {
|
|
33
|
+
if (intervalId) {
|
|
34
|
+
clearInterval(intervalId);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Update immediately if date prop changes
|
|
39
|
+
watch(() => props.date, updateTime);
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<span>{{ formattedTime }}</span>
|
|
44
|
+
</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"
|