diff options
Diffstat (limited to 'public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes')
4 files changed, 53 insertions, 0 deletions
diff --git a/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/format-comma.pipe.spec.ts b/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/format-comma.pipe.spec.ts new file mode 100644 index 0000000..e8f923d --- /dev/null +++ b/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/format-comma.pipe.spec.ts @@ -0,0 +1,8 @@ +import { FormatCommaPipe } from './format-comma.pipe'; + +describe('FormatCommaPipe', () => { + it('create an instance', () => { + const pipe = new FormatCommaPipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/format-comma.pipe.ts b/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/format-comma.pipe.ts new file mode 100644 index 0000000..761ae16 --- /dev/null +++ b/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/format-comma.pipe.ts @@ -0,0 +1,18 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +/* + * Add a space after a comma. + * Usage: + * text | formatComma + * Example: + * {{ foo,bar,baz | formatComma }} + * formats to: foo, bar, baz + */ +@Pipe({ + name: 'formatComma', +}) +export class FormatCommaPipe implements PipeTransform { + transform(text: string): string { + return text.replace(/,/g, ', '); + } +} diff --git a/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/slugify.pipe.spec.ts b/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/slugify.pipe.spec.ts new file mode 100644 index 0000000..2048bc8 --- /dev/null +++ b/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/slugify.pipe.spec.ts @@ -0,0 +1,8 @@ +import { SlugifyPipe } from './slugify.pipe'; + +describe('SlugifyPipe', () => { + it('create an instance', () => { + const pipe = new SlugifyPipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/slugify.pipe.ts b/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/slugify.pipe.ts new file mode 100644 index 0000000..1f44a03 --- /dev/null +++ b/public/projects/angular-small-apps/apps/recipes/src/app/shared/pipes/slugify.pipe.ts @@ -0,0 +1,19 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'slugify', +}) +export class SlugifyPipe implements PipeTransform { + transform(text: string): string { + return text + .toString() + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') + .toLowerCase() + .trim() + .replace(/\s+/g, '-') + .replace(/[^\w-]+/g, '-') + .replace(/--+/g, '-') + .replace(/^-|-$/g, ''); + } +} |
