Skip to content

Conversation

jake-bassett
Copy link
Contributor

Description

We keep using the same code over and over. Turning it into a const method and pipe.

@jake-bassett jake-bassett requested a review from a team as a code owner April 7, 2021 20:17
@Pipe({
name: 'htDisplayStringEnum'
})
export class DisplayStringEnumPipe implements PipeTransform {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use displayString?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Not sure that will work, or at least it shouldn't. The displayString method shouldn't replace - or _. It should just basically String() any input but not format it... with some extra logic for null checks, arrays, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to overload display string with this behavior (for example "my-value" would become "My Value", which we don't want the main string pipe doing)

@codecov
Copy link

codecov bot commented Apr 7, 2021

Codecov Report

Merging #752 (c00c4a2) into main (2d75012) will increase coverage by 0.00%.
The diff coverage is 85.71%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #752   +/-   ##
=======================================
  Coverage   85.34%   85.34%           
=======================================
  Files         786      788    +2     
  Lines       16115    16129   +14     
  Branches     2054     2055    +1     
=======================================
+ Hits        13753    13765   +12     
- Misses       2331     2333    +2     
  Partials       31       31           
Impacted Files Coverage Δ
...lities/formatters/enum/display-string-enum.pipe.ts 60.00% <60.00%> (ø)
projects/common/src/public-api.ts 100.00% <100.00%> (ø)
...c/utilities/formatters/enum/display-string-enum.ts 100.00% <100.00%> (ø)
...mmon/src/utilities/formatters/formatting.module.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d75012...c00c4a2. Read the comment docs.

@github-actions

This comment has been minimized.

Copy link
Contributor

@aaron-steinfeld aaron-steinfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, tests please (at least on the const function, the pipe is trivial enough to not matter)

@github-actions

This comment has been minimized.

@jake-bassett jake-bassett requested a review from anandtiwary April 7, 2021 21:02
// This removes dashes and underscores and gives all words initial caps
const startCased = startCase(provided);

// We only want the first word capitalized.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's what we want, what about capitalize(lowerCase(provided)) - believe that works the same way as startCase:

_.lowerCase('--Foo-Bar--');
// => 'foo bar'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does look cleaner, but I think this one fails for camelCase and PascalCase.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lodash should have ng pipes for each method. 'text' | lowercase | capitalize

@jake-bassett jake-bassett merged commit 24b8a5c into main Apr 7, 2021
@jake-bassett jake-bassett deleted the display-string-enum-pipe branch April 7, 2021 21:38
@github-actions
Copy link

github-actions bot commented Apr 7, 2021

Unit Test Results

    4 files  ±0  247 suites  +1   14m 57s ⏱️ -31s
884 tests +1  884 ✔️ +1  0 💤 ±0  0 ❌ ±0 
890 runs  +1  890 ✔️ +1  0 💤 ±0  0 ❌ ±0 

Results for commit 24b8a5c. ± Comparison against base commit 2d75012.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants