Add js.lib.NativeStringTools#8633
Add js.lib.NativeStringTools#8633terurou wants to merge 3 commits intoHaxeFoundation:developmentfrom
Conversation
std/js/lib/NativeStringTools.hx
Outdated
| the same as the given string in sort order. | ||
| */ | ||
| public static inline function localeCompare(string:String, compareString:String, ?locales:EitherType<String, Array<String>>, ?options:CollatorOptions):Bool { | ||
| return if (locales == null) { |
There was a problem hiding this comment.
Missing a branch for a case when both locales and options are null.
There was a problem hiding this comment.
Thanks for your review! I fixed it.
localeCompare() throws an error when it takes locales = null. So I use undefined.
|
@haxiomic could you please check this? |
|
To avoid the need to fill out different cases for argument combinations we can use @:native to the For example @:noClosure
@:native('')
extern class NativeStringTools {
/**
Returns a number indicating whether a reference string comes before or after or is
the same as the given string in sort order.
*/
@:native('String.prototype.localeCompare.call')
public static function localeCompare(string: String, compareString: String, ?locales: EitherType<String, Array<String>>, ?options: CollatorOptions):Bool;
}using js.lib.NativeStringTools;
trace('a'.localeCompare('b'));
// String.prototype.localeCompare.call("a","b")I'm not sure if there's a cleaner approach – what do you think @nadako? |
|
ping @nadako @haxiomic |
|
@terurou I'm looking more at that It applies to all externs with (nadako is away atm) |
|
But if you want to keep the null check approach, then maybe something like Syntax.code(
"({0}).toLocaleString()",
this,
locales == null ? js.Lib.undefined : locales,
options == null ? js.Lib.undefined : options
);Is more readable and maintainable |
|
I don't like "prototype call style" because Haxe compiler emits null into optional parameter now. In JavaScript, I think this style is better: Syntax.code(
"({0}).toLocaleString()",
this,
locales == null ? js.Lib.undefined : locales,
options == null ? js.Lib.undefined : options
); |
6e1d429 to
de52b05
Compare
|
I couldn't push to this branch so I cherry-picked your commits there: #12127 |
* [tests] add test for #11904 * Add js.lib.NativeStringTools * Fix unmatched case * refactoring * see #8633 (comment) * [js] Add charCodeAt and replace to NativeStringTools And use it in std --------- Co-authored-by: terurou <terurou@denkiyagi.jp>
No description provided.