timeprettify 0.0.1 → 0.0.3
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/CHANGELOG.md +23 -11
- package/LICENSE +21 -21
- package/README.md +82 -82
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## 0.0.
|
|
4
|
-
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
- `
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
# timeprettify
|
|
2
|
+
|
|
3
|
+
## 0.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2e438c2`](https://github.com/orazchollaev/timeprettify/commit/2e438c2f47a53c0dcf5c06e8a740b8d3edd94318) Thanks [@orazchollaev](https://github.com/orazchollaev)! - use github changelog
|
|
8
|
+
|
|
9
|
+
## 0.0.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- d0ec928: test ci/cd pipeline
|
|
14
|
+
|
|
15
|
+
## 0.0.1
|
|
16
|
+
|
|
17
|
+
### First Release
|
|
18
|
+
|
|
19
|
+
- `format(seconds, options?)` — format duration from seconds
|
|
20
|
+
- `createFormatter(defaults)` — create reusable formatter with preset options
|
|
21
|
+
- Locale support: `en`, `tr`, `ru`
|
|
22
|
+
- Styles: `long`, `short`, `narrow`
|
|
23
|
+
- `units` option to limit output length
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 orazchollaev
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 orazchollaev
|
|
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
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
# timeprettify
|
|
2
|
-
|
|
3
|
-
> Lightweight duration formatter with multi-locale support.
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/timeprettify)
|
|
6
|
-
[](./LICENSE)
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Install
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
pnpm add timeprettify
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
import { format } from 'timeprettify'
|
|
22
|
-
|
|
23
|
-
format(3661) // '1 hour 1 minute'
|
|
24
|
-
format(3661, { locale: 'tr' }) // '1 saat 1 dakika'
|
|
25
|
-
format(3661, { locale: 'ru' }) // '1 час 1 минута'
|
|
26
|
-
format(3661, { style: 'short' }) // '1h 1min'
|
|
27
|
-
format(3661, { style: 'narrow' }) // '1h1m'
|
|
28
|
-
format(3661, { units: 1 }) // '1 hour'
|
|
29
|
-
format(3661, { locale: 'tr', style: 'short' }) // '1sa 1dk'
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
## Options
|
|
35
|
-
|
|
36
|
-
| Option | Type | Default | Description |
|
|
37
|
-
| -------- | ------------------------------- | -------- | --------------------------- |
|
|
38
|
-
| `locale` | `'en' \| 'tr' \| 'ru'` | `'en'` | Output language |
|
|
39
|
-
| `style` | `'long' \| 'short' \| 'narrow'` | `'long'` | Format style |
|
|
40
|
-
| `units` | `number` | `2` | Max number of units to show |
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## Styles
|
|
45
|
-
|
|
46
|
-
| Style | Example |
|
|
47
|
-
| -------- | ------------------- |
|
|
48
|
-
| `long` | `1 hour 30 minutes` |
|
|
49
|
-
| `short` | `1h 30min` |
|
|
50
|
-
| `narrow` | `1h30m` |
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## createFormatter
|
|
55
|
-
|
|
56
|
-
Create a reusable formatter with preset options:
|
|
57
|
-
|
|
58
|
-
```ts
|
|
59
|
-
import { createFormatter } from 'timeprettify'
|
|
60
|
-
|
|
61
|
-
const formatTr = createFormatter({ locale: 'tr' })
|
|
62
|
-
|
|
63
|
-
formatTr(3600) // '1 saat'
|
|
64
|
-
formatTr(90) // '1 dakika 30 saniye'
|
|
65
|
-
formatTr(3600, { style: 'short' }) // '1sa'
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## Locales
|
|
71
|
-
|
|
72
|
-
| Locale | Language | Plural forms |
|
|
73
|
-
| ------ | -------- | ----------------------- |
|
|
74
|
-
| `en` | English | singular / plural |
|
|
75
|
-
| `tr` | Turkish | no plural |
|
|
76
|
-
| `ru` | Russian | singular / few / plural |
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## License
|
|
81
|
-
|
|
82
|
-
MIT
|
|
1
|
+
# timeprettify
|
|
2
|
+
|
|
3
|
+
> Lightweight duration formatter with multi-locale support.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/timeprettify)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add timeprettify
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { format } from 'timeprettify'
|
|
22
|
+
|
|
23
|
+
format(3661) // '1 hour 1 minute'
|
|
24
|
+
format(3661, { locale: 'tr' }) // '1 saat 1 dakika'
|
|
25
|
+
format(3661, { locale: 'ru' }) // '1 час 1 минута'
|
|
26
|
+
format(3661, { style: 'short' }) // '1h 1min'
|
|
27
|
+
format(3661, { style: 'narrow' }) // '1h1m'
|
|
28
|
+
format(3661, { units: 1 }) // '1 hour'
|
|
29
|
+
format(3661, { locale: 'tr', style: 'short' }) // '1sa 1dk'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Options
|
|
35
|
+
|
|
36
|
+
| Option | Type | Default | Description |
|
|
37
|
+
| -------- | ------------------------------- | -------- | --------------------------- |
|
|
38
|
+
| `locale` | `'en' \| 'tr' \| 'ru'` | `'en'` | Output language |
|
|
39
|
+
| `style` | `'long' \| 'short' \| 'narrow'` | `'long'` | Format style |
|
|
40
|
+
| `units` | `number` | `2` | Max number of units to show |
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Styles
|
|
45
|
+
|
|
46
|
+
| Style | Example |
|
|
47
|
+
| -------- | ------------------- |
|
|
48
|
+
| `long` | `1 hour 30 minutes` |
|
|
49
|
+
| `short` | `1h 30min` |
|
|
50
|
+
| `narrow` | `1h30m` |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## createFormatter
|
|
55
|
+
|
|
56
|
+
Create a reusable formatter with preset options:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { createFormatter } from 'timeprettify'
|
|
60
|
+
|
|
61
|
+
const formatTr = createFormatter({ locale: 'tr' })
|
|
62
|
+
|
|
63
|
+
formatTr(3600) // '1 saat'
|
|
64
|
+
formatTr(90) // '1 dakika 30 saniye'
|
|
65
|
+
formatTr(3600, { style: 'short' }) // '1sa'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Locales
|
|
71
|
+
|
|
72
|
+
| Locale | Language | Plural forms |
|
|
73
|
+
| ------ | -------- | ----------------------- |
|
|
74
|
+
| `en` | English | singular / plural |
|
|
75
|
+
| `tr` | Turkish | no plural |
|
|
76
|
+
| `ru` | Russian | singular / few / plural |
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
MIT
|
package/dist/index.js
CHANGED
|
@@ -117,7 +117,7 @@ function a(t, n, r, a) {
|
|
|
117
117
|
}
|
|
118
118
|
function o(n, r = {}) {
|
|
119
119
|
let { locale: i = "en", style: s = "long", units: c = 2 } = r;
|
|
120
|
-
if (!e[i]) throw Error(`[
|
|
120
|
+
if (!e[i]) throw Error(`[timeprettify] Unknown locale: "${i}". Supported: en, tr, ru`);
|
|
121
121
|
if (n < 0) return o(-n, r);
|
|
122
122
|
if (n === 0) return a(0, "seconds", i, s);
|
|
123
123
|
let l = t(n), u = [];
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.TimePrettify={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t={en:{long:{days:{singular:`day`,plural:`days`,narrow:`d`},hours:{singular:`hour`,plural:`hours`,narrow:`h`},minutes:{singular:`minute`,plural:`minutes`,narrow:`m`},seconds:{singular:`second`,plural:`seconds`,narrow:`s`}},short:{days:`d`,hours:`h`,minutes:`min`,seconds:`sec`}},tr:{long:{days:{singular:`gün`,narrow:`g`},hours:{singular:`saat`,narrow:`sa`},minutes:{singular:`dakika`,narrow:`dk`},seconds:{singular:`saniye`,narrow:`sn`}},short:{days:`g`,hours:`sa`,minutes:`dk`,seconds:`sn`}},ru:{long:{days:{singular:`день`,few:`дня`,plural:`дней`,narrow:`д`},hours:{singular:`час`,few:`часа`,plural:`часов`,narrow:`ч`},minutes:{singular:`минута`,few:`минуты`,plural:`минут`,narrow:`м`},seconds:{singular:`секунда`,few:`секунды`,plural:`секунд`,narrow:`с`}},short:{days:`д`,hours:`ч`,minutes:`мин`,seconds:`сек`}}};function n(e){let t=Math.abs(Math.floor(e));return{days:Math.floor(t/86400),hours:Math.floor(t%86400/3600),minutes:Math.floor(t%3600/60),seconds:t%60}}function r(e,t){let n=e%10,r=e%100;return r>=11&&r<=19?t.plural??t.singular:n===1?t.singular:n>=2&&n<=4?t.few??t.singular:t.plural??t.singular}function i(e,t){return e===1?t.singular:t.plural??t.singular}function a(e,t,n){return n===`ru`?r(e,t):n===`tr`?t.singular:i(e,t)}function o(e,n,r,i){let o=t[r];return i===`narrow`?`${e}${o.long[n].narrow}`:i===`short`?`${e}${o.short[n]}`:`${e} ${a(e,o.long[n],r)}`}function s(e,r={}){let{locale:i=`en`,style:a=`long`,units:c=2}=r;if(!t[i])throw Error(`[
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.TimePrettify={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t={en:{long:{days:{singular:`day`,plural:`days`,narrow:`d`},hours:{singular:`hour`,plural:`hours`,narrow:`h`},minutes:{singular:`minute`,plural:`minutes`,narrow:`m`},seconds:{singular:`second`,plural:`seconds`,narrow:`s`}},short:{days:`d`,hours:`h`,minutes:`min`,seconds:`sec`}},tr:{long:{days:{singular:`gün`,narrow:`g`},hours:{singular:`saat`,narrow:`sa`},minutes:{singular:`dakika`,narrow:`dk`},seconds:{singular:`saniye`,narrow:`sn`}},short:{days:`g`,hours:`sa`,minutes:`dk`,seconds:`sn`}},ru:{long:{days:{singular:`день`,few:`дня`,plural:`дней`,narrow:`д`},hours:{singular:`час`,few:`часа`,plural:`часов`,narrow:`ч`},minutes:{singular:`минута`,few:`минуты`,plural:`минут`,narrow:`м`},seconds:{singular:`секунда`,few:`секунды`,plural:`секунд`,narrow:`с`}},short:{days:`д`,hours:`ч`,minutes:`мин`,seconds:`сек`}}};function n(e){let t=Math.abs(Math.floor(e));return{days:Math.floor(t/86400),hours:Math.floor(t%86400/3600),minutes:Math.floor(t%3600/60),seconds:t%60}}function r(e,t){let n=e%10,r=e%100;return r>=11&&r<=19?t.plural??t.singular:n===1?t.singular:n>=2&&n<=4?t.few??t.singular:t.plural??t.singular}function i(e,t){return e===1?t.singular:t.plural??t.singular}function a(e,t,n){return n===`ru`?r(e,t):n===`tr`?t.singular:i(e,t)}function o(e,n,r,i){let o=t[r];return i===`narrow`?`${e}${o.long[n].narrow}`:i===`short`?`${e}${o.short[n]}`:`${e} ${a(e,o.long[n],r)}`}function s(e,r={}){let{locale:i=`en`,style:a=`long`,units:c=2}=r;if(!t[i])throw Error(`[timeprettify] Unknown locale: "${i}". Supported: en, tr, ru`);if(e<0)return s(-e,r);if(e===0)return o(0,`seconds`,i,a);let l=n(e),u=[];l.days>0&&u.push(o(l.days,`days`,i,a)),l.hours>0&&u.push(o(l.hours,`hours`,i,a)),l.minutes>0&&u.push(o(l.minutes,`minutes`,i,a)),l.seconds>0&&u.push(o(l.seconds,`seconds`,i,a));let d=a===`narrow`?``:` `;return u.slice(0,c).join(d)}function c(e){return(t,n={})=>s(t,{...e,...n})}e.createFormatter=c,e.format=s});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "timeprettify",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Lightweight duration formatter with multi-locale support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://github.com/orazchollaev/timeprettify#readme",
|
|
41
41
|
"devDependencies": {
|
|
42
|
+
"@changesets/changelog-github": "^0.6.0",
|
|
42
43
|
"@changesets/cli": "^2.30.0",
|
|
43
44
|
"@typescript-eslint/eslint-plugin": "^8.57.1",
|
|
44
45
|
"@typescript-eslint/parser": "^8.57.1",
|