You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { NgModule, Pipe, PipeTransform } from '@angular/core';
|
|
|
|
@Pipe({
|
|
name: 'removeleadingzeros'
|
|
})
|
|
export class RemoveLeadingZerosPipe implements PipeTransform {
|
|
|
|
transform(value: string, args?: any): string {
|
|
return value?.replace(/^[0]+/g, '');
|
|
}
|
|
|
|
}
|
|
|
|
@Pipe({
|
|
name: 'camelcase'
|
|
})
|
|
export class CamelCasePipe implements PipeTransform {
|
|
|
|
transform(value: string, args?: any): string {
|
|
return value?.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => (word.toUpperCase()))?.replace(/\s+/g, '')?.replace(/-/g, ' ');
|
|
}
|
|
|
|
}
|
|
|
|
@Pipe({
|
|
name: 'camelCaseWithSpaces'
|
|
})
|
|
export class CamelCaseWithSpacesPipe implements PipeTransform {
|
|
|
|
transform(value: string, arg1?: string, arg2?: string): string {
|
|
return value.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => (' ' + word.toUpperCase()));
|
|
}
|
|
|
|
}
|
|
|
|
@Pipe({
|
|
name: 'camelcaseWithReplace'
|
|
})
|
|
export class CamelCaseWithReplacePipe implements PipeTransform {
|
|
|
|
transform(value: string, arg1?: string, arg2?: string): string {
|
|
value = value ? value.toLowerCase().replace(/\s+/g, '')?.replace(/-/g, ' ') : '';
|
|
if (arg1) {
|
|
value = value.replace(new RegExp(arg1, 'g'), ' ');
|
|
}
|
|
if (arg2) {
|
|
value = value.replace(new RegExp(arg2, 'g'), ' ');
|
|
}
|
|
return value.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => (word.toUpperCase()));
|
|
}
|
|
|
|
}
|