-
-
Notifications
You must be signed in to change notification settings - Fork 9
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 toLocaleString() method to array #47
base: main
Are you sure you want to change the base?
Conversation
5c2cf1e
to
4dcda51
Compare
@roberto-butti I went ahead and implemented the method, let me know if there is anything I need to improve. |
- Add method description to arr.md - Add method use case example to cheatsheet.php
4dcda51
to
e45b6a1
Compare
thank you @xanaDev for the pull request. i',m going to check the PR from my mobile device, but i can try to merge it next weekend. is it ok for you? |
@roberto-butti No problem. |
Hi @xanaDev , my suggestion is: like the toLocaleString in JS, if the locale doesn't exist or is not installed, return the string in the default locale. |
@RoadSigns @roberto-butti Thanks for the feedback. |
* Returns a string representing the elements of the array | ||
* @return string the string representation | ||
*/ | ||
public function toLocaleString(string $locale = 'en_US', string $timezone = 'UTC'): string |
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.
By the way, while this covers the Date.prototype.toLocaleString()
there is also the Object.prototype.toLocaleString()
and the Number.prototype.toLocalString()
that can be converted from the Array.protoype.toLocalString()
.
Link to the other types of toLocalString()
conversions
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString#examples
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.
I can definitely add support for the other methods, I'll update the current PR unless otherwise advised.
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.
I agree. if you want you can do it in this PR, or if you prefer you could close this and create another new PR with this refactor.
I mention "refactor" because this package is for Array so I would like to provide the toLocaleString for Arr (public method). The toLocaleString for other types (number and data) is for a clear code that is easier to test.
Ehi @xanaDev thanks for the PR. If you want, i can merge it in a new branch , so i can fix the issue for managing differences between the operating system (the implementation works fine with GNU/Linux systems but the tests fail with Windows: |
@roberto-butti Sounds good, I didn't test the implementation in windows so no surprise there. Maybe I can add the missing implementations for other types within the new branch. |
Description
Add a new method to the Arr class which returns a string representing the elements of the array, uses a default locale or user-provided locale.
Fixes issue #15