mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-24 14:42:35 +03:00
add binding for join
This commit is contained in:
parent
667733e929
commit
0b80888c0d
@ -112,4 +112,10 @@ extern {
|
|||||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf
|
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf
|
||||||
#[wasm_bindgen(method, js_name = lastIndexOf)]
|
#[wasm_bindgen(method, js_name = lastIndexOf)]
|
||||||
pub fn last_index_of(this: &Array, value: JsValue, from_index: i32) -> i32;
|
pub fn last_index_of(this: &Array, value: JsValue, from_index: i32) -> i32;
|
||||||
|
|
||||||
|
/// The join() method joins all elements of an array (or an array-like object) into a string and returns this string.
|
||||||
|
///
|
||||||
|
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn join(this: &Array, delimiter: &str) -> String;
|
||||||
}
|
}
|
@ -76,4 +76,36 @@ fn last_index_of() {
|
|||||||
}
|
}
|
||||||
"#)
|
"#)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn join() {
|
||||||
|
project()
|
||||||
|
.file("src/lib.rs", r#"
|
||||||
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::js;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn join_array(this: &js::Array, delimiter: &str) -> String {
|
||||||
|
this.join(delimiter)
|
||||||
|
}
|
||||||
|
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let characters = ["a", "c", "x", "n"];
|
||||||
|
let stringValue = wasm.join_array(characters, ", ");
|
||||||
|
|
||||||
|
assert.equal("a, c, x, n", stringValue);
|
||||||
|
let withForwardSlash = wasm.join_array(characters, "/");
|
||||||
|
assert.equal("a/c/x/n", withForwardSlash);
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user