1 // Copyright 2022-present 650 Industries. All rights reserved.
2 
3 #import <Foundation/Foundation.h>
4 #import <ExpoModulesCore/EXJavaScriptObject.h>
5 
6 #ifdef __cplusplus
7 #import <jsi/jsi.h>
8 namespace jsi = facebook::jsi;
9 #endif // __cplusplus
10 
11 @class EXJavaScriptRuntime;
12 @class EXRawJavaScriptFunction;
13 @class EXJavaScriptTypedArray;
14 
15 /**
16  Represents any JavaScript value. Its purpose is to exposes `facebook::jsi::Value` API back to Swift.
17  */
18 NS_SWIFT_NAME(JavaScriptValue)
19 @interface EXJavaScriptValue : NSObject
20 
21 #ifdef __cplusplus
22 - (nonnull instancetype)initWithRuntime:(nonnull EXJavaScriptRuntime *)runtime
23                                   value:(std::shared_ptr<jsi::Value>)value;
24 
25 /**
26  \return the underlying `jsi::Value`.
27  */
28 - (nonnull jsi::Value *)get;
29 #endif // __cplusplus
30 
31 #pragma mark - Type checking
32 
33 - (BOOL)isUndefined;
34 - (BOOL)isNull;
35 - (BOOL)isBool;
36 - (BOOL)isNumber;
37 - (BOOL)isString;
38 - (BOOL)isSymbol;
39 - (BOOL)isObject;
40 - (BOOL)isFunction;
41 - (BOOL)isTypedArray;
42 
43 #pragma mark - Type casting
44 
45 - (nullable id)getRaw;
46 - (BOOL)getBool;
47 - (NSInteger)getInt;
48 - (double)getDouble;
49 - (nonnull NSString *)getString;
50 - (nonnull NSArray<EXJavaScriptValue *> *)getArray;
51 - (nonnull NSDictionary<NSString *, id> *)getDictionary;
52 - (nonnull EXJavaScriptObject *)getObject;
53 - (nonnull EXRawJavaScriptFunction *)getFunction;
54 - (nullable EXJavaScriptTypedArray *)getTypedArray;
55 
56 #pragma mark - Helpers
57 
58 - (nonnull NSString *)toString;
59 
60 @end
61