diff --git a/src/js.rs b/src/js.rs index 4733e92c..8820f44c 100644 --- a/src/js.rs +++ b/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; +} \ No newline at end of file diff --git a/tests/all/js_globals/Intl.rs b/tests/all/js_globals/Intl.rs new file mode 100644 index 00000000..86ead0a4 --- /dev/null +++ b/tests/all/js_globals/Intl.rs @@ -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() +} \ No newline at end of file diff --git a/tests/all/js_globals/mod.rs b/tests/all/js_globals/mod.rs index 238adad7..75b9fd28 100644 --- a/tests/all/js_globals/mod.rs +++ b/tests/all/js_globals/mod.rs @@ -10,6 +10,7 @@ mod Date; mod Error; mod Function; mod Generator; +mod Intl; mod JsString; mod Map; mod MapIterator;