update, text, response
This commit is contained in:
107
node_modules/fast-xml-parser/src/v5/valueParsers/EntitiesParser.js
generated
vendored
Normal file
107
node_modules/fast-xml-parser/src/v5/valueParsers/EntitiesParser.js
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
const ampEntity = { regex: /&(amp|#38|#x26);/g, val : "&"};
|
||||
const htmlEntities = {
|
||||
"space": { regex: /&(nbsp|#160);/g, val: " " },
|
||||
// "lt" : { regex: /&(lt|#60);/g, val: "<" },
|
||||
// "gt" : { regex: /&(gt|#62);/g, val: ">" },
|
||||
// "amp" : { regex: /&(amp|#38);/g, val: "&" },
|
||||
// "quot" : { regex: /&(quot|#34);/g, val: "\"" },
|
||||
// "apos" : { regex: /&(apos|#39);/g, val: "'" },
|
||||
"cent" : { regex: /&(cent|#162);/g, val: "¢" },
|
||||
"pound" : { regex: /&(pound|#163);/g, val: "£" },
|
||||
"yen" : { regex: /&(yen|#165);/g, val: "¥" },
|
||||
"euro" : { regex: /&(euro|#8364);/g, val: "€" },
|
||||
"copyright" : { regex: /&(copy|#169);/g, val: "©" },
|
||||
"reg" : { regex: /&(reg|#174);/g, val: "®" },
|
||||
"inr" : { regex: /&(inr|#8377);/g, val: "₹" },
|
||||
"num_dec": { regex: /&#([0-9]{1,7});/g, val : (_, str) => String.fromCharCode(Number.parseInt(str, 10)) },
|
||||
"num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val : (_, str) => String.fromCharCode(Number.parseInt(str, 16)) },
|
||||
};
|
||||
|
||||
class EntitiesParser{
|
||||
constructor(replaceHtmlEntities) {
|
||||
this.replaceHtmlEntities = replaceHtmlEntities;
|
||||
this.docTypeEntities = {};
|
||||
this.lastEntities = {
|
||||
"apos" : { regex: /&(apos|#39|#x27);/g, val : "'"},
|
||||
"gt" : { regex: /&(gt|#62|#x3E);/g, val : ">"},
|
||||
"lt" : { regex: /&(lt|#60|#x3C);/g, val : "<"},
|
||||
"quot" : { regex: /&(quot|#34|#x22);/g, val : "\""},
|
||||
};
|
||||
}
|
||||
|
||||
addExternalEntities(externalEntities){
|
||||
const entKeys = Object.keys(externalEntities);
|
||||
for (let i = 0; i < entKeys.length; i++) {
|
||||
const ent = entKeys[i];
|
||||
this.addExternalEntity(ent,externalEntities[ent])
|
||||
}
|
||||
}
|
||||
addExternalEntity(key,val){
|
||||
validateEntityName(key);
|
||||
if(val.indexOf("&") !== -1) {
|
||||
reportWarning(`Entity ${key} is not added as '&' is found in value;`)
|
||||
return;
|
||||
}else{
|
||||
this.lastEntities[ent] = {
|
||||
regex: new RegExp("&"+key+";","g"),
|
||||
val : val
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addDocTypeEntities(entities){
|
||||
const entKeys = Object.keys(entities);
|
||||
for (let i = 0; i < entKeys.length; i++) {
|
||||
const ent = entKeys[i];
|
||||
this.docTypeEntities[ent] = {
|
||||
regex: new RegExp("&"+ent+";","g"),
|
||||
val : entities[ent]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parse(val){
|
||||
return this.replaceEntitiesValue(val)
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Replace DOCTYPE entities
|
||||
* 2. Replace external entities
|
||||
* 3. Replace HTML entities if asked
|
||||
* @param {string} val
|
||||
*/
|
||||
replaceEntitiesValue(val){
|
||||
if(typeof val === "string" && val.length > 0){
|
||||
for(let entityName in this.docTypeEntities){
|
||||
const entity = this.docTypeEntities[entityName];
|
||||
val = val.replace( entity.regx, entity.val);
|
||||
}
|
||||
for(let entityName in this.lastEntities){
|
||||
const entity = this.lastEntities[entityName];
|
||||
val = val.replace( entity.regex, entity.val);
|
||||
}
|
||||
if(this.replaceHtmlEntities){
|
||||
for(let entityName in htmlEntities){
|
||||
const entity = htmlEntities[entityName];
|
||||
val = val.replace( entity.regex, entity.val);
|
||||
}
|
||||
}
|
||||
val = val.replace( ampEntity.regex, ampEntity.val);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
//an entity name should not contains special characters that may be used in regex
|
||||
//Eg !?\\\/[]$%{}^&*()<>
|
||||
const specialChar = "!?\\\/[]$%{}^&*()<>|+";
|
||||
|
||||
function validateEntityName(name){
|
||||
for (let i = 0; i < specialChar.length; i++) {
|
||||
const ch = specialChar[i];
|
||||
if(name.indexOf(ch) !== -1) throw new Error(`Invalid character ${ch} in entity name`);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
module.exports = EntitiesParser;
|
||||
23
node_modules/fast-xml-parser/src/v5/valueParsers/booleanParser.js
generated
vendored
Normal file
23
node_modules/fast-xml-parser/src/v5/valueParsers/booleanParser.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
class boolParser{
|
||||
constructor(trueList, falseList){
|
||||
if(trueList)
|
||||
this.trueList = trueList;
|
||||
else
|
||||
this.trueList = ["true"];
|
||||
|
||||
if(falseList)
|
||||
this.falseList = falseList;
|
||||
else
|
||||
this.falseList = ["false"];
|
||||
}
|
||||
parse(val){
|
||||
if (typeof val === 'string') {
|
||||
//TODO: performance: don't convert
|
||||
const temp = val.toLowerCase();
|
||||
if(this.trueList.indexOf(temp) !== -1) return true;
|
||||
else if(this.falseList.indexOf(temp) !== -1 ) return false;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
module.exports = boolParser;
|
||||
20
node_modules/fast-xml-parser/src/v5/valueParsers/booleanParserExt.js
generated
vendored
Normal file
20
node_modules/fast-xml-parser/src/v5/valueParsers/booleanParserExt.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
function boolParserExt(val){
|
||||
if(isArray(val)){
|
||||
for (let i = 0; i < val.length; i++) {
|
||||
val[i] = parse(val[i])
|
||||
}
|
||||
}else{
|
||||
val = parse(val)
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
function parse(val){
|
||||
if (typeof val === 'string') {
|
||||
const temp = val.toLowerCase();
|
||||
if(temp === 'true' || temp ==="yes" || temp==="1") return true;
|
||||
else if(temp === 'false' || temp ==="no" || temp==="0") return false;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
module.exports = boolParserExt;
|
||||
40
node_modules/fast-xml-parser/src/v5/valueParsers/currency.js
generated
vendored
Normal file
40
node_modules/fast-xml-parser/src/v5/valueParsers/currency.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
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 || defaultOptions;
|
||||
}
|
||||
parse(val){
|
||||
if (typeof val === 'string' && val.length <= this.options.maxLength) {
|
||||
if(val.indexOf(",,") !== -1 && val.indexOf(".." !== -1)){
|
||||
const match = val.match(currencyCheckRegex);
|
||||
if(match){
|
||||
const locale = this.options.locale || localeMap[match[2]||match[5]||"₹"];
|
||||
const formatter = new Intl.NumberFormat(locale)
|
||||
val = val.replace(/[^0-9,.]/g, '').trim();
|
||||
val = Number(val.replace(formatter.format(1000)[1], ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
CurrencyParser.defaultOptions = defaultOptions;
|
||||
|
||||
module.exports = CurrencyParser;
|
||||
14
node_modules/fast-xml-parser/src/v5/valueParsers/join.js
generated
vendored
Normal file
14
node_modules/fast-xml-parser/src/v5/valueParsers/join.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
*
|
||||
* @param {array} val
|
||||
* @param {string} by
|
||||
* @returns
|
||||
*/
|
||||
function join(val, by=" "){
|
||||
if(isArray(val)){
|
||||
val.join(by)
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
module.exports = join;
|
||||
16
node_modules/fast-xml-parser/src/v5/valueParsers/number.js
generated
vendored
Normal file
16
node_modules/fast-xml-parser/src/v5/valueParsers/number.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
const toNumber = require("strnum");
|
||||
|
||||
|
||||
class numParser{
|
||||
constructor(options){
|
||||
this.options = options;
|
||||
}
|
||||
parse(val){
|
||||
if (typeof val === 'string') {
|
||||
val = toNumber(val,this.options);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = numParser;
|
||||
8
node_modules/fast-xml-parser/src/v5/valueParsers/trim.js
generated
vendored
Normal file
8
node_modules/fast-xml-parser/src/v5/valueParsers/trim.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
class trimmer{
|
||||
parse(val){
|
||||
if(typeof val === "string") return val.trim();
|
||||
else return val;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = trimmer;
|
||||
Reference in New Issue
Block a user