onomad 1.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.
@@ -0,0 +1,48 @@
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"
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Dejan Simic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # Onomad
2
+
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
+
5
+ ## Instalacija
6
+
7
+ ```bash
8
+ npm install onomad
9
+ ```
10
+
11
+ Ili sa bun-om:
12
+
13
+ ```bash
14
+ bun add onomad
15
+ ```
16
+
17
+ ## Upotreba
18
+
19
+ ```typescript
20
+ import { timeago } from 'onomad';
21
+
22
+ const date = new Date(Date.now() - 5 * 60 * 1000);
23
+ console.log(timeago(date)); // "pre 5 minuta"
24
+
25
+ const yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000);
26
+ console.log(timeago(yesterday)); // "juče"
27
+
28
+ const lastWeek = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
29
+ console.log(timeago(lastWeek)); // "pre nedelju dana"
30
+ ```
31
+
32
+ ## API Referenca
33
+
34
+ ### `timeago(time: Date): string`
35
+
36
+ Glavna funkcija za formatiranje vremena.
37
+
38
+ - **Parametri**:
39
+ - `time` - Date objekat koji predstavlja vreme u prošlosti
40
+ - **Vraća**: String sa formatiranim vremenom na srpskom jeziku
41
+ - **Primeri**:
42
+ ```typescript
43
+ timeago(new Date(Date.now() - 30 * 1000)); // "malopre"
44
+ timeago(new Date(Date.now() - 60 * 1000)); // "pre minut"
45
+ timeago(new Date(Date.now() - 5 * 60 * 1000)); // "pre 5 minuta"
46
+ timeago(new Date(Date.now() - 30 * 60 * 1000)); // "pre pola sata"
47
+ timeago(new Date(Date.now() - 60 * 60 * 1000)); // "pre sat vremena"
48
+ timeago(new Date(Date.now() - 3 * 3600 * 1000)); // "pre 3 sata"
49
+ timeago(new Date(Date.now() - 24 * 3600 * 1000)); // "juče"
50
+ timeago(new Date(Date.now() - 3 * 86400 * 1000)); // "pre 3 dana"
51
+ timeago(new Date(Date.now() - 7 * 86400 * 1000)); // "pre nedelju dana"
52
+ timeago(new Date(Date.now() - 60 * 86400 * 1000));// "pre 2 meseca"
53
+ timeago(new Date(Date.now() - 365 * 86400 * 1000));// "pre godinu dana"
54
+ ```
55
+
56
+ ## Razvoj
57
+
58
+ ### Preduslov
59
+
60
+ - [Bun](https://bun.sh/) - Brzi JavaScript runtime i package manager
61
+
62
+ ### Instalacija
63
+
64
+ ```bash
65
+ git clone git@github.com:dejan/onomad.git
66
+ cd onomad
67
+
68
+ bun install
69
+ ```
70
+
71
+ ### Testiranje
72
+
73
+ ```bash
74
+ bun test
75
+ ```
76
+
77
+ ### Isprobavanje
78
+
79
+ ```bash
80
+ bun repl
81
+ ```
82
+
83
+ ```typescript
84
+ > import { timeago } from "./src/onomad";
85
+ > timeago(new Date(Date.now() - 5 * 60 * 1000))
86
+ 'pre 5 minuta'
87
+ ```
88
+
89
+ ### Formatiranje
90
+
91
+ ```bash
92
+ bunx prettier --check "src/**/*.ts" --write
93
+ ```
94
+
95
+ ### Pakovanje i objava
96
+
97
+ ```bash
98
+ bun run build
99
+
100
+ npm login
101
+ bun publish
102
+ ```
103
+
104
+ ## Licenca
105
+
106
+ MIT License
107
+
108
+ Copyright (c) 2025 Dejan Simic
109
+
110
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
111
+
112
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
113
+
114
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/index.js ADDED
@@ -0,0 +1,72 @@
1
+ // src/onomad.ts
2
+ function timeago(date) {
3
+ const now = new Date;
4
+ const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);
5
+ const minutes = Math.floor(seconds / 60);
6
+ const hours = Math.floor(seconds / 3600);
7
+ const days = Math.floor(seconds / 86400);
8
+ if (seconds < 60) {
9
+ return "malopre";
10
+ }
11
+ if (minutes < 60) {
12
+ if (minutes === 1) {
13
+ return "pre minut";
14
+ }
15
+ if (minutes === 30) {
16
+ return "pre pola sata";
17
+ }
18
+ return `pre ${minutes} minuta`;
19
+ }
20
+ if (hours < 20) {
21
+ if (hours === 1) {
22
+ return "pre sat vremena";
23
+ }
24
+ if (hours >= 2 && hours <= 4) {
25
+ return `pre ${hours} sata`;
26
+ }
27
+ return `pre ${hours} sati`;
28
+ }
29
+ if (hours < 48) {
30
+ return "juče";
31
+ }
32
+ if (days < 7) {
33
+ return `pre ${days} dana`;
34
+ }
35
+ if (days < 28) {
36
+ const weeks = Math.round(days / 7);
37
+ if (weeks === 1) {
38
+ return "pre nedelju dana";
39
+ }
40
+ if (weeks >= 2 && weeks <= 4) {
41
+ if (weeks === 2)
42
+ return "pre 2 nedelje";
43
+ if (weeks === 3)
44
+ return "pre 3 nedelje";
45
+ return `pre ${weeks} nedelje`;
46
+ }
47
+ return `pre ${weeks} nedelja`;
48
+ }
49
+ if (days < 300) {
50
+ const months = Math.round(days / 30);
51
+ if (months === 1) {
52
+ return "pre mesec dana";
53
+ }
54
+ if (months >= 2 && months <= 4) {
55
+ return `pre ${months} meseca`;
56
+ }
57
+ return `pre ${months} meseci`;
58
+ }
59
+ const years = Math.round(days / 365);
60
+ if (years === 1) {
61
+ return "pre godinu dana";
62
+ }
63
+ if (years >= 2 && years <= 4) {
64
+ return `pre ${years} godine`;
65
+ }
66
+ return `pre ${years} godina`;
67
+ }
68
+ export {
69
+ timeago
70
+ };
71
+
72
+ //# debugId=E7408E1C61FF255764756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/onomad.ts"],
4
+ "sourcesContent": [
5
+ "// return a string in Serbian like \"pre 5 minuta\" for a given date\nfunction timeago(date: Date): string {\n const now = new Date();\n const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);\n const minutes = Math.floor(seconds / 60);\n const hours = Math.floor(seconds / 3600);\n const days = Math.floor(seconds / 86400);\n\n // Less than 1 minute\n if (seconds < 60) {\n return \"malopre\";\n }\n\n // Minutes\n if (minutes < 60) {\n if (minutes === 1) {\n return \"pre minut\";\n }\n if (minutes === 30) {\n return \"pre pola sata\";\n }\n return `pre ${minutes} minuta`;\n }\n\n // Hours\n if (hours < 20) {\n if (hours === 1) {\n return \"pre sat vremena\";\n }\n if (hours >= 2 && hours <= 4) {\n return `pre ${hours} sata`;\n }\n return `pre ${hours} sati`;\n }\n\n // Yesterday (20-47 hours)\n if (hours < 48) {\n return \"juče\";\n }\n\n // Days (2-6 days)\n if (days < 7) {\n return `pre ${days} dana`;\n }\n\n // Weeks (7-27 days)\n if (days < 28) {\n const weeks = Math.round(days / 7);\n if (weeks === 1) {\n return \"pre nedelju dana\";\n }\n if (weeks >= 2 && weeks <= 4) {\n if (weeks === 2) return \"pre 2 nedelje\";\n if (weeks === 3) return \"pre 3 nedelje\";\n return `pre ${weeks} nedelje`;\n }\n return `pre ${weeks} nedelja`;\n }\n\n // Months (28-299 days)\n if (days < 300) {\n const months = Math.round(days / 30);\n if (months === 1) {\n return \"pre mesec dana\";\n }\n if (months >= 2 && months <= 4) {\n return `pre ${months} meseca`;\n }\n return `pre ${months} meseci`;\n }\n\n // Years\n const years = Math.round(days / 365);\n if (years === 1) {\n return \"pre godinu dana\";\n }\n if (years >= 2 && years <= 4) {\n return `pre ${years} godine`;\n }\n return `pre ${years} godina`;\n}\n\nexport { timeago };\n"
6
+ ],
7
+ "mappings": ";AACA,SAAS,OAAO,CAAC,MAAoB;AAAA,EACnC,MAAM,MAAM,IAAI;AAAA,EAChB,MAAM,UAAU,KAAK,OAAO,IAAI,QAAQ,IAAI,KAAK,QAAQ,KAAK,IAAI;AAAA,EAClE,MAAM,UAAU,KAAK,MAAM,UAAU,EAAE;AAAA,EACvC,MAAM,QAAQ,KAAK,MAAM,UAAU,IAAI;AAAA,EACvC,MAAM,OAAO,KAAK,MAAM,UAAU,KAAK;AAAA,EAGvC,IAAI,UAAU,IAAI;AAAA,IAChB,OAAO;AAAA,EACT;AAAA,EAGA,IAAI,UAAU,IAAI;AAAA,IAChB,IAAI,YAAY,GAAG;AAAA,MACjB,OAAO;AAAA,IACT;AAAA,IACA,IAAI,YAAY,IAAI;AAAA,MAClB,OAAO;AAAA,IACT;AAAA,IACA,OAAO,OAAO;AAAA,EAChB;AAAA,EAGA,IAAI,QAAQ,IAAI;AAAA,IACd,IAAI,UAAU,GAAG;AAAA,MACf,OAAO;AAAA,IACT;AAAA,IACA,IAAI,SAAS,KAAK,SAAS,GAAG;AAAA,MAC5B,OAAO,OAAO;AAAA,IAChB;AAAA,IACA,OAAO,OAAO;AAAA,EAChB;AAAA,EAGA,IAAI,QAAQ,IAAI;AAAA,IACd,OAAO;AAAA,EACT;AAAA,EAGA,IAAI,OAAO,GAAG;AAAA,IACZ,OAAO,OAAO;AAAA,EAChB;AAAA,EAGA,IAAI,OAAO,IAAI;AAAA,IACb,MAAM,QAAQ,KAAK,MAAM,OAAO,CAAC;AAAA,IACjC,IAAI,UAAU,GAAG;AAAA,MACf,OAAO;AAAA,IACT;AAAA,IACA,IAAI,SAAS,KAAK,SAAS,GAAG;AAAA,MAC5B,IAAI,UAAU;AAAA,QAAG,OAAO;AAAA,MACxB,IAAI,UAAU;AAAA,QAAG,OAAO;AAAA,MACxB,OAAO,OAAO;AAAA,IAChB;AAAA,IACA,OAAO,OAAO;AAAA,EAChB;AAAA,EAGA,IAAI,OAAO,KAAK;AAAA,IACd,MAAM,SAAS,KAAK,MAAM,OAAO,EAAE;AAAA,IACnC,IAAI,WAAW,GAAG;AAAA,MAChB,OAAO;AAAA,IACT;AAAA,IACA,IAAI,UAAU,KAAK,UAAU,GAAG;AAAA,MAC9B,OAAO,OAAO;AAAA,IAChB;AAAA,IACA,OAAO,OAAO;AAAA,EAChB;AAAA,EAGA,MAAM,QAAQ,KAAK,MAAM,OAAO,GAAG;AAAA,EACnC,IAAI,UAAU,GAAG;AAAA,IACf,OAAO;AAAA,EACT;AAAA,EACA,IAAI,SAAS,KAAK,SAAS,GAAG;AAAA,IAC5B,OAAO,OAAO;AAAA,EAChB;AAAA,EACA,OAAO,OAAO;AAAA;",
8
+ "debugId": "E7408E1C61FF255764756E2164756E21",
9
+ "names": []
10
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "onomad",
3
+ "version": "1.0.0",
4
+ "description": "Time formatting optimized for Serbian language",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "bun build src/index.ts --outdir dist --target node --sourcemap=external && bun run build:types",
17
+ "build:types": "tsc --emitDeclarationOnly --declaration --declarationMap",
18
+ "test": "bun test",
19
+ "prepublishOnly": "bun run build"
20
+ },
21
+ "keywords": [
22
+ "serbian",
23
+ "serbian-language",
24
+ "time-formatting"
25
+ ],
26
+ "author": "Dejan Simic <desimic@gmail.com>",
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/dejan/onomad.git"
31
+ },
32
+ "homepage": "https://github.com/dejan/onomad#readme",
33
+ "devDependencies": {
34
+ "@types/bun": "latest",
35
+ "typescript": "^5.3.3"
36
+ },
37
+ "peerDependencies": {
38
+ "typescript": "^5.0.0"
39
+ }
40
+ }