Humanize camel case pipe
This commit is contained in:
parent
7875f99a07
commit
c5b7877d4c
@ -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],
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
11
src/lib/utils/pipes/humanize-camel-case.pipe.ts
Normal file
11
src/lib/utils/pipes/humanize-camel-case.pipe.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user