Add static .is() function for comparison of custom JavaScript classes

This commit is contained in:
Tobie Morgan Hitchcock 2023-02-12 15:52:10 +00:00
parent 6556de7cd2
commit 838d4371fe
3 changed files with 12 additions and 0 deletions

View file

@ -26,6 +26,10 @@ pub mod duration {
pub fn value(&self) -> &str {
&self.value
}
// Compare two Duration instances
pub fn is(a: &Duration, b: &Duration, args: Rest<Value>) -> bool {
a.value == b.value
}
/// Convert the object to a string
pub fn toString(&self, args: Rest<Value>) -> String {
self.value.to_owned()

View file

@ -33,6 +33,10 @@ pub mod record {
pub fn id(&self) -> &str {
&self.id
}
// Compare two Record instances
pub fn is(a: &Record, b: &Record, args: Rest<Value>) -> bool {
a.tb == b.tb && a.id == b.id
}
/// Convert the object to a string
pub fn toString(&self, args: Rest<Value>) -> String {
format!("{}:{}", self.tb, self.id)

View file

@ -26,6 +26,10 @@ pub mod uuid {
pub fn value(&self) -> &str {
&self.value
}
// Compare two Uuid instances
pub fn is(a: &Uuid, b: &Uuid, args: Rest<Value>) -> bool {
a.value == b.value
}
/// Convert the object to a string
pub fn toString(&self, args: Rest<Value>) -> String {
self.value.to_owned()