Skip to content
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

Implement keyword-based positioning of ellipsis / truncation point #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

StephenKoller
Copy link

In response to #10.

Feature

Allows user to specify placement of truncation marker (default ellipsis) using a relative keyword 'left', 'center', or 'right'.

Examples

smartTruncate('A quick brown fox jumped over the lazy dog', 18, {position: 'right'});
// returns 'A quick brown fox…'

smartTruncate('A quick brown fox jumped over the lazy dog', 25, {position: 'left'});
// returns '…jumped over the lazy dog'

smartTruncate('A quick brown fox jumped over the lazy dog', 26, {position: 'center'});
// returns 'A quick brown…the lazy dog'

Notes

I used a TDD approach, but the implementation is still rather naïve. I'm interested to see if the control flow could be cleaned up while maintaining legibility.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 7c41fb2 on StephenKoller:master into 4ac0c7f on millerized:master.

}

if (position === 'center') {
var _start2 = str.substring(0, length / 2);
Copy link
Author

Choose a reason for hiding this comment

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

Perhaps this could use a more descriptive name than _start2?

@millerized
Copy link
Owner

millerized commented Sep 9, 2019

This still looks really great, @StephenKoller! I have decided to move this project over to TSdx for a much improved DX.

I also need to update the dependencies because there are some transitive deps that are flagged as potential security risks. This will most likely require a major version bump on this package. Knowing all this I think it's the perfect time to finally implement your solution for keyword-based positioning!

I am targeting this week to do some of these chores and then we'll look at getting this implemented into the new TS source asap – it should be quick and easy!

Thanks for your patience, friend!

@StephenKoller
Copy link
Author

Sounds good to me, @millerized! Have been using TS a lot more lately, looking forward to seeing the next iteration of this micro-lib!

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.

None yet

3 participants