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

Add string methods #425

Closed
jdalton opened this issue Dec 10, 2013 · 17 comments
Closed

Add string methods #425

jdalton opened this issue Dec 10, 2013 · 17 comments

Comments

@jdalton
Copy link
Member

jdalton commented Dec 10, 2013

For 3.0 I think it's time we adopt a few string methods.

I think we should start with
capitalize, startsWith, endsWith, repeat, trim, trimLeft, trimRight, & truncate

Are there any others you all think should make the cut for 3.0?

@terinjokes
Copy link
Contributor

Do we care to be compat with underscore.string? If not, I'd love for these (and other string functions) to be unicode safe.

@jdalton
Copy link
Member Author

jdalton commented Dec 10, 2013

I'm using underscore.string, as well as others, as a reference. However, we'll follow the spec closer for methods like startsWith and endsWith. Feel free to pass along more info on the unicode concern. I want to keep the implementations as light as possible and methods that are too complex will not be included. For example sprintf will not be included.

@terinjokes
Copy link
Contributor

@mathiasbynens did a great blog post on it, though I'm sure you knew that already. 😛

I haven't done more, since there seems to be radio silence on the project (and because some of the other changes are more breaking), but for example: esamattis/underscore.string/issues/220.

@Twipped
Copy link

Twipped commented Dec 10, 2013

I would also put in a vote for camelize. Some form of strpad would be nice too.

@phated
Copy link
Contributor

phated commented Dec 10, 2013

slugify is my number 1 want, it is great for turning user entered info into package names or filenames.

@mathiasbynens
Copy link
Member

Keep in mind that many of the proposed methods (like slugify) are trickier to implement than you’d think if non-ASCII symbols are to be supported (and they should be IMHO).

@jdalton
Copy link
Member Author

jdalton commented Jan 10, 2014

I've added _.trim, _.trimLeft, _.trimRight, and _.capitalize. These new methods are used by the JS port of DocDown which v3.0.0 will use to inline documentation into the readmes of each modularized npm package.

@jdalton jdalton closed this as completed in c7888ff Mar 3, 2014
@jdalton
Copy link
Member Author

jdalton commented Mar 3, 2014

I went ahead and added support for _.camelCase, _.endsWith, _.escapeRegExp, _.kebabCase, _.pad, _.padLeft, _.padRight, _.repeat, _.snakeCase, _.startsWith, and _.truncate too. Unit testing coming. Phew.

@Delapouite
Copy link
Contributor

Great news! Thanks/

I'm a bit confused about the kebabCase naming. Where does this convention come from?
I don't quite get the metaphor between dashes and a meat sandwich.

@jdalton
Copy link
Member Author

jdalton commented Mar 3, 2014

@Delapouite

I'm a bit confused about the kebabCase naming

See Wikipedia:

In American English, kebab with no qualification refers to shish kebab (Turkish: şiş kebap) cooked on a skewer

[skewer]

In this case the words are the veggies 😀

@milesj
Copy link

milesj commented Mar 3, 2014

Agreed, kebabCase is a bit weird. I've only even seen it as hyphenate or dashify or something.

@jdalton
Copy link
Member Author

jdalton commented Mar 3, 2014

Agreed, kebabCase is a bit weird. I've only even seen it as hyphenate or dashify or something.

I like keeping it narrowed to established case conventions to avoid the wishy-washy-ness of the *ify or *ize words. The use of hyphenate is too vague as it doesn't imply what to do with the case of the words.

I think the docs cover it well.
I'm pretty much in love ❤️ with the name.

@braddunbar
Copy link
Contributor

I like keeping it narrowed to established case conventions to avoid the wishy-washy-ness of the *ify or *ize words.

Beautifully said.

@mikehayesuk
Copy link

Do you think we could get _.numberFormat in here?

Taken from underscore.string documentation:

numberFormat _.numberFormat(number, [ decimals=0, decimalSeparator='.', orderSeparator=','])

_.numberFormat(1000, 2)
=> "1,000.00"

_.numberFormat(123456789.123, 5, '.', ',')
=> "123,456,789.12300"

@jdalton
Copy link
Member Author

jdalton commented Mar 25, 2014

Do you think we could get _.numberFormat in here?

Not for 3.0.0. We've already added a lot & I want to stabilize and get it bumped out.

@bnjmnt4n
Copy link
Member

Seems like Benchmark.js's formatNumber.

jdalton added a commit that referenced this issue Sep 25, 2014
…abCase`, `_.pad`, `_.padLeft`, `_.padRight`, `_.repeat`, `_.snakeCase`, `_.startsWith`, and `_.truncate`. [closes #425]
@jdalton
Copy link
Member Author

jdalton commented Jan 18, 2015

Thanks for the feedback all. Our string methods are locked-in for v3.0.

@lodash lodash locked and limited conversation to collaborators Jan 18, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

10 participants