Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let fractionUnitsString = '';
for (let i = 0; i < compoundUnit.length; i++) {
let extractResult = compoundUnit[i];
let parseResult = this.numberWithUnitParser.parse(extractResult);
let parseResultValue: UnitValue = parseResult.value;
let unitValue = parseResultValue != null ? parseResultValue.unit : null;
// Process a new group
if (count === 0) {
if (extractResult.type !== Constants.SYS_UNIT_CURRENCY) {
continue;
}
// Initialize a new result
result = new ParseResult(extractResult);
mainUnitValue = unitValue;
if (parseResultValue.number != null) {
numberValue = parseFloat(parseResultValue.number);
}
result.resolutionStr = parseResult.resolutionStr;
if (this.config.currencyNameToIsoCodeMap.has(unitValue)) {
mainUnitIsoCode = this.config.currencyNameToIsoCodeMap.get(unitValue);
}
// If the main unit can't be recognized, finish process this group.
if (StringUtility.isNullOrEmpty(mainUnitIsoCode)) {
result.value = {
number: numberValue.toString(),
unit: mainUnitValue
parse(extResult: ExtractResult): ParseResult {
let ret = new ParseResult(extResult);
let numberResult: ExtractResult;
if (extResult.data && typeof extResult.data === "object") {
numberResult = extResult.data as ExtractResult;
}
else if (extResult.type === Constants.SYS_NUM) {
ret.value = this.config.internalNumberParser.parse(extResult).value;
return ret;
}
else {
// if there is no unitResult, means there is just unit
numberResult = { start: -1, length: 0, text: null, type: null };
}
// key contains units
let key = extResult.text;
let unitKeyBuild = '';
private fracParseCJK(extResult: ExtractResult): ParseResult {
let result = new ParseResult(extResult);
let resultText = extResult.text;
let splitResult = RegExpUtility.split(this.config.fracSplitRegex, resultText);
let intPart = "";
let demoPart = "";
let numPart = "";
if (splitResult.length === 3) {
intPart = splitResult[0] || "";
demoPart = splitResult[1] || "";
numPart = splitResult[2] || "";
}
else {
intPart = this.config.zeroChar;
demoPart = splitResult[0] || "";
numPart = splitResult[1] || "";
}
private douParseCJK(extResult: ExtractResult): ParseResult {
let result = new ParseResult(extResult);
let resultText = extResult.text;
if (RegExpUtility.isMatch(this.config.doubleAndRoundRegex, resultText)) {
resultText = this.replaceUnit(resultText);
let power = this.config.roundNumberMapChar.get(resultText.charAt(resultText.length - 1));
result.value = this.getDigitValueCJK(resultText.substr(0, resultText.length - 1), power);
}
else {
resultText = this.replaceUnit(resultText);
let splitResult = RegExpUtility.split(this.config.pointRegex, resultText);
if (splitResult[0] === "") {
splitResult[0] = this.config.zeroChar;
}
result.data.otherMatches = result.data.otherMatches.map(m => {
let r = new ParseResult(m);
r.value = this.config.resolutions.get(r.type);
return r;
});
}
private intParseCJK(extResult: ExtractResult): ParseResult {
let result = new ParseResult(extResult);
result.value = this.getIntValueCJK(extResult.text);
result.resolutionStr = this.toString(result.value);
return result;
}
parse(extResult: ExtractResult): ParseResult {
let result = new ParseResult(extResult);
result.resolutionStr = extResult.text;
return result;
}
}
private ordParseCJK(extResult: ExtractResult): ParseResult {
let result = new ParseResult(extResult);
let resultText = extResult.text.substr(1);
if (RegExpUtility.isMatch(this.config.digitNumRegex, resultText) && !RegExpUtility.isMatch(this.config.roundNumberIntegerRegex, resultText)) {
result.value = this.getDigitValueCJK(resultText, 1);
}
else {
result.value = this.getIntValueCJK(resultText);
}
result.resolutionStr = this.toString(result.value);
return result;
}
parse(extResult: ExtractResult): ParseResult {
let result = new ParseResult(extResult);
result.resolutionStr = extResult.text;
result.value = this.ScorePhoneNumber(extResult.text);
return result;
}
}