Merge pull request #330 from elpiel/string-prototypes

String - length, trim, trimLeft, trimRight, trimStart, trimEnd, valueOf, toString
This commit is contained in:
Nick Fitzgerald
2018-06-26 17:10:15 -07:00
committed by GitHub
2 changed files with 326 additions and 90 deletions

View File

@ -625,6 +625,13 @@ extern {
#[wasm_bindgen(js_name = JsString)]
pub type JsString;
/// The length property of a String object indicates the length of a string,
/// in UTF-16 code units.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length
#[wasm_bindgen(method, getter, structural)]
pub fn length(this: &JsString) -> u32;
/// The String object's charAt() method returns a new string consisting of the single
/// UTF-16 code unit located at the specified offset into the string.
///
@ -695,6 +702,54 @@ extern {
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr
#[wasm_bindgen(method, js_class = "String")]
pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
/// The toString() method returns a string representing the specified object.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString
#[wasm_bindgen(method, js_class = "String", js_name = toString)]
pub fn to_string(this: &JsString) -> JsString;
/// The trim() method removes whitespace from both ends of a string.
/// Whitespace in this context is all the whitespace characters
/// (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim
#[wasm_bindgen(method, js_class = "String")]
pub fn trim(this: &JsString) -> JsString;
/// The trimEnd() method removes whitespace from the end of a string.
/// trimRight() is an alias of this method.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd
#[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
pub fn trim_end(this: &JsString) -> JsString;
/// The trimEnd() method removes whitespace from the end of a string.
/// trimRight() is an alias of this method.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd
#[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
pub fn trim_right(this: &JsString) -> JsString;
/// The trimStart() method removes whitespace from the beginning of a string.
/// trimLeft() is an alias of this method.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart
#[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
pub fn trim_start(this: &JsString) -> JsString;
/// The trimStart() method removes whitespace from the beginning of a string.
/// trimLeft() is an alias of this method.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart
#[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
pub fn trim_left(this: &JsString) -> JsString;
/// The valueOf() method returns the primitive value of a String object.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf
#[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
pub fn value_of(this: &JsString) -> JsString;
}
impl<'a> From<&'a str> for JsString {