import { Pipe, PipeTransform } from '@angular/core'; /** * Pipe - transformUrl * * Transforms url until hybris starts sending the new url's. At that point this pipe will not be used anymore * Current url: '/en/home/p.dewalt-dcd796d2-20v-max-xr-li-ion-cordless-brushless-compact-hammer-drill-kit.1000755818.html' * Transformed url: '../../p.dewalt-dcd796d2-20v-max-xr-li-ion-cordless-brushless-compact-hammer-drill-kit/1000755818' * * In the future hybris will send: /product/p.dewalt-dcd796d2-20v-max-xr-li-ion-cordless-brushless-compact-hammer-drill-kit/1000755818 */ @Pipe({ name: 'transformUrl' }) export class TransformUrlPipe implements PipeTransform { transform(url: string, hidePrefix?: boolean): string { return hidePrefix ? url.replace(/.html+$/g, '') .replace(/\/.*\//, '') .replace(/\.(?=[^.]*$)/, '/') : '../../' + url.replace(/.html+$/g, '') .replace(/\/.*\//, '') .replace(/\.(?=[^.]*$)/, '/'); } }