proposal: String.prototype.padCenter
What's wrong with combining padStart
with padEnd
? I'm not sure this is
worth it, since you can easily emulate it anyways (as you stated).
What's wrong with combining `padStart` with `padEnd`? I'm not sure this is worth it, since you can easily emulate it anyways (as you stated). On Tue, Aug 21, 2018 at 16:44 Ricardo Zorzal <ricardozorzal at hotmail.com> wrote: > 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 > > ```javascript > "MY-TEST".padStart(32) > //result: " MY-TEST" > ``` > > and when we call padEnd: > > ```javascript > "MY-TEST".padEnd(32) > //result: "MY-TEST " > ``` > > how about that: > > ```javascript > "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 ) > > > Att, > > *Ricardo Zorzal Davila * > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180821/98a7f219/attachment-0001.html>
How would you combine padStart and padEnd to get the desired result? Just curious, because the idea would be to create a minimum of 32 chars with the original string centered inside the "padding" (if there is any)
How would you combine padStart and padEnd to get the desired result? Just curious, because the idea would be to create a minimum of 32 chars with the original string centered inside the "padding" (if there is any) On Wed, 22 Aug 2018 at 07:26 Isiah Meadows <isiahmeadows at gmail.com> wrote: > What's wrong with combining `padStart` with `padEnd`? I'm not sure this is > worth it, since you can easily emulate it anyways (as you stated). > On Tue, Aug 21, 2018 at 16:44 Ricardo Zorzal <ricardozorzal at hotmail.com> > wrote: > >> 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 >> >> ```javascript >> "MY-TEST".padStart(32) >> //result: " MY-TEST" >> ``` >> >> and when we call padEnd: >> >> ```javascript >> "MY-TEST".padEnd(32) >> //result: "MY-TEST " >> ``` >> >> how about that: >> >> ```javascript >> "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 ) >> >> >> Att, >> >> *Ricardo Zorzal Davila * >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180822/425f47ad/attachment.html>
x.padStart((x.length + 32)/2).padEnd(32)
(BTW, I don’t like this habit of top-posting the reply. Please look below for the question I’m answering, and read the mail backwards for more context.)
```js x.padStart((x.length + 32)/2).padEnd(32) ``` (BTW, I don’t like this habit of top-posting the reply. Please look below for the question I’m answering, and read the mail backwards for more context.) —Claude > Le 22 août 2018 à 05:47, Naveen Chawla <naveen.chwl at gmail.com> a écrit : > > How would you combine padStart and padEnd to get the desired result? Just curious, because the idea would be to create a minimum of 32 chars with the original string centered inside the "padding" (if there is any) > > On Wed, 22 Aug 2018 at 07:26 Isiah Meadows <isiahmeadows at gmail.com <mailto:isiahmeadows at gmail.com>> wrote: > What's wrong with combining `padStart` with `padEnd`? I'm not sure this is worth it, since you can easily emulate it anyways (as you stated). > On Tue, Aug 21, 2018 at 16:44 Ricardo Zorzal <ricardozorzal at hotmail.com <mailto:ricardozorzal at hotmail.com>> wrote: > 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 > > ```javascript > "MY-TEST".padStart(32) > //result: " MY-TEST" > ``` > > and when we call padEnd: > > ```javascript > "MY-TEST".padEnd(32) > //result: "MY-TEST " > ``` > > how about that: > > ```javascript > "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 <https://lodash.com/docs#pad> > http://gabceb.github.io/underscore.string.site/#pad <http://gabceb.github.io/underscore.string.site/#pad> > https://vocajs.com/#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 <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 <https://docs.python.org/2/library/string.html#string.center>) > 3. Ruby (https://ruby-doc.org/core-2.2.0/String.html#center-method <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 <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 ) > > > Att, > > Ricardo Zorzal Davila > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> > https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> > https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180822/797b18d0/attachment-0001.html>
Isiah Meadows , don't have any problems in combine this two functions, but if it can be done with a native functions it could pass more confiability to javascript functions, avoiding polyfills, like I do.
In the past, when we did not had padStart and padEnd, we were using some polyfills functions to construct this two functions for us, then the comunity looked at this features and then started to implementing it. BTW, I do not know why we did not implementing this function when the padStart e padEnd was developed too.
And again, I think it's not hard to be done, but necessary. And Claude Pache, thanks for your exemple.
Naveen Chawla, yes this is the idea, as the same as the other "pad" functions, and look at the exemple from Claude Pache, it can be done like he coded.
I hope you guys understending that this is necessary to growth the language and make it more pratical than now.
Perhaps has other developers searching for this solution and they seen it in libs, polyfills and frameworks, but they do not like the idea to import other lib in the project just to use this feature.
And again, it seems not hard to be done.
Att,
Ricardo Zorzal Davila
Isiah Meadows , don't have any problems in combine this two functions, but if it can be done with a native functions it could pass more confiability to javascript functions, avoiding polyfills, like I do. In the past, when we did not had padStart and padEnd, we were using some polyfills functions to construct this two functions for us, then the comunity looked at this features and then started to implementing it. BTW, I do not know why we did not implementing this function when the padStart e padEnd was developed too. And again, I think it's not hard to be done, but necessary. And Claude Pache, thanks for your exemple. Naveen Chawla, yes this is the idea, as the same as the other "pad" functions, and look at the exemple from Claude Pache, it can be done like he coded. I hope you guys understending that this is necessary to growth the language and make it more pratical than now. Perhaps has other developers searching for this solution and they seen it in libs, polyfills and frameworks, but they do not like the idea to import other lib in the project just to use this feature. And again, it seems not hard to be done. Att, Ricardo Zorzal Davila ________________________________ De: es-discuss <es-discuss-bounces at mozilla.org> em nome de Claude Pache <claude.pache at gmail.com> Enviado: quarta-feira, 22 de agosto de 2018 04:49 Para: Naveen Chawla Cc: es-discuss at mozilla.org Assunto: Re: proposal: String.prototype.padCenter ```js x.padStart((x.length + 32)/2).padEnd(32) ``` (BTW, I don’t like this habit of top-posting the reply. Please look below for the question I’m answering, and read the mail backwards for more context.) —Claude Le 22 août 2018 à 05:47, Naveen Chawla <naveen.chwl at gmail.com<mailto:naveen.chwl at gmail.com>> a écrit : How would you combine padStart and padEnd to get the desired result? Just curious, because the idea would be to create a minimum of 32 chars with the original string centered inside the "padding" (if there is any) On Wed, 22 Aug 2018 at 07:26 Isiah Meadows <isiahmeadows at gmail.com<mailto:isiahmeadows at gmail.com>> wrote: What's wrong with combining `padStart` with `padEnd`? I'm not sure this is worth it, since you can easily emulate it anyways (as you stated). On Tue, Aug 21, 2018 at 16:44 Ricardo Zorzal <ricardozorzal at hotmail.com<mailto:ricardozorzal at hotmail.com>> wrote: 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 ```javascript "MY-TEST".padStart(32) //result: " MY-TEST" ``` and when we call padEnd: ```javascript "MY-TEST".padEnd(32) //result: "MY-TEST " ``` how about that: ```javascript "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 ) Att, Ricardo Zorzal Davila _______________________________________________ es-discuss mailing list es-discuss at mozilla.org<mailto:es-discuss at mozilla.org> https://mail.mozilla.org/listinfo/es-discuss _______________________________________________ es-discuss mailing list es-discuss at mozilla.org<mailto:es-discuss at mozilla.org> https://mail.mozilla.org/listinfo/es-discuss _______________________________________________ es-discuss mailing list es-discuss at mozilla.org<mailto:es-discuss at mozilla.org> https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180822/7a08cb61/attachment-0001.html>
Isn't "bluetooth printer" too niche a use case? Any other examples?
Isn't "bluetooth printer" too niche a use case? Any other examples? On Wed, 22 Aug 2018 at 17:59 Ricardo Zorzal <ricardozorzal at hotmail.com> wrote: > > Isiah Meadows , don't have any problems in combine this two functions, but > if it can be done with a native functions it could pass more confiability > to javascript functions, avoiding polyfills, like I do. > > In the past, when we did not had padStart and padEnd, we were using some > polyfills functions to construct this two functions for us, then the > comunity looked at this features and then started to implementing it. BTW, > I do not know why we did not implementing this function when the padStart e > padEnd was developed too. > > And again, I think it's not hard to be done, but necessary. And Claude > Pache, thanks for your exemple. > > Naveen Chawla, yes this is the idea, as the same as the other "pad" > functions, and look at the exemple from Claude Pache, it can be done like > he coded. > > I hope you guys understending that this is necessary to growth the > language and make it more pratical than now. > > Perhaps has other developers searching for this solution and they seen it > in libs, polyfills and frameworks, but they do not like the idea to import > other lib in the project just to use this feature. > > And again, it seems not hard to be done. > > > Att, > > *Ricardo Zorzal Davila * > ------------------------------ > *De:* es-discuss <es-discuss-bounces at mozilla.org> em nome de Claude Pache > <claude.pache at gmail.com> > *Enviado:* quarta-feira, 22 de agosto de 2018 04:49 > *Para:* Naveen Chawla > *Cc:* es-discuss at mozilla.org > *Assunto:* Re: proposal: String.prototype.padCenter > > ```js > x.padStart((x.length + 32)/2).padEnd(32) > ``` > > (BTW, I don’t like this habit of top-posting the reply. Please look below > for the question I’m answering, and read the mail backwards for more > context.) > > —Claude > > Le 22 août 2018 à 05:47, Naveen Chawla <naveen.chwl at gmail.com> a écrit : > > How would you combine padStart and padEnd to get the desired result? Just > curious, because the idea would be to create a minimum of 32 chars with the > original string centered inside the "padding" (if there is any) > > On Wed, 22 Aug 2018 at 07:26 Isiah Meadows <isiahmeadows at gmail.com> wrote: > > What's wrong with combining `padStart` with `padEnd`? I'm not sure this is > worth it, since you can easily emulate it anyways (as you stated). > On Tue, Aug 21, 2018 at 16:44 Ricardo Zorzal <ricardozorzal at hotmail.com> > wrote: > > 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 > > ```javascript > "MY-TEST".padStart(32) > //result: " MY-TEST" > ``` > > and when we call padEnd: > > ```javascript > "MY-TEST".padEnd(32) > //result: "MY-TEST " > ``` > > how about that: > > ```javascript > "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 ) > > > Att, > > *Ricardo Zorzal Davila * > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180822/d3353787/attachment.html>
specially in console it'd be handy to have centered headers, i.e.
August 2018
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
I think, as simple as this features look, I'd be happy to have it in core too.
specially in console it'd be handy to have centered headers, i.e. August 2018 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 I think, as simple as this features look, I'd be happy to have it in core too. Regards On Wed, Aug 22, 2018 at 5:57 PM Naveen Chawla <naveen.chwl at gmail.com> wrote: > Isn't "bluetooth printer" too niche a use case? Any other examples? > > On Wed, 22 Aug 2018 at 17:59 Ricardo Zorzal <ricardozorzal at hotmail.com> > wrote: > >> >> Isiah Meadows , don't have any problems in combine this two functions, >> but if it can be done with a native functions it could pass more >> confiability to javascript functions, avoiding polyfills, like I do. >> >> In the past, when we did not had padStart and padEnd, we were using some >> polyfills functions to construct this two functions for us, then the >> comunity looked at this features and then started to implementing it. BTW, >> I do not know why we did not implementing this function when the padStart e >> padEnd was developed too. >> >> And again, I think it's not hard to be done, but necessary. And Claude >> Pache, thanks for your exemple. >> >> Naveen Chawla, yes this is the idea, as the same as the other "pad" >> functions, and look at the exemple from Claude Pache, it can be done like >> he coded. >> >> I hope you guys understending that this is necessary to growth the >> language and make it more pratical than now. >> >> Perhaps has other developers searching for this solution and they seen it >> in libs, polyfills and frameworks, but they do not like the idea to import >> other lib in the project just to use this feature. >> >> And again, it seems not hard to be done. >> >> >> Att, >> >> *Ricardo Zorzal Davila * >> ------------------------------ >> *De:* es-discuss <es-discuss-bounces at mozilla.org> em nome de Claude >> Pache <claude.pache at gmail.com> >> *Enviado:* quarta-feira, 22 de agosto de 2018 04:49 >> *Para:* Naveen Chawla >> *Cc:* es-discuss at mozilla.org >> *Assunto:* Re: proposal: String.prototype.padCenter >> >> ```js >> x.padStart((x.length + 32)/2).padEnd(32) >> ``` >> >> (BTW, I don’t like this habit of top-posting the reply. Please look below >> for the question I’m answering, and read the mail backwards for more >> context.) >> >> —Claude >> >> Le 22 août 2018 à 05:47, Naveen Chawla <naveen.chwl at gmail.com> a écrit : >> >> How would you combine padStart and padEnd to get the desired result? Just >> curious, because the idea would be to create a minimum of 32 chars with the >> original string centered inside the "padding" (if there is any) >> >> On Wed, 22 Aug 2018 at 07:26 Isiah Meadows <isiahmeadows at gmail.com> >> wrote: >> >> What's wrong with combining `padStart` with `padEnd`? I'm not sure this >> is worth it, since you can easily emulate it anyways (as you stated). >> On Tue, Aug 21, 2018 at 16:44 Ricardo Zorzal <ricardozorzal at hotmail.com> >> wrote: >> >> 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 >> >> ```javascript >> "MY-TEST".padStart(32) >> //result: " MY-TEST" >> ``` >> >> and when we call padEnd: >> >> ```javascript >> "MY-TEST".padEnd(32) >> //result: "MY-TEST " >> ``` >> >> how about that: >> >> ```javascript >> "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 ) >> >> >> Att, >> >> *Ricardo Zorzal Davila * >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> >> _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180822/15d2ffd5/attachment-0001.html>
It can also be quite useful in Node, to center things printed to the terminal.
Il mer 22 ago 2018, 17:57 Naveen Chawla <naveen.chwl at gmail.com> ha scritto:
It can also be quite useful in Node, to center things printed to the terminal. Il mer 22 ago 2018, 17:57 Naveen Chawla <naveen.chwl at gmail.com> ha scritto: > Isn't "bluetooth printer" too niche a use case? Any other examples? > > On Wed, 22 Aug 2018 at 17:59 Ricardo Zorzal <ricardozorzal at hotmail.com> > wrote: > >> >> Isiah Meadows , don't have any problems in combine this two functions, >> but if it can be done with a native functions it could pass more >> confiability to javascript functions, avoiding polyfills, like I do. >> >> In the past, when we did not had padStart and padEnd, we were using some >> polyfills functions to construct this two functions for us, then the >> comunity looked at this features and then started to implementing it. BTW, >> I do not know why we did not implementing this function when the padStart e >> padEnd was developed too. >> >> And again, I think it's not hard to be done, but necessary. And Claude >> Pache, thanks for your exemple. >> >> Naveen Chawla, yes this is the idea, as the same as the other "pad" >> functions, and look at the exemple from Claude Pache, it can be done like >> he coded. >> >> I hope you guys understending that this is necessary to growth the >> language and make it more pratical than now. >> >> Perhaps has other developers searching for this solution and they seen it >> in libs, polyfills and frameworks, but they do not like the idea to import >> other lib in the project just to use this feature. >> >> And again, it seems not hard to be done. >> >> >> Att, >> >> *Ricardo Zorzal Davila * >> ------------------------------ >> *De:* es-discuss <es-discuss-bounces at mozilla.org> em nome de Claude >> Pache <claude.pache at gmail.com> >> *Enviado:* quarta-feira, 22 de agosto de 2018 04:49 >> *Para:* Naveen Chawla >> *Cc:* es-discuss at mozilla.org >> *Assunto:* Re: proposal: String.prototype.padCenter >> >> ```js >> x.padStart((x.length + 32)/2).padEnd(32) >> ``` >> >> (BTW, I don’t like this habit of top-posting the reply. Please look below >> for the question I’m answering, and read the mail backwards for more >> context.) >> >> —Claude >> >> Le 22 août 2018 à 05:47, Naveen Chawla <naveen.chwl at gmail.com> a écrit : >> >> How would you combine padStart and padEnd to get the desired result? Just >> curious, because the idea would be to create a minimum of 32 chars with the >> original string centered inside the "padding" (if there is any) >> >> On Wed, 22 Aug 2018 at 07:26 Isiah Meadows <isiahmeadows at gmail.com> >> wrote: >> >> What's wrong with combining `padStart` with `padEnd`? I'm not sure this >> is worth it, since you can easily emulate it anyways (as you stated). >> On Tue, Aug 21, 2018 at 16:44 Ricardo Zorzal <ricardozorzal at hotmail.com> >> wrote: >> >> 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 >> >> ```javascript >> "MY-TEST".padStart(32) >> //result: " MY-TEST" >> ``` >> >> and when we call padEnd: >> >> ```javascript >> "MY-TEST".padEnd(32) >> //result: "MY-TEST " >> ``` >> >> how about that: >> >> ```javascript >> "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 ) >> >> >> Att, >> >> *Ricardo Zorzal Davila * >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> >> _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180822/7866b768/attachment.html>
Like Nicolò said, it could be useful to make more pretty print to the terminal(Node.js), and also in the console(browser).
I think it can be useful for hide informations about id's
"12049393823947".substr(3,6).padCenter(14,'*');
//result: "****493938****"
Other use case that I thought is to customize titles with some custom characters like:
"MY TITLE".padCenter(14,'~');
//result: "~~~MY TITLE~~~"
In addition, it can make logs more readable too.
So, maybe this feature should had three arguments:
String.prototype.padCenter = function(maxLength [, padStringLeft, padStringRight]){}
"padStringLeft" as the string that fills the left part and as "padStringRight" that fills the right part.
Att,
Ricardo Zorzal Davila
Like Nicolò said, it could be useful to make more pretty print to the terminal(Node.js), and also in the console(browser). I think it can be useful for hide informations about id's ```javascript "12049393823947".substr(3,6).padCenter(14,'*'); //result: "****493938****" ``` Other use case that I thought is to customize titles with some custom characters like: ```javascript "MY TITLE".padCenter(14,'~'); //result: "~~~MY TITLE~~~" ``` In addition, it can make logs more readable too. So, maybe this feature should had three arguments: ```javascript String.prototype.padCenter = function(maxLength [, padStringLeft, padStringRight]){} ``` "padStringLeft" as the string that fills the left part and as "padStringRight" that fills the right part. Att, Ricardo Zorzal Davila ________________________________ De: Nicolò Ribaudo <nicolo.ribaudo at gmail.com> Enviado: quarta-feira, 22 de agosto de 2018 14:18 Para: Naveen Chawla Cc: Ricardo Zorzal; es-discuss at mozilla.org Assunto: Re: proposal: String.prototype.padCenter It can also be quite useful in Node, to center things printed to the terminal. Il mer 22 ago 2018, 17:57 Naveen Chawla <naveen.chwl at gmail.com<mailto:naveen.chwl at gmail.com>> ha scritto: Isn't "bluetooth printer" too niche a use case? Any other examples? On Wed, 22 Aug 2018 at 17:59 Ricardo Zorzal <ricardozorzal at hotmail.com<mailto:ricardozorzal at hotmail.com>> wrote: Isiah Meadows , don't have any problems in combine this two functions, but if it can be done with a native functions it could pass more confiability to javascript functions, avoiding polyfills, like I do. In the past, when we did not had padStart and padEnd, we were using some polyfills functions to construct this two functions for us, then the comunity looked at this features and then started to implementing it. BTW, I do not know why we did not implementing this function when the padStart e padEnd was developed too. And again, I think it's not hard to be done, but necessary. And Claude Pache, thanks for your exemple. Naveen Chawla, yes this is the idea, as the same as the other "pad" functions, and look at the exemple from Claude Pache, it can be done like he coded. I hope you guys understending that this is necessary to growth the language and make it more pratical than now. Perhaps has other developers searching for this solution and they seen it in libs, polyfills and frameworks, but they do not like the idea to import other lib in the project just to use this feature. And again, it seems not hard to be done. Att, Ricardo Zorzal Davila ________________________________ De: es-discuss <es-discuss-bounces at mozilla.org<mailto:es-discuss-bounces at mozilla.org>> em nome de Claude Pache <claude.pache at gmail.com<mailto:claude.pache at gmail.com>> Enviado: quarta-feira, 22 de agosto de 2018 04:49 Para: Naveen Chawla Cc: es-discuss at mozilla.org<mailto:es-discuss at mozilla.org> Assunto: Re: proposal: String.prototype.padCenter ```js x.padStart((x.length + 32)/2).padEnd(32) ``` (BTW, I don’t like this habit of top-posting the reply. Please look below for the question I’m answering, and read the mail backwards for more context.) —Claude Le 22 août 2018 à 05:47, Naveen Chawla <naveen.chwl at gmail.com<mailto:naveen.chwl at gmail.com>> a écrit : How would you combine padStart and padEnd to get the desired result? Just curious, because the idea would be to create a minimum of 32 chars with the original string centered inside the "padding" (if there is any) On Wed, 22 Aug 2018 at 07:26 Isiah Meadows <isiahmeadows at gmail.com<mailto:isiahmeadows at gmail.com>> wrote: What's wrong with combining `padStart` with `padEnd`? I'm not sure this is worth it, since you can easily emulate it anyways (as you stated). On Tue, Aug 21, 2018 at 16:44 Ricardo Zorzal <ricardozorzal at hotmail.com<mailto:ricardozorzal at hotmail.com>> wrote: 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 ```javascript "MY-TEST".padStart(32) //result: " MY-TEST" ``` and when we call padEnd: ```javascript "MY-TEST".padEnd(32) //result: "MY-TEST " ``` how about that: ```javascript "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 ) Att, Ricardo Zorzal Davila _______________________________________________ es-discuss mailing list es-discuss at mozilla.org<mailto:es-discuss at mozilla.org> https://mail.mozilla.org/listinfo/es-discuss _______________________________________________ es-discuss mailing list es-discuss at mozilla.org<mailto:es-discuss at mozilla.org> https://mail.mozilla.org/listinfo/es-discuss _______________________________________________ es-discuss mailing list es-discuss at mozilla.org<mailto:es-discuss at mozilla.org> https://mail.mozilla.org/listinfo/es-discuss _______________________________________________ es-discuss mailing list es-discuss at mozilla.org<mailto:es-discuss at mozilla.org> https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180823/64873a2c/attachment.html>
Then it should be probably like:
String.prototype.padCenter = function(maxLength [, padStringLeft = " " [,
padStringRight = padStringLeft]]){}
but in locales where the text is right to left might be confusing, so since
the left/right thing is a very specialized use case, I'd personally keep it
simple and accept only one pad
parameter, not two.
Then it should be probably like: ```js String.prototype.padCenter = function(maxLength [, padStringLeft = " " [, padStringRight = padStringLeft]]){} ``` but in locales where the text is right to left might be confusing, so since the left/right thing is a very specialized use case, I'd personally keep it simple and accept only one `pad` parameter, not two. Regards On Thu, Aug 23, 2018 at 3:49 AM Ricardo Zorzal <ricardozorzal at hotmail.com> wrote: > > Like Nicolò said, it could be useful to make more pretty print to the > terminal(Node.js), and also in the console(browser). > > I think it can be useful for hide informations about id's > > ```javascript > "12049393823947".substr(3,6).padCenter(14,'*'); > //result: "****493938****" > ``` > > Other use case that I thought is to customize titles with some custom > characters like: > > ```javascript > "MY TITLE".padCenter(14,'~'); > //result: "~~~MY TITLE~~~" > ``` > > In addition, it can make logs more readable too. > > So, maybe this feature should had three arguments: > > ```javascript > String.prototype.padCenter = function(maxLength [, padStringLeft, > padStringRight]){} > ``` > > "padStringLeft" as the string that fills the left part and as > "padStringRight" that fills the right part. > > Att, > > *Ricardo Zorzal Davila * > ------------------------------ > *De:* Nicolò Ribaudo <nicolo.ribaudo at gmail.com> > *Enviado:* quarta-feira, 22 de agosto de 2018 14:18 > *Para:* Naveen Chawla > *Cc:* Ricardo Zorzal; es-discuss at mozilla.org > *Assunto:* Re: proposal: String.prototype.padCenter > > It can also be quite useful in Node, to center things printed to the > terminal. > > Il mer 22 ago 2018, 17:57 Naveen Chawla <naveen.chwl at gmail.com> ha > scritto: > > Isn't "bluetooth printer" too niche a use case? Any other examples? > > On Wed, 22 Aug 2018 at 17:59 Ricardo Zorzal <ricardozorzal at hotmail.com> > wrote: > > > Isiah Meadows , don't have any problems in combine this two functions, but > if it can be done with a native functions it could pass more confiability > to javascript functions, avoiding polyfills, like I do. > > In the past, when we did not had padStart and padEnd, we were using some > polyfills functions to construct this two functions for us, then the > comunity looked at this features and then started to implementing it. BTW, > I do not know why we did not implementing this function when the padStart e > padEnd was developed too. > > And again, I think it's not hard to be done, but necessary. And Claude > Pache, thanks for your exemple. > > Naveen Chawla, yes this is the idea, as the same as the other "pad" > functions, and look at the exemple from Claude Pache, it can be done like > he coded. > > I hope you guys understending that this is necessary to growth the > language and make it more pratical than now. > > Perhaps has other developers searching for this solution and they seen it > in libs, polyfills and frameworks, but they do not like the idea to import > other lib in the project just to use this feature. > > And again, it seems not hard to be done. > > > Att, > > *Ricardo Zorzal Davila * > ------------------------------ > *De:* es-discuss <es-discuss-bounces at mozilla.org> em nome de Claude Pache > <claude.pache at gmail.com> > *Enviado:* quarta-feira, 22 de agosto de 2018 04:49 > *Para:* Naveen Chawla > *Cc:* es-discuss at mozilla.org > *Assunto:* Re: proposal: String.prototype.padCenter > > ```js > x.padStart((x.length + 32)/2).padEnd(32) > ``` > > (BTW, I don’t like this habit of top-posting the reply. Please look below > for the question I’m answering, and read the mail backwards for more > context.) > > —Claude > > Le 22 août 2018 à 05:47, Naveen Chawla <naveen.chwl at gmail.com> a écrit : > > How would you combine padStart and padEnd to get the desired result? Just > curious, because the idea would be to create a minimum of 32 chars with the > original string centered inside the "padding" (if there is any) > > On Wed, 22 Aug 2018 at 07:26 Isiah Meadows <isiahmeadows at gmail.com> wrote: > > What's wrong with combining `padStart` with `padEnd`? I'm not sure this is > worth it, since you can easily emulate it anyways (as you stated). > On Tue, Aug 21, 2018 at 16:44 Ricardo Zorzal <ricardozorzal at hotmail.com> > wrote: > > 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 > > ```javascript > "MY-TEST".padStart(32) > //result: " MY-TEST" > ``` > > and when we call padEnd: > > ```javascript > "MY-TEST".padEnd(32) > //result: "MY-TEST " > ``` > > how about that: > > ```javascript > "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 ) > > > Att, > > *Ricardo Zorzal Davila * > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180823/45a2e2ad/attachment.html>
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 lodash.com/docs#pad, gabceb.github.io/underscore.string.site/#pad, vocajs.com/#pad I think it can be done for native functions too
And it is native for other languages, such as: 1. PHP (www.w3schools.com/php/showphp.asp?filename=demo_func_string_str_pad3) 2. Python (docs.python.org/2/library/string.html#string.center) 3. Ruby (ruby-doc.org/core-2.2.0/String.html#center-method) 4. R (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 )
Att,
Ricardo Zorzal Davila