mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-15 14:01:25 +00:00
js-sys: Add bindings for Intl.Collator
This commit is contained in:
@ -3142,6 +3142,50 @@ pub mod Intl {
|
|||||||
#[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
|
#[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
|
||||||
pub fn get_canonical_locales(s: &JsValue) -> Array;
|
pub fn get_canonical_locales(s: &JsValue) -> Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Intl.Collator
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
/// The Intl.Collator object is a constructor for collators, objects
|
||||||
|
/// that enable language sensitive string comparison.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator
|
||||||
|
#[wasm_bindgen(js_namespace = Intl)]
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub type Collator;
|
||||||
|
|
||||||
|
/// The Intl.Collator object is a constructor for collators, objects
|
||||||
|
/// that enable language sensitive string comparison.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator
|
||||||
|
#[wasm_bindgen(constructor, js_namespace = Intl)]
|
||||||
|
pub fn new(locales: &Array, options: &Object) -> Collator;
|
||||||
|
|
||||||
|
/// The Intl.Collator.prototype.compare property returns a function that
|
||||||
|
/// compares two strings according to the sort order of this Collator
|
||||||
|
/// object.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare
|
||||||
|
#[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
|
||||||
|
pub fn compare(this: &Collator) -> Function;
|
||||||
|
|
||||||
|
/// The Intl.Collator.prototype.resolvedOptions() method returns a new
|
||||||
|
/// object with properties reflecting the locale and collation options
|
||||||
|
/// computed during initialization of this Collator object.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions
|
||||||
|
#[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
|
||||||
|
pub fn resolved_options(this: &Collator) -> Object;
|
||||||
|
|
||||||
|
/// The Intl.Collator.supportedLocalesOf() method returns an array
|
||||||
|
/// containing those of the provided locales that are supported in
|
||||||
|
/// collation without having to fall back to the runtime's default
|
||||||
|
/// locale.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf
|
||||||
|
#[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
|
||||||
|
pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Promise
|
// Promise
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use wasm_bindgen::JsValue;
|
use wasm_bindgen::{JsCast, JsValue};
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
use js_sys::*;
|
use js_sys::*;
|
||||||
|
|
||||||
@ -23,3 +23,16 @@ fn get_canonical_locales() {
|
|||||||
assert_eq!(l, "en-US");
|
assert_eq!(l, "en-US");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn collator() {
|
||||||
|
let locales = Array::of1(&JsValue::from("en-US"));
|
||||||
|
let opts = Object::new();
|
||||||
|
|
||||||
|
let c = Intl::Collator::new(&locales, &opts);
|
||||||
|
assert!(c.compare().is_instance_of::<Function>());
|
||||||
|
assert!(c.resolved_options().is_instance_of::<Object>());
|
||||||
|
|
||||||
|
let a = Intl::Collator::supported_locales_of(&locales, &opts);
|
||||||
|
assert!(a.is_instance_of::<Array>());
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user