@bodar/totallylazy
Advanced tools
Comparing version 0.400.242 to 0.401.243
@@ -7,4 +7,4 @@ "use strict"; | ||
"symbols": [ | ||
"Afs", | ||
"؋" | ||
"؋", | ||
"Afs" | ||
] | ||
@@ -11,0 +11,0 @@ }, |
@@ -18,6 +18,6 @@ "use strict"; | ||
exports.flexibleParse = flexibleParse; | ||
var allowedSeparators = "\u066C\u066B,.'\u2019" + money_1.Spaces.spaces; | ||
var allowedSeparators = "\u066C\u066B,.'\u2019" + parsing_1.Spaces.spaces; | ||
var numberPattern = cache_1.caching(function (locale) { | ||
var digits = "[\\d" + parsing_1.Numerals.get(locale).characters.join('') + "]+"; | ||
return "(?:" + digits + "[" + allowedSeparators + "])*" + digits; | ||
var d = parsing_1.digits(locale); | ||
return "(?:[" + d + "]+[" + allowedSeparators + "])*[" + d + "]+"; | ||
}); | ||
@@ -48,3 +48,3 @@ function mapIgnoreError(mapper) { | ||
FlexibleMoneyParser.patternFor = function (locale) { | ||
return characters_1.NamedRegExp.create(parsing_1.atBoundaryOnly("(?<currency>" + money_1.CurrencySymbols.get(locale).pattern + ")?(?<literal>[" + money_1.Spaces.spaces + "])?(?<number>" + numberPattern(locale) + ")(?<literal>[" + money_1.Spaces.spaces + "])?(?<currency>" + money_1.CurrencySymbols.get(locale).pattern + ")?")); | ||
return characters_1.NamedRegExp.create(parsing_1.atBoundaryOnly("(?<currency>" + money_1.CurrencySymbols.get(locale).pattern + ")?(?<literal>[" + parsing_1.Spaces.spaces + "])?(?<number>" + numberPattern(locale) + ")(?<literal>[" + parsing_1.Spaces.spaces + "])?(?<currency>" + money_1.CurrencySymbols.get(locale).pattern + ")?")); | ||
}; | ||
@@ -51,0 +51,0 @@ FlexibleMoneyParser.prototype.parse = function (value) { |
@@ -86,8 +86,2 @@ import { NamedMatch } from "../characters"; | ||
export declare function symbolFor(locale: string, isoCurrency: string, hasNative?: boolean): string; | ||
export declare class Spaces { | ||
static codes: string[]; | ||
static spaces: string; | ||
static pattern: RegExp; | ||
static handle(value: string): string; | ||
} | ||
export declare class RegexBuilder { | ||
@@ -105,3 +99,3 @@ static buildFromOptions(locale: string, options?: Options): string; | ||
static create(locale: string, options?: Options): Parser<NumberFormatPart[]>; | ||
static convert(matches: NamedMatch[]): NumberFormatPart[]; | ||
static convert(matches: NamedMatch[], locale: string): NumberFormatPart[]; | ||
} | ||
@@ -120,4 +114,4 @@ export declare class PartsFromFormat { | ||
parse(value: string): NumberFormatPart[]; | ||
static get digits(): IntegerGroupParser; | ||
static digits(locale: string): IntegerGroupParser; | ||
static get integerFormat(): IntegerGroupParser; | ||
} |
@@ -13,2 +13,4 @@ "use strict"; | ||
var cache_1 = require("../cache"); | ||
var flexible_parsing_1 = require("./flexible-parsing"); | ||
var functions_1 = require("../functions"); | ||
function money(currency, amount) { | ||
@@ -29,3 +31,5 @@ return { amount: amount, currency: currency }; | ||
var filtered = parts.filter(function (p) { return p.type === 'integer' || p.type === 'decimal' || p.type === 'fraction'; }); | ||
var value = Number(filtered.map(function (p) { return p.type === 'decimal' ? '.' : p.value; }).join('')); | ||
var decimal = functions_1.get(function () { return parts.filter(function (p) { return p.type === 'decimal'; })[0].value; }, '.'); | ||
var text = filtered.map(function (p) { return p.value; }).join(''); | ||
var value = flexible_parsing_1.numberParser(decimal, locale).parse(text); | ||
return money(currency, value); | ||
@@ -178,18 +182,6 @@ } | ||
return '£'; | ||
return result.replace(Spaces.pattern, ''); | ||
return result.replace(parsing_1.Spaces.pattern, ''); | ||
} | ||
} | ||
exports.symbolFor = symbolFor; | ||
var Spaces = /** @class */ (function () { | ||
function Spaces() { | ||
} | ||
Spaces.handle = function (value) { | ||
return Spaces.codes.indexOf(value) != -1 ? Spaces.spaces : value; | ||
}; | ||
Spaces.codes = [32, 160, 8239].map(function (code) { return String.fromCharCode(code); }); | ||
Spaces.spaces = Spaces.codes.join(''); | ||
Spaces.pattern = new RegExp("[" + Spaces.spaces + "]", 'g'); | ||
return Spaces; | ||
}()); | ||
exports.Spaces = Spaces; | ||
var RegexBuilder = /** @class */ (function () { | ||
@@ -209,2 +201,3 @@ function RegexBuilder() { | ||
var _a = tslib_1.__read(raw.filter(function (p) { return p.type === 'group'; }).map(function (p) { return p.value; }), 1), _b = _a[0], group = _b === void 0 ? '' : _b; | ||
var d = parsing_1.digits(locale); | ||
var pattern = noGroups.map(function (part) { | ||
@@ -217,7 +210,7 @@ switch (part.type) { | ||
case "fraction": | ||
return "(?<fraction>\\d*)"; | ||
return "(?<fraction>[" + d + "]*)"; | ||
case "integer": | ||
return "(?<integer-group>[\\d" + Spaces.handle(group) + "]*\\d+)"; | ||
return "(?<integer-group>[" + d + parsing_1.Spaces.handle(group) + "]*[" + d + "]+)"; | ||
default: | ||
return "(?<" + part.type + ">[" + Spaces.handle(part.value) + "]?)"; | ||
return "(?<" + part.type + ">[" + parsing_1.Spaces.handle(part.value) + "]?)"; | ||
} | ||
@@ -261,9 +254,10 @@ }).join(""); | ||
NumberFormatPartParser.create = function (locale, patternOrOption) { | ||
var _this = this; | ||
var pattern = typeof patternOrOption === "string" ? patternOrOption : RegexBuilder.buildFromOptions(locale, patternOrOption); | ||
return parsing_1.mappingParser(parsing_1.namedRegexParser(characters_1.NamedRegExp.create(pattern)), this.convert); | ||
return parsing_1.mappingParser(parsing_1.namedRegexParser(characters_1.NamedRegExp.create(pattern)), function (m) { return _this.convert(m, locale); }); | ||
}; | ||
NumberFormatPartParser.convert = function (matches) { | ||
NumberFormatPartParser.convert = function (matches, locale) { | ||
return collections_1.array(matches, transducers_1.filter(function (m) { return Boolean(m.value); }), transducers_1.flatMap(function (m) { | ||
if (m.name === 'integer-group') { | ||
return IntegerGroupParser.digits.parse(m.value); | ||
return IntegerGroupParser.digits(locale).parse(m.value); | ||
} | ||
@@ -323,3 +317,3 @@ else { | ||
var regex = characters_1.NamedRegExp.create("(?:(?<integer-group>1.*2)(?:(?<decimal>.)(?<fraction>3+))?|(?<currency>" + CurrencySymbols.get(locale).pattern + "))"); | ||
return new PartsFromFormat(regex, IntegerGroupParser.digits); | ||
return new PartsFromFormat(regex, IntegerGroupParser.digits(locale)); | ||
}; | ||
@@ -349,9 +343,5 @@ tslib_1.__decorate([ | ||
}; | ||
Object.defineProperty(IntegerGroupParser, "digits", { | ||
get: function () { | ||
return new IntegerGroupParser(characters_1.NamedRegExp.create('(?<integer>\\d+)')); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
IntegerGroupParser.digits = function (locale) { | ||
return new IntegerGroupParser(characters_1.NamedRegExp.create("(?<integer>[" + parsing_1.digits(locale) + "]+)")); | ||
}; | ||
Object.defineProperty(IntegerGroupParser, "integerFormat", { | ||
@@ -365,3 +355,3 @@ get: function () { | ||
tslib_1.__decorate([ | ||
lazy_1.lazy | ||
cache_1.cache | ||
], IntegerGroupParser, "digits", null); | ||
@@ -368,0 +358,0 @@ tslib_1.__decorate([ |
{ | ||
"name": "@bodar/totallylazy", | ||
"version": "0.400.242", | ||
"version": "0.401.243", | ||
"description": "Totallylazy", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:bodar/totallylazy.js.git", |
@@ -83,1 +83,8 @@ import { NamedMatch, NamedRegExp } from "./characters"; | ||
} | ||
export declare function digits(locale: string): string; | ||
export declare class Spaces { | ||
static codes: string[]; | ||
static spaces: string; | ||
static pattern: RegExp; | ||
static handle(value: string): string; | ||
} |
@@ -285,3 +285,3 @@ "use strict"; | ||
Numerals.generateData = function (locale) { | ||
var digits = new Intl.NumberFormat(locale).format(1234567890).replace(/[,. '٬٫]/g, ''); | ||
var digits = new Intl.NumberFormat(locale, { useGrouping: false }).format(1234567890).replace(/[,. '٬٫]/g, ''); | ||
return collections_1.array(characters_1.characters(digits), transducers_1.zip([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), transducers_1.map(function (_a) { | ||
@@ -296,1 +296,17 @@ var _b = tslib_1.__read(_a, 2), c = _b[0], d = _b[1]; | ||
exports.Numerals = Numerals; | ||
function digits(locale) { | ||
return "\\d" + Numerals.get(locale).characters.join(''); | ||
} | ||
exports.digits = digits; | ||
var Spaces = /** @class */ (function () { | ||
function Spaces() { | ||
} | ||
Spaces.handle = function (value) { | ||
return Spaces.codes.indexOf(value) != -1 ? Spaces.spaces : value; | ||
}; | ||
Spaces.codes = [32, 160, 8239].map(function (code) { return String.fromCharCode(code); }); | ||
Spaces.spaces = Spaces.codes.join(''); | ||
Spaces.pattern = new RegExp("[" + Spaces.spaces + "]", 'g'); | ||
return Spaces; | ||
}()); | ||
exports.Spaces = Spaces; |
309222
7873