@bodar/totallylazy
Advanced tools
Comparing version 0.402.244 to 0.403.245
import { MonthFormat, Options, WeekdayFormat } from "./core"; | ||
import { Datum, NumericLookup } from "../parsing"; | ||
import { Datum, DatumLookup, NumericLookup } from "../parsing"; | ||
import DateTimeFormatPartTypes = Intl.DateTimeFormatPartTypes; | ||
@@ -7,2 +7,5 @@ import DateTimeFormatPart = Intl.DateTimeFormatPart; | ||
export declare class Months extends NumericLookup { | ||
private readonly numerals; | ||
constructor(data: Datum<number>[], locale: string); | ||
parse(value: string): number; | ||
static formats: Options[]; | ||
@@ -20,3 +23,3 @@ static cache: { | ||
export declare type Weekday = Datum<number>; | ||
export declare class Weekdays extends NumericLookup { | ||
export declare class Weekdays extends DatumLookup<number> { | ||
static formats: Options[]; | ||
@@ -23,0 +26,0 @@ static cache: { |
@@ -9,7 +9,15 @@ "use strict"; | ||
var parsing_1 = require("../parsing"); | ||
var functions_1 = require("../functions"); | ||
var Months = /** @class */ (function (_super) { | ||
tslib_1.__extends(Months, _super); | ||
function Months() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
function Months(data, locale) { | ||
var _this = _super.call(this, data) || this; | ||
_this.numerals = parsing_1.Numerals.get(locale); | ||
return _this; | ||
} | ||
Months.prototype.parse = function (value) { | ||
var _this = this; | ||
var number = functions_1.get(function () { return _this.numerals.parse(value); }); | ||
return isNaN(number) ? _super.prototype.parse.call(this, value) : number; | ||
}; | ||
Months.get = function (locale, additionalData) { | ||
@@ -24,3 +32,3 @@ if (additionalData === void 0) { additionalData = []; } | ||
if (additionalData === void 0) { additionalData = []; } | ||
return new Months(tslib_1.__spread(Months.generateData(locale), additionalData)); | ||
return new Months(tslib_1.__spread(Months.generateData(locale), additionalData), locale); | ||
}; | ||
@@ -97,3 +105,3 @@ Months.generateData = function (locale) { | ||
return Weekdays; | ||
}(parsing_1.NumericLookup)); | ||
}(parsing_1.DatumLookup)); | ||
exports.Weekdays = Weekdays; | ||
@@ -100,0 +108,0 @@ var weekdays_cache = {}; |
@@ -150,3 +150,3 @@ "use strict"; | ||
get: function () { | ||
return new index_1.Months(index_1.Months.dataFor(this.locale, this.options, false)); | ||
return index_1.Months.create(this.locale, index_1.Months.dataFor(this.locale, this.options, false)); | ||
}, | ||
@@ -153,0 +153,0 @@ enumerable: true, |
{ | ||
"name": "@bodar/totallylazy", | ||
"version": "0.402.244", | ||
"version": "0.403.245", | ||
"description": "Totallylazy", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:bodar/totallylazy.js.git", |
@@ -75,3 +75,3 @@ import { NamedMatch, NamedRegExp } from "./characters"; | ||
export declare type Numeral = Datum<number>; | ||
export declare class Numerals extends NumericLookup { | ||
export declare class Numerals extends DatumLookup<number> { | ||
static cache: { | ||
@@ -83,2 +83,3 @@ [key: string]: Numerals; | ||
static generateData(locale: string): Numeral[]; | ||
parse(value: string): number; | ||
} | ||
@@ -109,1 +110,2 @@ export declare function digits(locale: string): string; | ||
export declare function numberParser(decimalSeparator: AllowedDecimalSeparators, locale?: string): NumberParser; | ||
export declare function numberOf(value: string): number; |
@@ -266,3 +266,3 @@ "use strict"; | ||
NumericLookup.prototype.parse = function (value) { | ||
var number = parseInt(value); | ||
var number = numberOf(value); | ||
return !isNaN(number) ? number : _super.prototype.parse.call(this, value); | ||
@@ -293,5 +293,9 @@ }; | ||
}; | ||
Numerals.prototype.parse = function (value) { | ||
var number = numberOf(value); | ||
return !isNaN(number) ? number : _super.prototype.parse.call(this, value); | ||
}; | ||
Numerals.cache = {}; | ||
return Numerals; | ||
}(NumericLookup)); | ||
}(DatumLookup)); | ||
exports.Numerals = Numerals; | ||
@@ -383,3 +387,3 @@ function digits(locale) { | ||
var text = this.convert(value); | ||
var result = Number(text); | ||
var result = numberOf(text); | ||
if (isNaN(result)) { | ||
@@ -398,1 +402,7 @@ throw new Error("Unable to parse '" + value + "'"); | ||
exports.numberParser = numberParser; | ||
function numberOf(value) { | ||
if (!value || value.trim().length === 0) | ||
return NaN; | ||
return Number(value); | ||
} | ||
exports.numberOf = numberOf; |
310468
7901