Skip to content

Commit

Permalink
fix maxlength for currency value
Browse files Browse the repository at this point in the history
  • Loading branch information
amitguptagwl committed Jul 28, 2024
1 parent 2c14fcf commit d0bfe8a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/v5/OutputBuilders/JsArrBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

This comment has been minimized.

Copy link
@aaleksu

aaleksu Sep 4, 2024

is this line using wrong indentation?

This comment has been minimized.

Copy link
@amitguptagwl

amitguptagwl Sep 5, 2024

Author Member

probably the above one

}

registerValueParser(name,parserInstance){//existing name will override the parser without warning
Expand Down
2 changes: 1 addition & 1 deletion src/v5/OutputBuilders/JsMinArrBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/v5/OutputBuilders/JsObjBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/v5/OutputBuilders/ParserOptionsBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const defaultOptions={
// "currency",
// "date",
]
},
dataType:{

}
}

Expand Down Expand Up @@ -75,7 +78,7 @@ function copyProperties(target, source) {
}
}

function registerCommonValueParsers(){
function registerCommonValueParsers(options){
return {
"trim": new trimParser(),
// "join": this.entityParser.parse,
Expand Down
15 changes: 12 additions & 3 deletions src/v5/valueParsers/currency.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@

const defaultOptions = {
maxLength: 200,
// locale: "en-IN"
}
const localeMap = {
"$":"en-US",
"€":"de-DE",
"£":"en-GB",
"¥":"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){
Expand All @@ -28,4 +35,6 @@ class CurrencyParser{
return val;
}
}
CurrencyParser.defaultOptions = defaultOptions;

module.exports = CurrencyParser;

0 comments on commit d0bfe8a

Please sign in to comment.