1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::fmt::{Display, Formatter, Result};

use crate::sys;

#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)]
pub enum ValueType {
  Undefined = 0,
  Null = 1,
  Boolean = 2,
  Number = 3,
  String = 4,
  Symbol = 5,
  Object = 6,
  Function = 7,
  External = 8,
  #[cfg(feature = "napi6")]
  BigInt = 9,
  Unknown = 1024,
}

impl Display for ValueType {
  fn fmt(&self, f: &mut Formatter<'_>) -> Result {
    let status_string = format!("{:?}", self);
    write!(f, "{}", status_string)
  }
}

impl From<i32> for ValueType {
  fn from(value: i32) -> ValueType {
    match value {
      #[cfg(feature = "napi6")]
      sys::ValueType::napi_bigint => ValueType::BigInt,
      sys::ValueType::napi_boolean => ValueType::Boolean,
      sys::ValueType::napi_external => ValueType::External,
      sys::ValueType::napi_function => ValueType::Function,
      sys::ValueType::napi_null => ValueType::Null,
      sys::ValueType::napi_number => ValueType::Number,
      sys::ValueType::napi_object => ValueType::Object,
      sys::ValueType::napi_string => ValueType::String,
      sys::ValueType::napi_symbol => ValueType::Symbol,
      sys::ValueType::napi_undefined => ValueType::Undefined,
      _ => ValueType::Unknown,
    }
  }
}