Humanize camel case pipe

This commit is contained in:
Adina Țeudan 2022-07-27 17:29:37 +03:00
parent 7875f99a07
commit c5b7877d4c
3 changed files with 17 additions and 1 deletions

View File

@ -36,6 +36,7 @@ import { DragDropFileUploadDirective } from './upload-file/drag-drop-file-upload
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { ConfirmationDialogComponent } from './dialog';
import { MatTooltipModule } from '@angular/material/tooltip';
import { HumanizeCamelCasePipe } from './utils/pipes/humanize-camel-case.pipe';
const matModules = [MatIconModule, MatProgressSpinnerModule, MatButtonModule, MatDialogModule, MatCheckboxModule, MatTooltipModule];
const modules = [
@ -66,7 +67,7 @@ const components = [
DragDropFileUploadDirective,
];
const pipes = [SortByPipe, HumanizePipe, CapitalizePipe, LogPipe];
const pipes = [SortByPipe, HumanizePipe, CapitalizePipe, LogPipe, HumanizeCamelCasePipe];
@NgModule({
declarations: [...components, ...pipes],

View File

@ -21,6 +21,10 @@ export function humanize(value: string, lowercase = true): string {
return words.map(capitalize).join(' ');
}
export function humanizeCamelCase(value: string): string {
return value.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase();
}
export function _log(value: unknown, message = '') {
console.log(`%c[${dayjs().format('mm:ss.SSS')}] ${message}`, 'color: yellow;', value);
}

View File

@ -0,0 +1,11 @@
import { Pipe, PipeTransform } from '@angular/core';
import { humanizeCamelCase } from '../functions';
@Pipe({
name: 'humanizeCamelCase',
})
export class HumanizeCamelCasePipe implements PipeTransform {
transform(item: string): string {
return humanizeCamelCase(item);
}
}