Skip to content

Commit d0bfe8a

Browse files
committed
fix maxlength for currency value
1 parent 2c14fcf commit d0bfe8a

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

src/v5/OutputBuilders/JsArrBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const {buildOptions,registerCommonValueParsers} = require("./ParserOptionsBuilde
33
class OutputBuilder{
44
constructor(options){
55
this.options = buildOptions(options);
6-
this.registeredParsers = registerCommonValueParsers();
6+
this.registeredParsers = registerCommonValueParsers(this.options);
77
}
88

99
registerValueParser(name,parserInstance){//existing name will override the parser without warning

src/v5/OutputBuilders/JsMinArrBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const {buildOptions,registerCommonValueParsers} = require("./ParserOptionsBuilde
33
class OutputBuilder{
44
constructor(options){
55
this.options = buildOptions(options);
6-
this.registeredParsers = registerCommonValueParsers();
6+
this.registeredParsers = registerCommonValueParsers(this.options);
77
}
88

99
registerValueParser(name,parserInstance){//existing name will override the parser without warning

src/v5/OutputBuilders/JsObjBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const {buildOptions,registerCommonValueParsers} = require("./ParserOptionsBuilde
55
class OutputBuilder{
66
constructor(builderOptions){
77
this.options = buildOptions(builderOptions);
8-
this.registeredParsers = registerCommonValueParsers();
8+
this.registeredParsers = registerCommonValueParsers(this.options);
99
}
1010

1111
registerValueParser(name,parserInstance){//existing name will override the parser without warning

src/v5/OutputBuilders/ParserOptionsBuilder.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const defaultOptions={
3434
// "currency",
3535
// "date",
3636
]
37+
},
38+
dataType:{
39+
3740
}
3841
}
3942

@@ -75,7 +78,7 @@ function copyProperties(target, source) {
7578
}
7679
}
7780

78-
function registerCommonValueParsers(){
81+
function registerCommonValueParsers(options){
7982
return {
8083
"trim": new trimParser(),
8184
// "join": this.entityParser.parse,

src/v5/valueParsers/currency.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
1+
const defaultOptions = {
2+
maxLength: 200,
3+
// locale: "en-IN"
4+
}
25
const localeMap = {
36
"$":"en-US",
47
"€":"de-DE",
58
"£":"en-GB",
69
"¥":"ja-JP",
710
"₹":"en-IN",
811
}
12+
const sign = "(?:-|\+)?";
13+
const digitsAndSeparator = "(?:\d+|\d{1,3}(?:,\d{3})+)";
14+
const decimalPart = "(?:\.\d{1,2})?";
15+
const symbol = "(?:\$|€|¥|₹)?";
916

1017
const currencyCheckRegex = /^\s*(?:-|\+)?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d{1,2})?\s*(?:\$||¥|)?\s*$/u;
1118

1219
class CurrencyParser{
1320
constructor(options){
14-
this.options = options;
21+
this.options = options || defaultOptions;
1522
}
1623
parse(val){
17-
if (typeof val === 'string') {
24+
if (typeof val === 'string' && val.length <= this.options.maxLength) {
1825
if(val.indexOf(",,") !== -1 && val.indexOf(".." !== -1)){
1926
const match = val.match(currencyCheckRegex);
2027
if(match){
@@ -28,4 +35,6 @@ class CurrencyParser{
2835
return val;
2936
}
3037
}
38+
CurrencyParser.defaultOptions = defaultOptions;
39+
3140
module.exports = CurrencyParser;

0 commit comments

Comments
 (0)