All files / src/app/common/masked-trim masked-trim.ts

100% Statements 9/9
50% Branches 1/2
100% Functions 1/1
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24    1x 29x   29x 2x     29x 2x   29x     1x 1x              
// Ref: http://stackoverflow.com/questions/36390853/how-to-remove-specific-character-surrounding-a-string
 
const trimWithMask = function(mask: string): string {
  let s = this.toString();  // Otherwise, can get a String object instead of a string primitive
  // tslint:disable-next-line:no-bitwise
  while (~mask.indexOf(s[0])) {
    s = s.slice(1);
  }
  // tslint:disable-next-line:no-bitwise
  while (~mask.indexOf(s[s.length - 1])) {
    s = s.slice(0, -1);
  }
  return s;
};
 
Eif (!String.prototype.hasOwnProperty('trimWithMask')) {
  String.prototype.trimWithMask = trimWithMask;
}
 
interface String {
  trimWithMask: typeof trimWithMask;
}
 
// export default trimWithMask