@phensley/cldr-core
Advanced tools
Comparing version 0.2.11 to 0.2.12
import { Bundle, DateFields, DateFieldType, Schema } from '@phensley/cldr-schema'; | ||
import { DecimalArg, ZonedDateTime } from '../../types'; | ||
import { DecimalArg } from '../../types'; | ||
import { WrapperInternal } from '..'; | ||
import { RelativeTimeFormatOptions } from './options'; | ||
export declare const fieldDifference: (a: ZonedDateTime, b: ZonedDateTime) => [DateFieldType, number]; | ||
export declare class DateFieldsInternal { | ||
@@ -7,0 +6,0 @@ readonly root: Schema; |
@@ -5,17 +5,18 @@ "use strict"; | ||
var types_1 = require("../../types"); | ||
exports.fieldDifference = function (a, b) { | ||
if (a.zoneId() !== b.zoneId()) { | ||
b = new types_1.ZonedDateTime(b.epochUTC(), a.zoneId()); | ||
} | ||
var diff = a.getYear() - b.getYear(); | ||
if (diff !== 0) { | ||
return ['year', diff]; | ||
} | ||
// TODO: | ||
// diff = a.getMonth() - b.getMonth(); | ||
// if (diff !== 0) { | ||
// } | ||
diff = a.getSecond() - b.getSecond(); | ||
return ['second', diff]; | ||
}; | ||
// TODO: expose a method to calculate field difference with different options | ||
// export const fieldDifference = (a: ZonedDateTime, b: ZonedDateTime): [DateFieldType, number] => { | ||
// if (a.zoneId() !== b.zoneId()) { | ||
// b = new ZonedDateTime(b.epochUTC(), a.zoneId()); | ||
// } | ||
// let diff = a.getYear() - b.getYear(); | ||
// if (diff !== 0) { | ||
// return ['year', diff]; | ||
// } | ||
// // TODO: | ||
// // diff = a.getMonth() - b.getMonth(); | ||
// // if (diff !== 0) { | ||
// // } | ||
// diff = a.getSecond() - b.getSecond(); | ||
// return ['second', diff]; | ||
// }; | ||
var DateFieldsInternal = /** @class */ (function () { | ||
@@ -22,0 +23,0 @@ function DateFieldsInternal(root, wrapper) { |
@@ -1,2 +0,2 @@ | ||
import { Bundle, CharacterOrderType, LineOrderType } from '@phensley/cldr-schema'; | ||
import { Bundle, CharacterOrderType, LineOrderType, ScriptType, TerritoryType } from '@phensley/cldr-schema'; | ||
import { GeneralInternal } from './internal'; | ||
@@ -9,2 +9,4 @@ export declare class GeneralEngine { | ||
lineOrder(): LineOrderType; | ||
getScriptDisplayName(code: ScriptType | string): string; | ||
getTerritoryDisplayName(code: TerritoryType | string, type?: string): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var cldr_schema_1 = require("@phensley/cldr-schema"); | ||
var GeneralEngine = /** @class */ (function () { | ||
@@ -14,2 +15,10 @@ function GeneralEngine(internal, bundle) { | ||
}; | ||
GeneralEngine.prototype.getScriptDisplayName = function (code) { | ||
return this.internal.getScriptDisplayName(this.bundle, code); | ||
}; | ||
GeneralEngine.prototype.getTerritoryDisplayName = function (code, type) { | ||
var alt = type === 'short' ? cldr_schema_1.Alt.SHORT : type === 'variant' ? cldr_schema_1.Alt.VARIANT : cldr_schema_1.Alt.NONE; | ||
var name = this.internal.getTerritoryDisplayName(this.bundle, code, alt); | ||
return name !== '' ? name : this.internal.getTerritoryDisplayName(this.bundle, code, cldr_schema_1.Alt.NONE); | ||
}; | ||
return GeneralEngine; | ||
@@ -16,0 +25,0 @@ }()); |
@@ -1,2 +0,2 @@ | ||
import { Bundle, Layout, Schema } from '@phensley/cldr-schema'; | ||
import { Alt, Bundle, Layout, Names, Schema } from '@phensley/cldr-schema'; | ||
export declare class GeneralInternal { | ||
@@ -6,5 +6,8 @@ readonly root: Schema; | ||
protected layout: Layout; | ||
protected names: Names; | ||
constructor(root: Schema, cacheSize?: number); | ||
characterOrder(bundle: Bundle): string; | ||
lineOrder(bundle: Bundle): string; | ||
getScriptDisplayName(bundle: Bundle, code: string): string; | ||
getTerritoryDisplayName(bundle: Bundle, code: string, alt: Alt): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var cldr_schema_1 = require("@phensley/cldr-schema"); | ||
var GeneralInternal = /** @class */ (function () { | ||
@@ -9,2 +10,3 @@ function GeneralInternal(root, cacheSize) { | ||
this.layout = root.Layout; | ||
this.names = root.Names; | ||
} | ||
@@ -17,2 +19,12 @@ GeneralInternal.prototype.characterOrder = function (bundle) { | ||
}; | ||
GeneralInternal.prototype.getScriptDisplayName = function (bundle, code) { | ||
var id = code; | ||
return this.names.scripts.displayName(bundle, id); | ||
}; | ||
GeneralInternal.prototype.getTerritoryDisplayName = function (bundle, code, alt) { | ||
var id = code; | ||
var name = this.names.territories.displayName(bundle, id, alt); | ||
// Fall back if preferred form is not available | ||
return name === '' ? this.names.territories.displayName(bundle, id, cldr_schema_1.Alt.NONE) : name; | ||
}; | ||
return GeneralInternal; | ||
@@ -19,0 +31,0 @@ }()); |
@@ -1,2 +0,2 @@ | ||
import { Bundle, FieldWidthType, IntervalFormatType, DayPeriodType, QuarterType, MonthType, WeekdayType, EraType } from '@phensley/cldr-schema'; | ||
import { IntervalFormatType } from '@phensley/cldr-schema'; | ||
import { ZonedDateTime } from '../../types/datetime'; | ||
@@ -6,2 +6,3 @@ import { GregorianInternal } from './internal'; | ||
import { Part } from '../../types'; | ||
import { ResourceBundle } from '../../resource/pack'; | ||
/** | ||
@@ -12,24 +13,4 @@ * Date formatting using the Gregorian calendar. | ||
protected internal: GregorianInternal; | ||
protected bundle: Bundle; | ||
constructor(internal: GregorianInternal, bundle: Bundle); | ||
/** | ||
* Get standalone day period. | ||
*/ | ||
getDayPeriod(dayPeriod: DayPeriodType, width?: FieldWidthType): string; | ||
/** | ||
* Get standalone era name. | ||
*/ | ||
getEra(era: EraType, width?: FieldWidthType): string; | ||
/** | ||
* Get standalone month name. | ||
*/ | ||
getMonth(month: MonthType, width?: FieldWidthType): string; | ||
/** | ||
* Get standalone quarter name. | ||
*/ | ||
getQuarter(quarter: QuarterType, width?: FieldWidthType): string; | ||
/** | ||
* Get standalone weekday name. | ||
*/ | ||
getWeekday(weekday: WeekdayType, width?: FieldWidthType): string; | ||
protected bundle: ResourceBundle; | ||
constructor(internal: GregorianInternal, bundle: ResourceBundle); | ||
getCompactISOWeekDate(date: ZonedDateTime): string; | ||
@@ -41,4 +22,2 @@ getExtendedISOWeekDate(date: ZonedDateTime): string; | ||
formatIntervalParts(start: ZonedDateTime, end: ZonedDateTime, skeleton: IntervalFormatType): Part[]; | ||
formatRelative(start: ZonedDateTime, end: ZonedDateTime): string; | ||
formatRelativeParts(start: ZonedDateTime, end: ZonedDateTime): Part[]; | ||
formatRaw(date: ZonedDateTime, pattern: string): string; | ||
@@ -45,0 +24,0 @@ formatRawParts(date: ZonedDateTime, pattern: string): Part[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var cldr_schema_1 = require("@phensley/cldr-schema"); | ||
var ISO_WEEKDATE_EXTENDED = "YYYY-'W'ww-"; | ||
@@ -14,50 +13,31 @@ var ISO_WEEKDATE_COMPACT = "YYYY'W'ww"; | ||
} | ||
/** | ||
* Get standalone day period. | ||
*/ | ||
GregorianEngine.prototype.getDayPeriod = function (dayPeriod, width) { | ||
if (width === void 0) { width = cldr_schema_1.FieldWidth.WIDE; } | ||
var impl = this.internal.dayPeriods.standAlone[width]; | ||
return impl === undefined ? '' : impl(this.bundle, dayPeriod, cldr_schema_1.Alt.NONE); | ||
}; | ||
/** | ||
* Get standalone era name. | ||
*/ | ||
GregorianEngine.prototype.getEra = function (era, width) { | ||
if (width === void 0) { width = cldr_schema_1.FieldWidth.WIDE; } | ||
switch (width) { | ||
case cldr_schema_1.FieldWidth.NARROW: | ||
case cldr_schema_1.FieldWidth.SHORT: | ||
return this.internal.eras.narrow(this.bundle, era); | ||
case cldr_schema_1.FieldWidth.ABBREVIATED: | ||
return this.internal.eras.abbr(this.bundle, era); | ||
case cldr_schema_1.FieldWidth.WIDE: | ||
default: | ||
return this.internal.eras.names(this.bundle, era); | ||
} | ||
}; | ||
/** | ||
* Get standalone month name. | ||
*/ | ||
GregorianEngine.prototype.getMonth = function (month, width) { | ||
if (width === void 0) { width = cldr_schema_1.FieldWidth.WIDE; } | ||
var impl = this.internal.months.standAlone[width]; | ||
return impl === undefined ? '' : impl(this.bundle, month); | ||
}; | ||
/** | ||
* Get standalone quarter name. | ||
*/ | ||
GregorianEngine.prototype.getQuarter = function (quarter, width) { | ||
if (width === void 0) { width = cldr_schema_1.FieldWidth.WIDE; } | ||
var impl = this.internal.quarters.standAlone[width]; | ||
return impl === undefined ? '' : impl(this.bundle, quarter); | ||
}; | ||
/** | ||
* Get standalone weekday name. | ||
*/ | ||
GregorianEngine.prototype.getWeekday = function (weekday, width) { | ||
if (width === void 0) { width = cldr_schema_1.FieldWidth.WIDE; } | ||
var impl = this.internal.weekdays.standAlone[width]; | ||
return impl === undefined ? '' : impl(this.bundle, weekday); | ||
}; | ||
// TODO: rework these to return standalone field for a given 'now' | ||
// getDayPeriod(dayPeriod: DayPeriodType, width: FieldWidthType = FieldWidth.WIDE): string { | ||
// const impl = this.internal.dayPeriods.standAlone[width]; | ||
// return impl === undefined ? '' : impl(this.bundle, dayPeriod, Alt.NONE); | ||
// } | ||
// getEra(era: EraType, width: FieldWidthType = FieldWidth.WIDE): string { | ||
// switch (width) { | ||
// case FieldWidth.NARROW: | ||
// case FieldWidth.SHORT: | ||
// return this.internal.eras.narrow(this.bundle, era); | ||
// case FieldWidth.ABBREVIATED: | ||
// return this.internal.eras.abbr(this.bundle, era); | ||
// case FieldWidth.WIDE: | ||
// default: | ||
// return this.internal.eras.names(this.bundle, era); | ||
// } | ||
// } | ||
// getMonth(month: MonthType, width: FieldWidthType = FieldWidth.WIDE): string { | ||
// const impl = this.internal.months.standAlone[width]; | ||
// return impl === undefined ? '' : impl(this.bundle, month); | ||
// } | ||
// getQuarter(quarter: QuarterType, width: FieldWidthType = FieldWidth.WIDE): string { | ||
// const impl = this.internal.quarters.standAlone[width]; | ||
// return impl === undefined ? '' : impl(this.bundle, quarter); | ||
// } | ||
// getWeekday(weekday: WeekdayType, width: FieldWidthType = FieldWidth.WIDE): string { | ||
// const impl = this.internal.weekdays.standAlone[width]; | ||
// return impl === undefined ? '' : impl(this.bundle, weekday); | ||
// } | ||
GregorianEngine.prototype.getCompactISOWeekDate = function (date) { | ||
@@ -89,8 +69,9 @@ return this.getISOWeekDate(date, ISO_WEEKDATE_COMPACT); | ||
}; | ||
GregorianEngine.prototype.formatRelative = function (start, end) { | ||
return ''; | ||
}; | ||
GregorianEngine.prototype.formatRelativeParts = function (start, end) { | ||
return []; | ||
}; | ||
// TODO: | ||
// formatRelative(start: ZonedDateTime, end: ZonedDateTime): string { | ||
// return ''; | ||
// } | ||
// formatRelativeParts(start: ZonedDateTime, end: ZonedDateTime): Part[] { | ||
// return []; | ||
// } | ||
GregorianEngine.prototype.formatRaw = function (date, pattern) { | ||
@@ -97,0 +78,0 @@ return this.internal.formatRaw(this.bundle, date, pattern); |
import { Bundle, DayPeriodsFormats, Gregorian, ErasFormat, QuartersFormats, MonthsFormats, Schema, TimeZoneNames, WeekdaysFormat, WeekdaysFormats } from '@phensley/cldr-schema'; | ||
import { DateTimeNode } from '../../parsing/patterns/date'; | ||
import { GregorianFormatOptions } from './options'; | ||
import { DayPeriodRules } from './rules'; | ||
import { Cache } from '../../utils/cache'; | ||
import { Part, ZonedDateTime } from '../../types'; | ||
import { WrapperInternal } from '../wrapper'; | ||
import { ResourceBundle } from '../../resource/pack'; | ||
/** | ||
* Function that formats a given date field. | ||
*/ | ||
export declare type FormatterFunc = (bundle: Bundle, date: ZonedDateTime, ch: string, width: number) => string; | ||
export declare type FormatterFunc = (bundle: ResourceBundle, date: ZonedDateTime, ch: string, width: number) => string; | ||
export interface FieldFormatter { | ||
@@ -34,2 +36,3 @@ readonly type: string; | ||
readonly hourFormatCache: Cache<[DateTimeNode[], DateTimeNode[]]>; | ||
readonly dayPeriodRules: DayPeriodRules; | ||
private impl; | ||
@@ -40,3 +43,3 @@ constructor(root: Schema, wrapper: WrapperInternal, cacheSize?: number); | ||
*/ | ||
format(bundle: Bundle, date: ZonedDateTime, options: GregorianFormatOptions): string; | ||
format(bundle: ResourceBundle, date: ZonedDateTime, options: GregorianFormatOptions): string; | ||
/** | ||
@@ -46,10 +49,10 @@ * Format a pattern into an array of parts, each part being either a string literal | ||
*/ | ||
formatParts(bundle: Bundle, date: ZonedDateTime, options: GregorianFormatOptions): Part[]; | ||
formatParts(bundle: ResourceBundle, date: ZonedDateTime, options: GregorianFormatOptions): Part[]; | ||
/** | ||
* Format a date-time interval pattern as a sring. | ||
*/ | ||
formatInterval(bundle: Bundle, start: ZonedDateTime, end: ZonedDateTime, pattern: string): string; | ||
formatIntervalParts(bundle: Bundle, start: ZonedDateTime, end: ZonedDateTime, pattern: string): Part[]; | ||
formatRaw(bundle: Bundle, date: ZonedDateTime, pattern: string): string; | ||
formatRawParts(bundle: Bundle, date: ZonedDateTime, pattern: string): Part[]; | ||
formatInterval(bundle: ResourceBundle, start: ZonedDateTime, end: ZonedDateTime, pattern: string): string; | ||
formatIntervalParts(bundle: ResourceBundle, start: ZonedDateTime, end: ZonedDateTime, pattern: string): Part[]; | ||
formatRaw(bundle: ResourceBundle, date: ZonedDateTime, pattern: string): string; | ||
formatRawParts(bundle: ResourceBundle, date: ZonedDateTime, pattern: string): Part[]; | ||
protected getDatePattern(bundle: Bundle, key: string | undefined): DateTimeNode[] | undefined; | ||
@@ -65,3 +68,3 @@ protected getTimePattern(bundle: Bundle, key: string | undefined): DateTimeNode[] | undefined; | ||
protected dayPeriodExt(bundle: Bundle, date: ZonedDateTime, field: string, width: number): string; | ||
protected dayPeriodFlex(bundle: Bundle, date: ZonedDateTime, field: string, width: number): string; | ||
protected dayPeriodFlex(bundle: ResourceBundle, date: ZonedDateTime, field: string, width: number): string; | ||
protected era(bundle: Bundle, date: ZonedDateTime, field: string, width: number): string; | ||
@@ -68,0 +71,0 @@ protected fractionalSecond(bundle: Bundle, date: ZonedDateTime, field: string, width: number): string; |
@@ -6,2 +6,3 @@ "use strict"; | ||
var date_1 = require("../../parsing/patterns/date"); | ||
var rules_1 = require("./rules"); | ||
var cache_1 = require("../../utils/cache"); | ||
@@ -83,2 +84,3 @@ var string_1 = require("../../utils/string"); | ||
this.hourFormatCache = new cache_1.Cache(parseHourFormat, cacheSize); | ||
this.dayPeriodRules = new rules_1.DayPeriodRules(cacheSize); | ||
} | ||
@@ -244,3 +246,3 @@ /** | ||
var format = this.dayPeriods.format; | ||
var key = date.getHour() < 13 ? 'am' : 'pm'; | ||
var key = date.getHour() < 12 ? 'am' : 'pm'; | ||
switch (width) { | ||
@@ -259,9 +261,12 @@ case 5: | ||
var minute = date.getMinute(); | ||
var key = hour < 13 ? 'am' : 'pm'; | ||
var key = hour < 12 ? 'am' : 'pm'; | ||
// Set extended key which may not exist for some locales, in which case we | ||
// fall back to "am" / "pm" | ||
var extkey = key; | ||
if (minute === 0) { | ||
if (hour === 0) { | ||
key = 'midnight'; | ||
extkey = 'midnight'; | ||
} | ||
else if (hour === 12) { | ||
key = 'noon'; | ||
extkey = 'noon'; | ||
} | ||
@@ -271,2 +276,19 @@ } | ||
case 5: | ||
return format.narrow(bundle, extkey, cldr_schema_1.Alt.NONE) || format.narrow(bundle, key, cldr_schema_1.Alt.NONE); | ||
case 4: | ||
return format.wide(bundle, extkey, cldr_schema_1.Alt.NONE) || format.wide(bundle, key, cldr_schema_1.Alt.NONE); | ||
default: | ||
return format.abbreviated(bundle, extkey, cldr_schema_1.Alt.NONE) || format.abbreviated(bundle, key, cldr_schema_1.Alt.NONE); | ||
} | ||
}; | ||
GregorianInternal.prototype.dayPeriodFlex = function (bundle, date, field, width) { | ||
var minutes = (date.getHour() * 60) + date.getMinute(); | ||
var key = this.dayPeriodRules.get(bundle, minutes); | ||
if (key === undefined) { | ||
// Fallback to extended day period | ||
return this.dayPeriodExt(bundle, date, field, width); | ||
} | ||
var format = this.dayPeriods.format; | ||
switch (width) { | ||
case 5: | ||
return format.narrow(bundle, key, cldr_schema_1.Alt.NONE); | ||
@@ -279,6 +301,2 @@ case 4: | ||
}; | ||
GregorianInternal.prototype.dayPeriodFlex = function (bundle, date, field, width) { | ||
// TODO: need to embed the dayPeriodRules. | ||
return ''; | ||
}; | ||
GregorianInternal.prototype.era = function (bundle, date, field, width) { | ||
@@ -285,0 +303,0 @@ var format = this.eras; |
export * from './datefields'; | ||
export * from './general'; | ||
export * from './gregorian'; | ||
export * from './names'; | ||
export * from './numbers'; | ||
@@ -6,0 +5,0 @@ export * from './plurals'; |
@@ -9,3 +9,2 @@ "use strict"; | ||
__export(require("./gregorian")); | ||
__export(require("./names")); | ||
__export(require("./numbers")); | ||
@@ -12,0 +11,0 @@ __export(require("./plurals")); |
@@ -55,3 +55,3 @@ "use strict"; | ||
var d = types_1.coerceDecimal(n); | ||
var params = this.getNumberParams(options.nu); | ||
var params = this.numberParams.getNumberParams(options.nu); | ||
var _a = this.internal.formatDecimal(this.bundle, render_1.STRING_RENDERER, d, options, params), result = _a[0], plural = _a[1]; | ||
@@ -63,3 +63,3 @@ return result; | ||
var d = types_1.coerceDecimal(n); | ||
var params = this.getNumberParams(options.nu); | ||
var params = this.numberParams.getNumberParams(options.nu); | ||
var _a = this.internal.formatDecimal(this.bundle, render_1.PARTS_RENDERER, d, options, params), result = _a[0], plural = _a[1]; | ||
@@ -71,3 +71,3 @@ return result; | ||
var d = types_1.coerceDecimal(n); | ||
var params = this.getNumberParams(options.nu); | ||
var params = this.numberParams.getNumberParams(options.nu, 'finance'); | ||
return this.internal.formatCurrency(this.bundle, render_1.STRING_RENDERER, d, code, options, params); | ||
@@ -78,3 +78,3 @@ }; | ||
var d = types_1.coerceDecimal(n); | ||
var params = this.getNumberParams(options.nu); | ||
var params = this.numberParams.getNumberParams(options.nu); | ||
return this.internal.formatCurrency(this.bundle, render_1.PARTS_RENDERER, d, code, options, params); | ||
@@ -81,0 +81,0 @@ }; |
@@ -20,5 +20,2 @@ "use strict"; | ||
this.numberPatternCache = new cache_1.Cache(number_1.parseNumberPattern, cacheSize); | ||
// this.currencyFormats = root.Numbers.currencyFormats; | ||
// this.decimalFormats = root.Numbers.decimalFormats; | ||
// this.percentFormats = root.Numbers.percentFormats; | ||
} | ||
@@ -25,0 +22,0 @@ NumbersInternal.prototype.formatDecimal = function (bundle, renderer, n, options, params) { |
@@ -9,7 +9,7 @@ import { Bundle, NumberSystemName } from '@phensley/cldr-schema'; | ||
private numberSystems; | ||
private defaultParams; | ||
constructor(bundle: Bundle, internal: NumbersInternal); | ||
getNumberParams(numberSystem?: NumberSystemType): NumberParams; | ||
getNumberParams(numberSystem?: NumberSystemType, defaultSystem?: NumberSystemType): NumberParams; | ||
protected select(numberSystem: NumberSystemType): NumberSystemName; | ||
protected lookup(numberSystem: NumberSystemName): NumberParams; | ||
protected build(numberSystemName: NumberSystemName): NumberParams; | ||
} |
@@ -11,18 +11,31 @@ "use strict"; | ||
this.numberSystems = internal.root.Numbers.numberSystems(bundle); | ||
this.defaultParams = this.lookup(this.numberSystems.default); | ||
} | ||
NumberParamsCache.prototype.getNumberParams = function (numberSystem) { | ||
NumberParamsCache.prototype.getNumberParams = function (numberSystem, defaultSystem) { | ||
// Default numbering system for a locale unless explicitly overridden | ||
// https://www.unicode.org/reports/tr35/tr35-33/tr35-numbers.html#defaultNumberingSystem | ||
if (defaultSystem === undefined) { | ||
defaultSystem = 'default'; | ||
} | ||
if (numberSystem === undefined) { | ||
numberSystem = 'native'; | ||
numberSystem = defaultSystem; | ||
} | ||
var realName = this.select(numberSystem); | ||
// Handle invalid number systems by returning the specified default | ||
// TODO: include algorithmic number system check | ||
if (systems_1.numericNumberingDigits[realName] === undefined) { | ||
realName = this.select(defaultSystem); | ||
} | ||
return this.lookup(realName); | ||
}; | ||
NumberParamsCache.prototype.select = function (numberSystem) { | ||
switch (numberSystem) { | ||
case 'default': | ||
return this.defaultParams; | ||
case 'native': | ||
case 'finance': | ||
case 'traditional': | ||
numberSystem = this.numberSystems[numberSystem]; | ||
break; | ||
// Dereference to find real name of number system | ||
return this.numberSystems[numberSystem]; | ||
default: | ||
return numberSystem; | ||
} | ||
return this.lookup(numberSystem); | ||
}; | ||
@@ -41,5 +54,7 @@ NumberParamsCache.prototype.lookup = function (numberSystem) { | ||
var currencySpacing = info.currencyFormats.currencySpacing; | ||
// Fetch standard pattern to determine grouping digits | ||
var standardRaw = info.decimalFormats.standard(this.bundle); | ||
var standard = this.internal.getNumberPattern(standardRaw, false); | ||
var digits = systems_1.numericNumberingDigits[numberSystemName] || systems_1.numericNumberingDigits.latn; | ||
// Decimal digits for the number system | ||
var digits = systems_1.numericNumberingDigits[numberSystemName]; | ||
return { | ||
@@ -46,0 +61,0 @@ numberSystemName: numberSystemName, |
@@ -13,5 +13,9 @@ export declare const LANGUAGE = 0; | ||
protected core: (undefined | string)[]; | ||
protected _extensions?: string[]; | ||
protected _extensions?: { | ||
[x: string]: string[]; | ||
}; | ||
protected _privateUse?: string; | ||
constructor(language?: string, script?: string, region?: string, variant?: string, extensions?: string[], privateUse?: string); | ||
constructor(language?: string, script?: string, region?: string, variant?: string, extensions?: { | ||
[x: string]: string[]; | ||
}, privateUse?: string); | ||
/** | ||
@@ -46,6 +50,13 @@ * Language subtag. | ||
/** | ||
* Extension subtags. | ||
* Return a copy of this language tag's extensions map. | ||
*/ | ||
extensions(): string[]; | ||
extensions(): { | ||
[x: string]: string[]; | ||
}; | ||
/** | ||
* Return a copy of the extensions of the given type. Use 'u' for Unicode | ||
* and 't' for Transforms. | ||
*/ | ||
extensionSubtags(key: string): string[]; | ||
/** | ||
* Private use subtag. | ||
@@ -52,0 +63,0 @@ */ |
@@ -50,3 +50,3 @@ "use strict"; | ||
]; | ||
this._extensions = extensions || []; | ||
this._extensions = extensions || {}; | ||
this._privateUse = privateUse || ''; | ||
@@ -97,8 +97,23 @@ } | ||
/** | ||
* Extension subtags. | ||
* Return a copy of this language tag's extensions map. | ||
*/ | ||
LanguageTag.prototype.extensions = function () { | ||
return this._extensions === undefined ? [] : this._extensions.slice(0); | ||
var exts = this._extensions; | ||
var res = {}; | ||
if (exts !== undefined) { | ||
Object.keys(exts).forEach(function (k) { | ||
res[k] = exts[k]; | ||
}); | ||
} | ||
return res; | ||
}; | ||
/** | ||
* Return a copy of the extensions of the given type. Use 'u' for Unicode | ||
* and 't' for Transforms. | ||
*/ | ||
LanguageTag.prototype.extensionSubtags = function (key) { | ||
var exts = this._extensions === undefined ? [] : this._extensions[key]; | ||
return exts === undefined ? [] : exts.slice(0); | ||
}; | ||
/** | ||
* Private use subtag. | ||
@@ -146,4 +161,10 @@ */ | ||
}); | ||
if (Array.isArray(this._extensions) && this._extensions.length > 0) { | ||
buf += SEP + this._extensions.join(SEP); | ||
var exts = this._extensions; | ||
if (exts !== undefined) { | ||
Object.keys(exts).sort().forEach(function (k) { | ||
var vals = exts[k]; | ||
if (vals !== undefined && vals.length > 0) { | ||
buf += SEP + k + SEP + exts[k].join(SEP); | ||
} | ||
}); | ||
} | ||
@@ -150,0 +171,0 @@ if (typeof this._privateUse === 'string' && this._privateUse.length > 0) { |
@@ -32,2 +32,11 @@ "use strict"; | ||
var PRIVATEUSE_SUBTAG = /^[\da-z]{1,8}$/i; | ||
// https://www.unicode.org/reports/tr35/tr35-33/tr35.html#Key_And_Type_Definitions_ | ||
var UNICODE_EXTENSION_KEYS = { | ||
ca: 1, | ||
co: 1, | ||
cu: 1, | ||
nu: 1, | ||
tz: 1, | ||
va: 1 // common variant type | ||
}; | ||
// Grandfathered irregular and regular tags from IANA registry. | ||
@@ -59,3 +68,3 @@ var GRANDFATHERED_TAGS = __assign({}, string_1.stringToObject(subtags.grandfatheredRaw, '|', ':'), { | ||
this.variants = []; | ||
this.extensions = []; | ||
this.extensions = {}; | ||
this.privateUse = ''; | ||
@@ -125,2 +134,3 @@ this.str = str; | ||
LanguageTagParser.prototype.parseExtensions = function (parts) { | ||
var parsed = false; | ||
while (parts.length > 0) { | ||
@@ -132,2 +142,3 @@ var prefix = match(parts, EXTENSION_PREFIX); | ||
var subs = []; | ||
var temp = ''; | ||
while (parts.length > 0) { | ||
@@ -138,9 +149,23 @@ var subtag = match(parts, EXTENSION_SUBTAG); | ||
} | ||
subs.push(subtag); | ||
if (UNICODE_EXTENSION_KEYS[subtag] !== 1) { | ||
temp += temp ? SEP + subtag : subtag; | ||
continue; | ||
} | ||
if (temp) { | ||
subs.push(temp); | ||
} | ||
temp = subtag; | ||
} | ||
if (temp) { | ||
subs.push(temp); | ||
} | ||
if (subs.length > 0) { | ||
this.extensions.push("" + prefix + SEP + subs.join(SEP)); | ||
parsed = true; | ||
subs.sort(); | ||
var curr = this.extensions[prefix]; | ||
curr = curr === undefined ? subs : curr.concat(subs); | ||
this.extensions[prefix] = curr.sort(); | ||
} | ||
} | ||
return this.extensions.length !== 0; | ||
return parsed; | ||
}; | ||
@@ -147,0 +172,0 @@ LanguageTagParser.prototype.parsePrivateUse = function (parts) { |
@@ -6,2 +6,8 @@ import { Bundle } from '@phensley/cldr-schema'; | ||
}; | ||
export interface ResourceBundle extends Bundle { | ||
calendarSystem(): string; | ||
numberSystem(): string; | ||
languageScript(): string; | ||
languageRegion(): string; | ||
} | ||
export declare class StringBundle implements Bundle { | ||
@@ -13,2 +19,6 @@ readonly id: string; | ||
readonly index: ExceptionIndex | undefined; | ||
private _calendarSystem; | ||
private _numberSystem; | ||
private _languageRegion; | ||
private _languageScript; | ||
constructor(id: string, tag: LanguageTag, strings: string[], exceptions: string[], index?: ExceptionIndex | undefined); | ||
@@ -18,2 +28,6 @@ bundleId(): string; | ||
region(): string; | ||
languageScript(): string; | ||
languageRegion(): string; | ||
calendarSystem(): string; | ||
numberSystem(): string; | ||
get(offset: number): string; | ||
@@ -27,6 +41,10 @@ } | ||
*/ | ||
export declare class DummyBundle implements Bundle { | ||
export declare class DummyBundle implements ResourceBundle { | ||
bundleId(): string; | ||
language(): string; | ||
region(): string; | ||
languageScript(): string; | ||
languageRegion(): string; | ||
calendarSystem(): string; | ||
numberSystem(): string; | ||
get(offset: number): string; | ||
@@ -49,3 +67,3 @@ } | ||
}); | ||
get(tag: LanguageTag): Bundle; | ||
get(tag: LanguageTag): ResourceBundle; | ||
private decode(region); | ||
@@ -66,3 +84,3 @@ } | ||
constructor(data: any); | ||
get(tag: LanguageTag): Bundle; | ||
get(tag: LanguageTag): ResourceBundle; | ||
} |
@@ -13,2 +13,21 @@ "use strict"; | ||
this.index = index; | ||
// Properties for fast internal lookups into maps. | ||
// For example, extended day periods cover all of 'es' except for 'es-CO'. | ||
// Pre-computing these to avoid string creation for lookups at runtime. | ||
this._calendarSystem = 'gregory'; | ||
this._numberSystem = 'default'; | ||
var language = tag.language(); | ||
this._languageRegion = language + "-" + tag.region(); | ||
this._languageScript = language + "-" + tag.script(); | ||
// When bundle is constructed, see if there are unicode extensions for | ||
// number and calendar systems. | ||
for (var _i = 0, _a = tag.extensionSubtags('u'); _i < _a.length; _i++) { | ||
var subtag = _a[_i]; | ||
if (subtag.startsWith('nu-')) { | ||
this._numberSystem = subtag.substring(3); | ||
} | ||
else if (subtag.startsWith('co-')) { | ||
this._calendarSystem = subtag.substring(3); | ||
} | ||
} | ||
} | ||
@@ -24,2 +43,14 @@ StringBundle.prototype.bundleId = function () { | ||
}; | ||
StringBundle.prototype.languageScript = function () { | ||
return this._languageScript; | ||
}; | ||
StringBundle.prototype.languageRegion = function () { | ||
return this._languageRegion; | ||
}; | ||
StringBundle.prototype.calendarSystem = function () { | ||
return this._calendarSystem; | ||
}; | ||
StringBundle.prototype.numberSystem = function () { | ||
return this._numberSystem; | ||
}; | ||
StringBundle.prototype.get = function (offset) { | ||
@@ -57,2 +88,14 @@ // If there is an exception index, attempt to resolve it. | ||
}; | ||
DummyBundle.prototype.languageScript = function () { | ||
return 'und-Zzzz'; | ||
}; | ||
DummyBundle.prototype.languageRegion = function () { | ||
return 'und-ZZ'; | ||
}; | ||
DummyBundle.prototype.calendarSystem = function () { | ||
return 'gregory'; | ||
}; | ||
DummyBundle.prototype.numberSystem = function () { | ||
return 'default'; | ||
}; | ||
DummyBundle.prototype.get = function (offset) { | ||
@@ -59,0 +102,0 @@ return ''; |
export * from './datetime'; | ||
export * from './enum'; | ||
export * from './numbers'; | ||
export * from './parts'; |
@@ -7,4 +7,3 @@ "use strict"; | ||
__export(require("./datetime")); | ||
__export(require("./enum")); | ||
__export(require("./numbers")); | ||
//# sourceMappingURL=index.js.map |
@@ -33,2 +33,6 @@ import { NumberOperands } from './operands'; | ||
/** | ||
* Return the absolute value of the number. | ||
*/ | ||
abs(): Decimal; | ||
/** | ||
* Invert this number's sign. | ||
@@ -50,14 +54,31 @@ */ | ||
isInteger(): boolean; | ||
/** | ||
* Return the integer part. | ||
*/ | ||
toInteger(): Decimal; | ||
/** | ||
* Adds v. | ||
*/ | ||
add(v: DecimalArg): Decimal; | ||
/** | ||
* Subtracts v. | ||
*/ | ||
subtract(v: DecimalArg): Decimal; | ||
/** | ||
* Multiplies by v with optional math context. | ||
*/ | ||
multiply(v: DecimalArg, context?: MathContext): Decimal; | ||
/** | ||
* Divide this number by v and return the quotient. | ||
* Divide by v with optional math context. | ||
*/ | ||
divide(v: DecimalArg, context?: MathContext): Decimal; | ||
/** | ||
* Divide this number by v and return the quotient and remainder. | ||
* Divide by v and return the quotient and remainder. | ||
*/ | ||
divmod(v: DecimalArg): [Decimal, Decimal]; | ||
/** | ||
* Divide by v and return the remainder. | ||
*/ | ||
mod(v: DecimalArg): Decimal; | ||
/** | ||
* Number of trailing zeros. | ||
@@ -64,0 +85,0 @@ */ |
@@ -92,3 +92,4 @@ "use strict"; | ||
if (shift > 0) { | ||
return -1 * operations_1.compare(u.data, v.data, shift); | ||
var c = operations_1.compare(v.data, u.data, shift); | ||
return c === 0 ? c : -c; | ||
} | ||
@@ -117,6 +118,12 @@ return operations_1.compare(u.data, v.data, -shift); | ||
/** | ||
* Return the absolute value of the number. | ||
*/ | ||
Decimal.prototype.abs = function () { | ||
return this.sign === -1 ? Decimal.fromRaw(-this.sign, this.exp, this.data) : this; | ||
}; | ||
/** | ||
* Invert this number's sign. | ||
*/ | ||
Decimal.prototype.negate = function () { | ||
return this.sign === 0 ? new Decimal(this) : Decimal.fromRaw(-this.sign, this.exp, this.data); | ||
return this.sign === 0 ? this : Decimal.fromRaw(-this.sign, this.exp, this.data); | ||
}; | ||
@@ -142,2 +149,11 @@ /** | ||
}; | ||
/** | ||
* Return the integer part. | ||
*/ | ||
Decimal.prototype.toInteger = function () { | ||
return this.setScale(0, "truncate" /* TRUNCATE */); | ||
}; | ||
/** | ||
* Adds v. | ||
*/ | ||
Decimal.prototype.add = function (v) { | ||
@@ -147,2 +163,5 @@ v = exports.coerceDecimal(v); | ||
}; | ||
/** | ||
* Subtracts v. | ||
*/ | ||
Decimal.prototype.subtract = function (v) { | ||
@@ -152,2 +171,5 @@ v = exports.coerceDecimal(v); | ||
}; | ||
/** | ||
* Multiplies by v with optional math context. | ||
*/ | ||
Decimal.prototype.multiply = function (v, context) { | ||
@@ -178,3 +200,3 @@ var _a = parseMathContext('half-even', context), usePrecision = _a[0], scaleprec = _a[1], rounding = _a[2]; | ||
/** | ||
* Divide this number by v and return the quotient. | ||
* Divide by v with optional math context. | ||
*/ | ||
@@ -229,3 +251,3 @@ Decimal.prototype.divide = function (v, context) { | ||
/** | ||
* Divide this number by v and return the quotient and remainder. | ||
* Divide by v and return the quotient and remainder. | ||
*/ | ||
@@ -259,2 +281,9 @@ Decimal.prototype.divmod = function (v) { | ||
/** | ||
* Divide by v and return the remainder. | ||
*/ | ||
Decimal.prototype.mod = function (v) { | ||
var _a = this.divmod(v), q = _a[0], r = _a[1]; | ||
return r; | ||
}; | ||
/** | ||
* Number of trailing zeros. | ||
@@ -261,0 +290,0 @@ */ |
@@ -32,2 +32,5 @@ /** | ||
export declare const trimLeadingZeros: (data: number[]) => void; | ||
/** | ||
* Reusable quotient and remainder for repeated divmod operations. | ||
*/ | ||
export declare class DivMod { | ||
@@ -40,3 +43,2 @@ private s; | ||
word(n: number, w: number): number[]; | ||
size(n: number): number; | ||
} | ||
@@ -43,0 +45,0 @@ /** |
@@ -255,2 +255,5 @@ "use strict"; | ||
}; | ||
/** | ||
* Reusable quotient and remainder for repeated divmod operations. | ||
*/ | ||
var DivMod = /** @class */ (function () { | ||
@@ -270,6 +273,2 @@ function DivMod() { | ||
}; | ||
DivMod.prototype.size = function (n) { | ||
var _a = exports.divword(this.s, n, 7 /* RDIGITS */), q = _a[0], r = _a[1]; | ||
return r === 0 ? q : q + 1; | ||
}; | ||
return DivMod; | ||
@@ -276,0 +275,0 @@ }()); |
@@ -20,3 +20,3 @@ "use strict"; | ||
} | ||
else if (n instanceof Rational || n.numerator !== undefined) { | ||
else if (n instanceof Rational) { | ||
return n; | ||
@@ -62,5 +62,6 @@ } | ||
Rational.prototype.compare = function (num, context) { | ||
var n = coerceRational(num); | ||
var a = this.numer.multiply(n.denom, context); | ||
var b = n.numer.multiply(this.denom, context); | ||
var u = this; | ||
var v = coerceRational(num); | ||
var a = u.numer.multiply(v.denom, context); | ||
var b = v.numer.multiply(u.denom, context); | ||
return a.compare(b); | ||
@@ -67,0 +68,0 @@ }; |
{ | ||
"name": "@phensley/cldr-core", | ||
"version": "0.2.11", | ||
"version": "0.2.12", | ||
"description": "Core library for @phensley/cldr", | ||
@@ -30,3 +30,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@phensley/cldr-schema": "^0.2.11" | ||
"@phensley/cldr-schema": "^0.2.12" | ||
}, | ||
@@ -33,0 +33,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
762419
9054
236