diff --git a/src/v5/OutputBuilders/JsArrBuilder.js b/src/v5/OutputBuilders/JsArrBuilder.js index 05ad1e11..c63f6274 100644 --- a/src/v5/OutputBuilders/JsArrBuilder.js +++ b/src/v5/OutputBuilders/JsArrBuilder.js @@ -3,7 +3,7 @@ const {buildOptions,registerCommonValueParsers} = require("./ParserOptionsBuilde class OutputBuilder{ constructor(options){ this.options = buildOptions(options); - this.registeredParsers = registerCommonValueParsers(); + this.registeredParsers = registerCommonValueParsers(this.options); } registerValueParser(name,parserInstance){//existing name will override the parser without warning diff --git a/src/v5/OutputBuilders/JsMinArrBuilder.js b/src/v5/OutputBuilders/JsMinArrBuilder.js index 84281cb1..e0dc1e94 100644 --- a/src/v5/OutputBuilders/JsMinArrBuilder.js +++ b/src/v5/OutputBuilders/JsMinArrBuilder.js @@ -3,7 +3,7 @@ const {buildOptions,registerCommonValueParsers} = require("./ParserOptionsBuilde class OutputBuilder{ constructor(options){ this.options = buildOptions(options); - this.registeredParsers = registerCommonValueParsers(); + this.registeredParsers = registerCommonValueParsers(this.options); } registerValueParser(name,parserInstance){//existing name will override the parser without warning diff --git a/src/v5/OutputBuilders/JsObjBuilder.js b/src/v5/OutputBuilders/JsObjBuilder.js index 261b0fc2..37036c52 100644 --- a/src/v5/OutputBuilders/JsObjBuilder.js +++ b/src/v5/OutputBuilders/JsObjBuilder.js @@ -5,7 +5,7 @@ const {buildOptions,registerCommonValueParsers} = require("./ParserOptionsBuilde class OutputBuilder{ constructor(builderOptions){ this.options = buildOptions(builderOptions); - this.registeredParsers = registerCommonValueParsers(); + this.registeredParsers = registerCommonValueParsers(this.options); } registerValueParser(name,parserInstance){//existing name will override the parser without warning diff --git a/src/v5/OutputBuilders/ParserOptionsBuilder.js b/src/v5/OutputBuilders/ParserOptionsBuilder.js index 0776fdf4..c71ea94a 100644 --- a/src/v5/OutputBuilders/ParserOptionsBuilder.js +++ b/src/v5/OutputBuilders/ParserOptionsBuilder.js @@ -34,6 +34,9 @@ const defaultOptions={ // "currency", // "date", ] + }, + dataType:{ + } } @@ -75,7 +78,7 @@ function copyProperties(target, source) { } } -function registerCommonValueParsers(){ +function registerCommonValueParsers(options){ return { "trim": new trimParser(), // "join": this.entityParser.parse, diff --git a/src/v5/valueParsers/currency.js b/src/v5/valueParsers/currency.js index 5ec00006..82e21e75 100644 --- a/src/v5/valueParsers/currency.js +++ b/src/v5/valueParsers/currency.js @@ -1,4 +1,7 @@ - +const defaultOptions = { + maxLength: 200, + // locale: "en-IN" +} const localeMap = { "$":"en-US", "€":"de-DE", @@ -6,15 +9,19 @@ const localeMap = { "¥":"ja-JP", "₹":"en-IN", } +const sign = "(?:-|\+)?"; +const digitsAndSeparator = "(?:\d+|\d{1,3}(?:,\d{3})+)"; +const decimalPart = "(?:\.\d{1,2})?"; +const symbol = "(?:\$|€|¥|₹)?"; const currencyCheckRegex = /^\s*(?:-|\+)?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d{1,2})?\s*(?:\$|€|¥|₹)?\s*$/u; class CurrencyParser{ constructor(options){ - this.options = options; + this.options = options || defaultOptions; } parse(val){ - if (typeof val === 'string') { + if (typeof val === 'string' && val.length <= this.options.maxLength) { if(val.indexOf(",,") !== -1 && val.indexOf(".." !== -1)){ const match = val.match(currencyCheckRegex); if(match){ @@ -28,4 +35,6 @@ class CurrencyParser{ return val; } } +CurrencyParser.defaultOptions = defaultOptions; + module.exports = CurrencyParser; \ No newline at end of file