smartstring/ts/smartstring.normalize.ts

23 lines
664 B
TypeScript
Raw Normal View History

import * as plugins from './smartstring.plugins';
2017-10-05 13:55:59 +00:00
/**
* replaces all occurences of something in a string
* @param stringArg
* @param searchRegExp
* @param replacementString
2017-10-05 13:55:59 +00:00
*/
2017-10-26 13:24:10 +00:00
export const replaceAll = (stringArg: string, searchRegExp: any, replacementString: string) => {
return stringArg.replace(new RegExp(searchRegExp, 'g'), replacementString);
};
2017-10-05 13:55:59 +00:00
/**
* normalizes a string
* @param stringArg
*/
2017-10-26 13:24:10 +00:00
export const standard = (stringArg: string): string => {
let fix1 = plugins.stripIndent(stringArg); // fix indention
let fix2 = plugins.normalizeNewline(fix1); // fix newlines
let fix3 = replaceAll(fix2, /\t/, ' '); // fix tabs
return fix3;
};