Skip to content

Instantly share code, notes, and snippets.

@shifatul-i
Created October 8, 2018 23:39
Show Gist options
  • Select an option

  • Save shifatul-i/f9bd9a7603c96be35e2a2ab3bf139052 to your computer and use it in GitHub Desktop.

Select an option

Save shifatul-i/f9bd9a7603c96be35e2a2ab3bf139052 to your computer and use it in GitHub Desktop.
Angular - short URL pipe (Long URL to short URL - https://github.com…roid)
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'shortUrl'
})
export class ShortUrlPipe implements PipeTransform {
transform(url: string, args?: any): any {
if (url) {
const len = url.length;
if (len > 30) // only shorten if greater than 30
// change value 21 and 9 as per requirement
return url.substr(0, 21) + '...' + url.substring(len - 9, len);
return url;
}
return url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment