<commit_before>use std::ptr;

use env::NapiEnv;
use result::NapiResult;
use sys;

mod any;
mod array;
mod boolean;
mod null;
mod number;
mod object;
mod string;
mod undefined;

pub use self::any::NapiAny;
pub use self::array::NapiArray;
pub use self::boolean::NapiBoolean;
pub use self::null::NapiNull;
pub use self::number::NapiNumber;
pub use self::object::NapiObject;
pub use self::string::NapiString;
pub use self::undefined::NapiUndefined;

pub trait NapiValue {
    fn as_sys_value(&self) -> sys::napi_value;
    fn env(&self) -> &NapiEnv;

    fn to_napi_boolean(&self) -> NapiResult<NapiBoolean> {
        coerce(self, sys::napi_coerce_to_bool)
    }

    fn to_napi_number(&self) -> NapiResult<NapiNumber> {
        coerce(self, sys::napi_coerce_to_number)
    }

    fn to_napi_object(&self) -> NapiResult<NapiObject> {
        coerce(self, sys::napi_coerce_to_object)
    }

    fn to_napi_string(&self) -> NapiResult<NapiString> {
        coerce(self, sys::napi_coerce_to_string)
    }

    fn as_any(&self) -> NapiAny {
        NapiAny::with_value(self.env(), self.as_sys_value())
    }

    fn instanceof(&self, constructor: &NapiObject) -> NapiResult<bool> {
        let env = self.env();
        let mut result = false;

        env.handle_status(unsafe {
            sys::napi_instanceof(
                env.as_sys_env(),
                self.as_sys_value(),
                constructor.as_sys_value(),
                &mut result,
            )
        })?;

        Ok(result)
    }

    fn is_array(&self) -> NapiResult<bool> {
        check_type(self, sys::napi_is_array)<commit_msg>fix(napi): rename NapiValue::as_any to NapiValue::as_napi_any<commit_after>use std::ptr;

use env::NapiEnv;
use result::NapiResult;
use sys;

mod any;
mod array;
mod boolean;
mod null;
mod number;
mod object;
mod string;
mod undefined;

pub use self::any::NapiAny;
pub use self::array::NapiArray;
pub use self::boolean::NapiBoolean;
pub use self::null::NapiNull;
pub use self::number::NapiNumber;
pub use self::object::NapiObject;
pub use self::string::NapiString;
pub use self::undefined::NapiUndefined;

pub trait NapiValue {
    fn as_sys_value(&self) -> sys::napi_value;
    fn env(&self) -> &NapiEnv;

    fn to_napi_boolean(&self) -> NapiResult<NapiBoolean> {
        coerce(self, sys::napi_coerce_to_bool)
    }

    fn to_napi_number(&self) -> NapiResult<NapiNumber> {
        coerce(self, sys::napi_coerce_to_number)
    }

    fn to_napi_object(&self) -> NapiResult<NapiObject> {
        coerce(self, sys::napi_coerce_to_object)
    }

    fn to_napi_string(&self) -> NapiResult<NapiString> {
        coerce(self, sys::napi_coerce_to_string)
    }

    fn as_napi_any(&self) -> NapiAny {
        NapiAny::with_value(self.env(), self.as_sys_value())
    }

    fn instanceof(&self, constructor: &NapiObject) -> NapiResult<bool> {
        let env = self.env();
        let mut result = false;

        env.handle_status(unsafe {
            sys::napi_instanceof(
                env.as_sys_env(),
                self.as_sys_value(),
                constructor.as_sys_value(),
                &mut result,
            )
        })?;

        Ok(result)
    }

    fn is_array(&self) -> NapiResult<bool> {
        check_type(self, sys::napi_is_array)
{'fraction_non_alphanumeric': 0.13086117070180814, 'fraction_numerical': 0.0, 'mean_word_length': 3.0647571606475714, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4711123', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1141, 'n_words': 217}