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

String.prototype.padCenter, how about that? #1292

Closed
rzorzal opened this Issue Aug 21, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@rzorzal

rzorzal commented Aug 21, 2018

Hello guys, I here to talk about padStart, padEnd and my new proposal "padCenter", I think it is not hard to develop because we already had padStart and padEnd.

I thought that we need to add one more feature to String's prototype, and it is not a hard work. So the proposal is to create the String.prototype.padCenter that centralize a string with a max character lenght, equals we do when call the "pad" functions.

For exemple, when we call padStart

"MY-TEST".padStart(32)
//result: "                         MY-TEST"

and when we call padEnd:

"MY-TEST".padEnd(32)
//result: "MY-TEST                         "

how about that:

"MY-TEST".padCenter(32)
//result: "            MY-TEST            "

I'm searching it for a long time and I seen people talking about it in different use cases. But for me it will be usefull when I need to send some text data to my bluetooth printer, becouse the length of his line is 32 and I need to centralize the data and adjust the line to right and left.

I think this feature can improve the language and it will be useful for other developers like me.

Although we has libs that has an implementation of it
https://lodash.com/docs#pad
http://gabceb.github.io/underscore.string.site/#pad
https://vocajs.com/#pad
I think it can be done for native functions too

And it is native for other languages, such as:
1. PHP (https://www.w3schools.com/php/showphp.asp?filename=demo_func_string_str_pad3)
2. Python (https://docs.python.org/2/library/string.html#string.center)
3. Ruby (https://ruby-doc.org/core-2.2.0/String.html#center-method)
4. R (https://www.rdocumentation.org/packages/stringr/versions/1.3.1/topics/str_pad)
5. etc...

What do you guys think ?

( We can call it "pad" instead of "padCenter" haha )

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Aug 21, 2018

Member

Please read https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md for how to best suggest new features.

Member

ljharb commented Aug 21, 2018

Please read https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md for how to best suggest new features.

@ljharb ljharb closed this Aug 21, 2018

@rzorzal

This comment has been minimized.

Show comment
Hide comment
@rzorzal

rzorzal Aug 21, 2018

Ok, sorry. I thought we need discussing it before create a pull-request for it.

rzorzal commented Aug 21, 2018

Ok, sorry. I thought we need discussing it before create a pull-request for it.

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Aug 21, 2018

Member

@rzorzal yes, you’d also need a champion, and generally pull requests for new features aren’t made until stage 3.

Member

ljharb commented Aug 21, 2018

@rzorzal yes, you’d also need a champion, and generally pull requests for new features aren’t made until stage 3.

@rzorzal

This comment has been minimized.

Show comment
Hide comment
@rzorzal

rzorzal Aug 21, 2018

HMM, ok. Only for my understanding, how can I apply it ? I thought everyone can went apply a new conversation for new features. So, for this purpose I need to contact other one to be my "hero" and than he can apply this new feature ?

rzorzal commented Aug 21, 2018

HMM, ok. Only for my understanding, how can I apply it ? I thought everyone can went apply a new conversation for new features. So, for this purpose I need to contact other one to be my "hero" and than he can apply this new feature ?

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Aug 21, 2018

Member

You’d need to find a TC39 member willing to champion the proposal; you’d want to start by emailing es-discuss, as noted here

Member

ljharb commented Aug 21, 2018

You’d need to find a TC39 member willing to champion the proposal; you’d want to start by emailing es-discuss, as noted here

@rzorzal

This comment has been minimized.

Show comment
Hide comment
@rzorzal

rzorzal Aug 21, 2018

Thanks a lot, I will send the e-mail right now.

rzorzal commented Aug 21, 2018

Thanks a lot, I will send the e-mail right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment