mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-28 07:51:07 +00:00
Add toLocaleString to Number
This commit is contained in:
parent
f636f7b28d
commit
6b5974d1bd
@ -213,6 +213,13 @@ extern {
|
|||||||
extern {
|
extern {
|
||||||
pub type Number;
|
pub type Number;
|
||||||
|
|
||||||
|
/// The toLocaleString() method returns a string with a language sensitive
|
||||||
|
/// representation of this number.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString
|
||||||
|
#[wasm_bindgen(method, js_name = toLocaleString)]
|
||||||
|
pub fn to_locale_string(this: &Number, locale: String) -> String;
|
||||||
|
|
||||||
/// The toPrecision() method returns a string representing the Number
|
/// The toPrecision() method returns a string representing the Number
|
||||||
/// object to the specified precision.
|
/// object to the specified precision.
|
||||||
///
|
///
|
||||||
|
@ -2,6 +2,36 @@
|
|||||||
|
|
||||||
use super::project;
|
use super::project;
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_locale_string() {
|
||||||
|
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 to_locale_string(this: &js::Number, locale: String) -> String {
|
||||||
|
this.to_locale_string(locale)
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let number = 1234.45;
|
||||||
|
assert.equal(wasm.to_locale_string(number, "de-DE"), "1,234.45");
|
||||||
|
assert.equal(wasm.to_locale_string(number, "en-US"), "1,234.45");
|
||||||
|
assert.equal(wasm.to_locale_string(number, "zh-Hans-CN-u-nu-hanidec"), "1,234.45");
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_precision() {
|
fn to_precision() {
|
||||||
project()
|
project()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user