Created
October 8, 2018 23:39
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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