js: implement more functions for JS backend (#12167)

This commit is contained in:
playX 2021-10-13 09:40:14 +03:00 committed by GitHub
parent ade5774313
commit d373eba79b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 134 additions and 3 deletions

View file

@ -900,3 +900,13 @@ pub fn (s []string) join(sep string) string {
// There's no better way to find length of JS String in bytes.
#Object.defineProperty(string.prototype,"len", { get: function() {return new int(new TextEncoder().encode(this.str).length);}, set: function(l) {/* ignore */ } });
// index returns the position of the first character of the input string.
// It will return `none` if the input string can't be found.
pub fn (s string) index(search string) ?int {
res := 0
#res.val = s.str.indexOf(search)
if res == -1 {
return none
}
return res
}