Compare commits

..

No commits in common. "99d35a9adea5fc92de1c79b2c05a776707572be1" and "ec25164cba66933bac7be56b6ae51cb4de0ca4b9" have entirely different histories.

4 changed files with 503 additions and 761 deletions

View File

@ -1,31 +1,34 @@
# uhrwerk 🕰 # uhrwerk 🕰
![package size](https://img.shields.io/bundlephobia/min/uhrwerk?style=flat) ![dependencies](https://badgen.net/david/dep/cupcakearmy/uhrwerk)
![downloads badge](https://img.shields.io/npm/dt/uhrwerk) ![downloads badge](https://badgen.net/npm/dt/uhrwerk)
![types badge](https://img.shields.io/npm/types/uhrwerk) ![types badge](https://badgen.net/npm/types/uhrwerk)
![version badge](https://img.shields.io/npm/v/uhrwerk) ![version badge](https://badgen.net/npm/v/uhrwerk)
![minzip size badge](https://badgen.net/bundlephobia/minzip/uhrwerk)
Minimal time duration utility. Replacement for MomentJS Durations. If you are looking into the time component of MomentJS check out this awesome library [dayjs](https://github.com/iamkun/dayjs). Minimal time duration utility. Replacement for MomentJS Durations. If you are looking into the time component of MomentJS check out this awesome library [dayjs](https://github.com/iamkun/dayjs).
📦 It's **tiny**: [2kB](https://bundlephobia.com/package/uhrwerk@latest) vs moment js [295kB](https://bundlephobia.com/result?p=moment@latest) 📦 It's **tiny**: [1.6kB](https://bundlephobia.com/result?p=uhrwerk@1.0.0) vs moment js [231.7kb](https://bundlephobia.com/result?p=moment@latest)
🌈 No dependencies, types included. **Typescript typings included**
## Quickstart 🚀 ## Quickstart 🚀
```typescript ```typescript
// Whatever import you prefer
// const { Duration } = require('uhrwerk')
import { Duration } from 'uhrwerk' import { Duration } from 'uhrwerk'
const d = new Duration(10, 'days') const d = new Duration(10, 'days')
d.subtract(1, 'week') d.subtract(1, 'week')
d.add(5, 'minutes') d.add(5, 'minutes')
d.humanize() // '3 days' d.humanize() // '3 days'
d.minutes() // 5 d.minutes() // 5
d.asMinute() // 4325 d.asMinute() // 4325
d.subtract(3, 'days') d.subtract(3, 'days')
d.humanize() // 'a few minutes' d.humanize() // 'a few minutes'
``` ```
### Reference 📒 ### Reference 📒
@ -34,13 +37,13 @@ d.humanize() // 'a few minutes'
- amount: number - amount: number
- interval: - interval:
- millisecond, milliseconds, ms - millisecond, milliseconds, ms
- second, seconds, s - second, seconds, s
- minute, minutes, m - minute, minutes, m
- hour, hours, h - hour, hours, h
- day, days, d - day, days, d
- week, weeks, w - week, weeks, w
- year, years, y - year, years, y
###### Examples ###### Examples
@ -48,7 +51,7 @@ d.humanize() // 'a few minutes'
const a = new Duration(1, 'day') const a = new Duration(1, 'day')
const b = new Duration(2, 'days') const b = new Duration(2, 'days')
const c = new Duration(0.5, 'year') const c = new Duration(0.5, 'year')
const d = new Duration(Date.now(), 'ms') const d = new Duration (Date.now(), 'ms')
``` ```
#### `.add(amount, interval)` #### `.add(amount, interval)`
@ -141,9 +144,9 @@ The order of the array is important. The first match will return, like in a stan
```javascript ```javascript
const humanizer = [ const humanizer = [
[(d) => d.days() > 1, (d) => `${d.days()} days`], [d => d.days() > 1, d => `${d.days()} days`],
[(d) => d.days() > 0, (d) => `1 day`], [d => d.days() > 0, d => `1 day`],
[() => true, () => 'catch all, below 1 day'], [() => true, () => 'catch all, below 1 day'],
] ]
const a = new Duration(2, 'days') const a = new Duration(2, 'days')

View File

@ -1,6 +1,6 @@
{ {
"name": "uhrwerk", "name": "uhrwerk",
"version": "1.1.1", "version": "1.1.0",
"description": "time utility", "description": "time utility",
"author": "Niccolo Borgioli", "author": "Niccolo Borgioli",
"license": "MIT", "license": "MIT",
@ -25,13 +25,12 @@
"keywords": [ "keywords": [
"time", "time",
"interval", "interval",
"human-readable", "humand-readable",
"utility" "utility"
], ],
"devDependencies": { "devDependencies": {
"@tsconfig/strictest": "^2.0.3", "mocha": "~10.0.0",
"mocha": "^10.3.0", "tsup": "^6.1.3",
"tsup": "^8.0.2", "typescript": "~4.7.4"
"typescript": "^5.3.3"
} }
} }

1189
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,23 @@
{ {
"extends": "@tsconfig/strictest/tsconfig.json",
"compilerOptions": { "compilerOptions": {
"target": "es2022", "target": "es2020",
"module": "es2022", "module": "commonjs",
"declaration": true, "declaration": true,
"outDir": "./lib", "outDir": "./lib",
"rootDir": "./src", "rootDir": "./src",
"removeComments": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true
} }
} }