# millit

> This utility allow convert strings to milliseconds.

Latest version **0.0.7** (published 2023-08-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install millit
pnpm add millit
yarn add millit
bun add millit
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2023-08-02 |
| First published | 2023-06-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | DavidEsdrs |
| Maintainers | davidesdrs |
| Keywords | milliseconds, time, convert, parsing |

## Links

- npm: https://www.npmjs.com/package/millit
- Repository: https://github.com/DavidEsdrs/millit
- Homepage: https://github.com/DavidEsdrs/millit#readme
- Issues: https://github.com/DavidEsdrs/millit/issues
- npm.io page: https://npm.io/package/millit

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 0.0.7 (latest) — 2023-08-02
- 0.0.6 — 2023-06-02
- 0.0.5 — 2023-06-02
- 0.0.4 — 2023-06-02
- 0.0.3 — 2023-06-02
- 0.0.2 — 2023-06-02
- 0.0.1 — 2023-06-02

## README

# Millit
This utility allow convert strings to milliseconds. You can use even compost times.

## Examples
```js
millit('10 days') // 864000000
millit('10d') // 864000000
millit('5h') // 18000000
millit('12 hrs') // 43200000
millit('2.5hours') // 9000000
millit('1min 10s') // 70000
millit('10d 5seconds') // 864005000
millit('1year 45days') // 35445600000
millit("45days 1year") // 35445600000 - sames as before, order doesn't matter
millit('100h 12m') // 360720000
millit('1 days') // 86400000
millit('20') // 20
millit('-200h') // -720000000
```

## Installation
Install it with you favorite package manager:
```sh
npm install millit
OR
yarn add millit
```
Usage:

If you are using plain javascript:
```js
const millit = require("millit")

millit("10d")
```

if you are using typescript:
```ts
import millit from "millit"

millit("10d")
```

## Features
The fact that the order doesn't matter empowers you to dynammically sum up different dates whitout be afraid of date inconsistencies. Example:
```js
let myDateStr = "10d"
let sum10m = true

if(sum10m) {
  myDateStr += "10m"
  console.log(millit(myDateStr)) //864600000
} else {
  myDateStr += "1y"
  console.log(millit(myDateStr)) // 32421600000
}
```
**hint**: Try to change sum10m to `false`

**disclaimer**: When dynammically summing milliseconds along with other time units as above, always include the "ms" prefix. For example, "10d 10ms 20m" works as expected, while omitting the "ms" prefix in expressions like "10d 10 20m" will result in a silent error (NaN).

## How it compares with MS
```js
const tenDays = ms("10d")
const tenSecs = ms("10s")
const withMs = tenDays + tenSecs

const withMillit = millit("10d 10s")
console.log(withMs === withMillit) // true

console.log(ms(withMs)) // 10d
console.log(millit(withMillit)) // 10d
```

**hint**: This package is written intended to be fully compatible with the results that `ms` would give.

## Performance
This package is just a convenience for small projects. It is not intended to be a substitute for "ms" as this package uses simple for loops to search through strings. It's not as powerful as "ms" which uses regex search, known to be faster for larger inputs.

## Contribution
Contributions are welcome! If you want to contribute with this project, follow the steps:

1. Fork this repository
2. Create a branch: `git checkout -b my-contribution`
3. Do your changes and commit it: `git commit -m "fix: fix XYZ"`
4. Send your changes to the remote repository: `git push origin my-contribution`
5. Open a pull request in the original repository

Thanks in advance!

---
_Source: https://npm.io/package/millit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
