mirror of
https://github.com/cupcakearmy/uhrwerk.git
synced 2025-09-10 04:30:45 +00:00
Compare commits
4 Commits
ec25164cba
...
master
Author | SHA1 | Date | |
---|---|---|---|
c9514fa0aa | |||
d913a35ae9 | |||
99d35a9ade | |||
8679a04346 |
45
README.md
45
README.md
@@ -1,34 +1,31 @@
|
|||||||
# uhrwerk 🕰
|
# 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**: [1.6kB](https://bundlephobia.com/result?p=uhrwerk@1.0.0) vs moment js [231.7kb](https://bundlephobia.com/result?p=moment@latest)
|
📦 It's **tiny**: [2kB](https://bundlephobia.com/package/uhrwerk@latest) vs moment js [295kB](https://bundlephobia.com/result?p=moment@latest)
|
||||||
|
|
||||||
**Typescript typings included**
|
🌈 No dependencies, types 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 📒
|
||||||
@@ -37,13 +34,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
|
||||||
|
|
||||||
@@ -51,7 +48,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)`
|
||||||
@@ -144,9 +141,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')
|
||||||
|
40
package.json
40
package.json
@@ -1,17 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "uhrwerk",
|
"name": "uhrwerk",
|
||||||
"version": "1.1.0",
|
"version": "1.1.2",
|
||||||
"description": "time utility",
|
"description": "time utility",
|
||||||
"author": "Niccolo Borgioli",
|
"keywords": [
|
||||||
|
"time",
|
||||||
|
"interval",
|
||||||
|
"human-readable",
|
||||||
|
"utility"
|
||||||
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"author": "Niccolo Borgioli",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
|
||||||
"build": "tsup src/index.ts --format cjs,esm --dts --sourcemap",
|
|
||||||
"test": "pnpm run build && mocha",
|
|
||||||
"prepublishOnly": "pnpm run test"
|
|
||||||
},
|
|
||||||
"main": "./dist/index.cjs",
|
|
||||||
"types": "./dist/index.d.ts",
|
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"require": "./dist/index.cjs",
|
"require": "./dist/index.cjs",
|
||||||
@@ -19,18 +18,21 @@
|
|||||||
"types": "./dist/index.d.ts"
|
"types": "./dist/index.d.ts"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"keywords": [
|
"scripts": {
|
||||||
"time",
|
"build": "tsup src/index.ts --format cjs,esm --dts --sourcemap",
|
||||||
"interval",
|
"prepublishOnly": "pnpm run test",
|
||||||
"humand-readable",
|
"test": "pnpm run build && mocha"
|
||||||
"utility"
|
},
|
||||||
],
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "~10.0.0",
|
"@tsconfig/strictest": "^2.0.5",
|
||||||
"tsup": "^6.1.3",
|
"mocha": "^10.7.0",
|
||||||
"typescript": "~4.7.4"
|
"tsup": "^8.2.3",
|
||||||
}
|
"typescript": "^5.5.4"
|
||||||
|
},
|
||||||
|
"packageManager": "pnpm@9.6.0"
|
||||||
}
|
}
|
||||||
|
2175
pnpm-lock.yaml
generated
2175
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,23 +1,10 @@
|
|||||||
{
|
{
|
||||||
|
"extends": "@tsconfig/strictest/tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2020",
|
"target": "es2022",
|
||||||
"module": "commonjs",
|
"module": "es2022",
|
||||||
"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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user