Skip to content

CompactJS/parse-time

Repository files navigation

@compactjs/parse-time

Tiny hour parser & stringifier

Version License: MIT

· Homepage · Report Bug / Request Feature ·

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 timo@bechtel.solutions

🤝 Contributing

Contributions, issues and feature requests are welcome!

  1. Check issues
  2. Fork the Project
  3. Create your Feature Branch (git checkout -b feat/AmazingFeature)
  4. Test your changes npm run test
  5. Commit your Changes (git commit -m 'feat: add amazingFeature')
  6. Push to the Branch (git push origin feat/AmazingFeature)
  7. 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