-
-
Notifications
You must be signed in to change notification settings - Fork 675
Add js.lib.NativeStringTools #8633
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
base: development
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a branch for a case when both locales
and options
are null.
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.
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
No description provided.