Skip to content

Latest commit

 

History

History
261 lines (179 loc) · 9.73 KB

api.md

File metadata and controls

261 lines (179 loc) · 9.73 KB

Classes

DurationParser
DurationTranslator
DurationValidator

Validate duration string without doing a conversion

TimeConverter

Allow time conversion between units

TimeGroups

Manage time groups and make some operations on them.

TimeIdentifiers

Manage time identifiers used in duration string. This class allows to use time identifiers from many languages.

DurationParser

Kind: global class

new DurationParser(locale, customTimeIdentifiers)

Param Type Default Description
locale string "en" Locale used for parsing duration
customTimeIdentifiers TimeIdentifiers | null Custom TimeIdentifiers object with added localized identifiers

durationParser.parse(input, targetUnit) ⇒ number | null

Return duration length from input expressed in target units

Kind: instance method of DurationParser

Param Type Default Description
input string Input duration string expressed in human-like pattern
targetUnit m Identifier of target time unit

durationParser.compose(time, sourceUnit, groupSeparator) ⇒ string | null

Create duration string from time amount

Kind: instance method of DurationParser

Param Default Description
time input time amount expressed in source time unit
sourceUnit m Source time unit identifier
groupSeparator Group separator used to join time groups in output duration string

DurationTranslator

Kind: global class

new DurationTranslator(timeIdentifiers)

Param Type
timeIdentifiers TimeIdentifiers | null

durationTranslator.translate(duration, sourceLocale, targetLocale) ⇒ string | null

Translate duration string from source to target locale

Kind: instance method of DurationTranslator

Param Description
duration Input duration string
sourceLocale Source locale name
targetLocale Target locale name

DurationValidator

Validate duration string without doing a conversion

Kind: global class

new DurationValidator(timeIdentifiers)

Param Type Default
timeIdentifiers TimeIdentifiers | null

durationValidator.validate(duration, locale) ⇒ boolean

Validate if duration string meets all syntactic requirements

Kind: instance method of DurationValidator

Param Type Default Description
duration string Duration string expressed in human-like format
locale string "en" Locale name which is used in duration string

TimeConverter

Allow time conversion between units

Kind: global class

timeConverter.convert(time, sourceUnit, targetUnit) ⇒ number

Convert time number expressed in source unit to number expressed in target unit; both units are basic one (en)

Kind: instance method of TimeConverter

Param Type Description
time number Input time number
sourceUnit string Source time unit
targetUnit string Target time unit

TimeGroups

Manage time groups and make some operations on them.

Kind: global class

new TimeGroups(timeIdentifiers)

Param Type Default
timeIdentifiers TimeIdentifiers | null

timeGroups.extractTimeGroups(duration, locale) ⇒ Array.<string>

Extract array of time groups which are in duration string

Kind: instance method of TimeGroups

Param Type Description
duration string Whole duration string
locale string Locale name of time identifiers used in duration string

timeGroups.parseTimeGroup(timeGroup, locale) ⇒ Object | null

Parse single time group to object having information about both unit and number of it

Kind: instance method of TimeGroups

Param Type Description
timeGroup string Single time group
locale string Locale name of time unit used in time group

timeGroups.buildTimeGroup(parsedTime) ⇒ string

Build a single time group from object created while parsing a group

Kind: instance method of TimeGroups

Param Type Description
parsedTime Object Object of parsed time group

timeGroups.composeDuration(timeGroups, groupSeparator) ⇒ string

Compose the whole duration string from array of time groups; given separator is used to join all groups

Kind: instance method of TimeGroups

Param Type Default Description
timeGroups Array.<string> Array of time groups in the same locale as for output
groupSeparator string " " Separator between every group in output duration string

TimeIdentifiers

Manage time identifiers used in duration string. This class allows to use time identifiers from many languages.

Kind: global class

timeIdentifiers.add(locale, newIdentifiers) ⇒ TimeIdentifiers

Register new time identifiers for the given locale

Kind: instance method of TimeIdentifiers

Param Type Description
locale string Name of locale for which time identifiers are registered
newIdentifiers New time identifiers

timeIdentifiers.get(locale) ⇒ Object

Return time identifiers for the given locale name; if not registered, return identifiers for 'en' locale

Kind: instance method of TimeIdentifiers

Param Type Description
locale string Locale name

timeIdentifiers.getInternalUnit(identifier, locale) ⇒ string | null

Return internal unit (en) for the time unit in the specified locale

Kind: instance method of TimeIdentifiers

Param Type Description
identifier string Localized time identifier
locale string Locale name