@compactjs/parse-time
v1.1.0
Published
Tiny hour parser
Downloads
115
Readme
Table of Contents
Install
NPM:
npm install @compactjs/parse-time
CDN:
<script src="https://unpkg.com/@compactjs/parse-time/dist/index.umd.js"></script>
Usage
As module:
import { parse, stringify } from '@compactjs/parse-time';
Example:
// parse a time string to a number
parse('13:30'); // => 13.5
parse('13:19:48'); // => 13.33
// stringify a number to a time string
stringify(13.33); // => 13:19:48
// formating options:
stringify(13.33, 'hh'); // => 13
stringify(13.33, 'hh:mm'); // => 13:19
stringify(13.33, 'hh:mm:ss'); // => 13:19:48
// it accepts numbers higher than 24
stringify(34.5); // => 34:30:00
// to limit to a range between 0 and 24 (or 0-12),
// I recommend to use https://github.com/CompactJS/limit
stringify(limit(34.5, 24)); // => 10:30:00
Run tests
npm run test
Contact
👤 Timo Bechtel [email protected]
- Website: https://timobechtel.com
- Twitter: @TimoBechtel
- GitHub: @TimoBechtel
🤝 Contributing
Contributions, issues and feature requests are welcome!
- Check issues
- Fork the Project
- Create your Feature Branch (
git checkout -b feat/AmazingFeature
) - Test your changes
npm run test
- Commit your Changes (
git commit -m 'feat: add amazingFeature'
) - Push to the Branch (
git push origin feat/AmazingFeature
) - Open a Pull Request
Commit messages
This project uses semantic-release for automated release versions. So commits in this project follow the Conventional Commits guidelines. I recommend using commitizen for automated commit messages.
Show your support
Give a ⭐️ if this project helped you!
📝 License
Distributed under the MIT License.
This README was generated with ❤️ by readme-md-generator