mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 02:00:51 +00:00
Add bindings for Intl.getCanonicalLocales
This commit is contained in:
parent
0e2e826182
commit
8352b4610f
14
src/js.rs
14
src/js.rs
@ -1628,3 +1628,17 @@ extern "C" {
|
||||
#[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = toStringTag)]
|
||||
pub fn to_string_tag() -> Symbol;
|
||||
}
|
||||
|
||||
// Intl
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
pub type Intl;
|
||||
|
||||
/// The `Intl.getCanonicalLocales()` method returns an array containing
|
||||
/// the canonical locale names. Duplicates will be omitted and elements
|
||||
/// will be validated as structurally valid language tags.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales
|
||||
#[wasm_bindgen(static_method_of = Intl, js_name = getCanonicalLocales)]
|
||||
pub fn get_canonical_locales(s: &JsValue) -> Array;
|
||||
}
|
34
tests/all/js_globals/Intl.rs
Normal file
34
tests/all/js_globals/Intl.rs
Normal file
@ -0,0 +1,34 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use project;
|
||||
|
||||
#[test]
|
||||
fn get_canonical_locales() {
|
||||
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 get_canonical_locales(v: &JsValue) -> js::Array {
|
||||
js::Intl::get_canonical_locales(v)
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
let locales = ["EN-US", "Fr"];
|
||||
let canonical_locales = wasm.get_canonical_locales(locales);
|
||||
assert.deepStrictEqual(canonical_locales, ["en-US", "fr"]);
|
||||
|
||||
let single_locale = wasm.get_canonical_locales("EN-US");
|
||||
assert.equal(single_locale, "en-US");
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
@ -10,6 +10,7 @@ mod Date;
|
||||
mod Error;
|
||||
mod Function;
|
||||
mod Generator;
|
||||
mod Intl;
|
||||
mod JsString;
|
||||
mod Map;
|
||||
mod MapIterator;
|
||||
|
Loading…
x
Reference in New Issue
Block a user