Skip to content

Create pipe underscore to space #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- [latinise](#latinise)
- [lines](#lines)
- [underscore](#underscore)
- [underscoreToSpace](#underscoreToSpace)
- [test](#test)
- [match](#match)
- [lpad](#lpad)
Expand Down Expand Up @@ -352,6 +353,17 @@ Converts camelCase string to underscore.
<p>{{'FooBar' | underscore }}</p> <!-- Output: "foo_bar" -->
```

### underscore

Converts underscore to space.

**Usage:** `string | underscoreToSpace`

```html
<p>{{'angular_is_awesome' | underscoreToSpace }}</p> <!-- Output: "angular is awesome" -->
<p>{{'FOO_BAR' | underscore }}</p> <!-- Output: "FOO BAR" -->
```

### test

Tests if a string matches a pattern.
Expand Down
3 changes: 3 additions & 0 deletions src/ng-pipes/pipes/string/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CamelizePipe } from './camelize';
import { LatinisePipe } from './latinise';
import { LinesPipe } from './lines';
import { UnderscorePipe } from './underscore';
import { UnderscoreToSpacePipe } from './underscore-to-space';
import { MatchPipe } from './match';
import { TestPipe } from './test';
import { LeftPadPipe } from './lpad';
Expand All @@ -37,6 +38,7 @@ export const STRING_PIPES = [
LatinisePipe,
LinesPipe,
UnderscorePipe,
UnderscoreToSpacePipe,
MatchPipe,
TestPipe,
LeftPadPipe,
Expand Down Expand Up @@ -67,6 +69,7 @@ export { CamelizePipe } from './camelize';
export { LatinisePipe } from './latinise';
export { LinesPipe } from './lines';
export { UnderscorePipe } from './underscore';
export { UnderscoreToSpacePipe } from './underscore-to-space';
export { MatchPipe } from './match';
export { TestPipe } from './test';
export { LeftPadPipe } from './lpad';
Expand Down
8 changes: 8 additions & 0 deletions src/ng-pipes/pipes/string/underscore-to-space.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'underscoreToSpace' })
export class UnderscoreToSpacePipe implements PipeTransform {
transform(value: any, args?: any): any {
return value.replace(/_/g, ' ');
}
}