parsec v2.0.2
ParSec
A duration parser and formatter to turn random garbage into program usable times.
Provides a clear, easy to use interface to parse strings into usable timings
Example:
Parsec('aug3 1920').format('{MONTH-NAME} {DAYS}{DAY-SUFFIX} {YEAR}')
// August 3rd 1920Documentation Navigation
Installation
NPM
Installing on NPM is simple, just open your terminal and run:
npm install parsec --saveYarn
to install with Yarn, open your terminal and use:
yarn add parsecLocales
Supported Locales
All languages supported by this module are translated to the best knowledge of the person submitting the translation, this means we are trying to get native speakers of the language to submit translations of time phrases in their local language, |Language|Native|Supported Since|Translator| |:------:|:----:|:-------------:|:--------:| |English|English|0.0.1|Fatalcenturion|
Planned Locales
This table contains languages which we are planning to implement into the module, but have not managed to do just yet. If you are a native speaker of any of the languages below and would like to help translate, please get in touch so we can send you a translation package.
| Language | Native |
|---|---|
| German | Deutsch |
| French | français |
| Spanish | español |
| Portuguese | português |
Suggest a Locale
To suggest a Locale for ParSec, please open an issue and use the "Locale" tag informing us of the locale you wish to add
Usage
ParSec
Importing the module:
const ParSec = require('parsec');Getting started:
This module is a hybrid function-object, this means that the module can be called by running both:
let parsed = ParSec('1 minute, 30 seconds and 145 milliseconds');And:
let parsed = ParSec.parse('1 minute, 30 seconds and 145 milliseconds');Note: in both cases here,
parsedis an instance ofTimeConstruct.TimeConstructis a custom class built to provide detailed information about your parsed results. Read the documentation onTimeConstructfor more information
Values:
self:Parameters: inputString:
StringDescription: Formats the provided string into an instance ofTimeConstruct. Usage:ParSec(<inputString>)
format:Parameters inputString:
StringDescription: Formats the provided string using internal values (Internal version of ParSec(string))
parse:Parameters inputString:
StringDescription: Formats the provided string into an instance ofTimeConstruct(Internal version of ParSec(string))
TimeConstruct
Layout:
Values:
locale:
Stringmilliseconds:Numberseconds:Numberminutes:Numberhours:Numberdays:Numberweeks:Numbermonths:Numberyears:Number
Methods:
format:Parameters inputString:
StringDescription: Formats the provided string using internal values (Internal version of ParSec(string))
into:Parameters inputString:
StringDescription: Formats the provided string, converting all internal values to the largest specified value (Internal version of ParSec(string))
More coming soon....
5 years ago
5 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
13 years ago