-
Notifications
You must be signed in to change notification settings - Fork 375
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
Add wrap function #410
Add wrap function #410
Conversation
I will have a look at it on the WE.Can you add the documentation to the |
equal(_.wrap("My name is", 2, '.', false), "My .name .is", 'works with width 2 and cut = false'); | ||
equal(_.wrap("My name is", 2, '.', true), "My. n.am.e .is", 'works with width 2 and cut = true'); | ||
equal(_.wrap("My name is", 3, '.', false), "My .name .is", 'works with width 3 and cut = true'); | ||
equal(_.wrap("My name is", 3), "My \nname \nis", 'Default parameters work'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add more tests.
- edgecases
- defaults
Checkout the other tests.
Can you rebase this? Thanks |
Rebased with a mocha test |
If you add this test: Otherwise it looks good to me. |
Done and squashed. |
return str; | ||
} | ||
else if(!cut){ | ||
words = str.split(" "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we use `underscore.string/words' here?
Let's talk about the specifics of what this is supposed to do. wrap('this is a sentence', 4, \n, false) What should this return? Right now it would return 'this \nis a \nsentence' which I'm realizing now doesn't make much sense. Would 'this\nis a\nsentence' be more obvious? |
Yes, I think so. PHP's |
Options object maybe. Could be done as backwards compatible with type checking. |
👍 for an options object I could think of some other options we could add in the future f.e. dontBreakHTMLTags |
Now wrap('this is a sentence', {width: 4, seperator: '\n', cut: false}) returns 'this\nis a\nsentence' |
Options object looks good. Could you add an option for dropping trailing spaces as discussed above? And updat the readme? Thanks for your work |
I added a trailingSpaces options which, if true, fills each line with trailing spaces to make them at least |
Sorry, I actually meant this:
Maybe call the option |
but the trailingSpaces option is nice too 👍 |
@bsteephenson Would be great if you would add the Thanks |
Working on this atm. I am having preserveSpaces have a higher precedence over trailingSpaces. |
@@ -269,6 +269,25 @@ lines("Hello\nWorld"); | |||
// => ["Hello", "World"] | |||
``` | |||
|
|||
#### wrap(str, options) => string | |||
|
|||
Splits a line `str` (default '') into several lines of size `options.width` (default 75) using a `options.seperator` (default '\n'). If `options.trailingSpaces` is true, make each line at least `width` long using trailing spaces. If `options.cut` is true, create new lines in the middle of words. If `options.trailingSpaces` is true, preserve the space that should be there at the end of a line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.trailingSpaces
is true, preserve the space that should be there at the end of a line.
This should be options.preserveSpaces
Besides my comments in the readme, this looks good to me. Thx a lot |
Corrected all the oops's in Readme |
Squashing would be nice. I want have time today to check it one more time. But I will review it again in the beginning of next week and then merge it. |
Did check it again. Could you squash? I will merge it. |
Adds a line wrapping function that limits line length to a certain width Added documentation and tests
Done =) |
nice thanks a lot. |
@stoeffel when "wrap" was added, it wasn't added to the "exports" function as a conflict with underscore. I know mixing in underscore.string is now discouraged, but unfortunately we have a lot of old code written with the mixin paradigm. I am having difficulty upgrading underscore.string from 2.x due to the wrap conflict. |
Sure, I will looking into it this weekend. I would like to add a test that checks for conflicting functions between underscore and underscore.string.exports. I haven't looked at your test framework yet, but hope it's possible to add a test-only dependency on underscore. |
@stoeffel I see that underscore is already a development dependency. Can you point me to documentation on how to run the tests locally? I poked around but couldn't find anything. |
Fixes a bug introduced in esamattis#410.
Fixes a bug introduced in esamattis#410.
Fixes a bug introduced in esamattis#410.
Adds a line wrapping function that limits line length to a certain width
In response to issue #278
Let me know if there's anything more I should do (more tests, documentation, etc). I'm glad to help out.