Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/domchristie/juration
A natural language duration parser/stringifier written in javascript
https://github.com/domchristie/juration
Last synced: 12 days ago
JSON representation
A natural language duration parser/stringifier written in javascript
- Host: GitHub
- URL: https://github.com/domchristie/juration
- Owner: domchristie
- Created: 2011-09-18T09:20:59.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2020-08-28T10:18:25.000Z (about 4 years ago)
- Last Synced: 2024-10-09T22:01:50.337Z (about 1 month ago)
- Language: JavaScript
- Homepage: http://domchristie.github.com/juration
- Size: 258 KB
- Stars: 103
- Watchers: 10
- Forks: 28
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Juration.js
========A simple natural language duration parser written in javascript. Time ranges (in seconds) can also be converted to human readable strings. Check out the [demo](http://domchristie.github.com/juration).
Inspired by [chronic](https://github.com/mojombo/chronic/), and [chronic_duration](https://github.com/hpoydar/chronic_duration).
Usage
-----### Parsing
juration.parse("3mins 5secs"); // returns 185
### Stringifying
juration.stringify(185); // returns "3 mins 5 secs"
juration.stringify(185, { format: 'small' }); // returns "3 mins 5 secs"
juration.stringify(185, { format: 'micro' }); // returns "3m 5s"
juration.stringify(185, { format: 'long' }); // returns "3 minutes 5 seconds"
juration.stringify(185, { format: 'long', units: 1 }); // returns "3 minutes"
juration.stringify(3601, { format: 'micro', units: 2 }); // returns "1h"Examples
--------
Parse-able strings:* 12.4 secs
* 3 mins 4 sec
* 2 hrs 20 min
* 2h20min
* 6 mos 1 day
* 47 yrs 6 mos and 4d
* 3 weeks and 2 daysTodo
----
* Add customisable default unit option, e.g. `juration.parse("10", { defaultUnit: 'minutes' }) // returns 600`
* Parse chrono format i.e. hh:mm:ssLicence
-------
Juration is copyright © 2011 [Dom Christie](http://domchristie.co.uk) and released under the MIT license.