Helpers.ts (967B)
1 import { EMPTY_STRING } from "./constants"; 2 3 /** 4 * String preparation function. In a future here will be realization of algorithm from RFC4518 5 * @param inputString JavaScript string. As soon as for each ASN.1 string type we have a specific 6 * transformation function here we will work with pure JavaScript string 7 * @returns Formatted string 8 */ 9 export function stringPrep(inputString: string): string { 10 //#region Initial variables 11 let isSpace = false; 12 let cutResult = EMPTY_STRING; 13 //#endregion 14 15 const result = inputString.trim(); // Trim input string 16 17 //#region Change all sequence of SPACE down to SPACE char 18 for (let i = 0; i < result.length; i++) { 19 if (result.charCodeAt(i) === 32) { 20 if (isSpace === false) 21 isSpace = true; 22 } else { 23 if (isSpace) { 24 cutResult += " "; 25 isSpace = false; 26 } 27 28 cutResult += result[i]; 29 } 30 } 31 //#endregion 32 33 return cutResult.toLowerCase(); 34 }