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 EXJavaScriptTypedArray;
13 
14 /**
15  Represents any JavaScript value. Its purpose is to exposes `facebook::jsi::Value` API back to Swift.
16  */
17 NS_SWIFT_NAME(JavaScriptValue)
18 @interface EXJavaScriptValue : NSObject
19 
20 #ifdef __cplusplus
21 - (nonnull instancetype)initWithRuntime:(nonnull EXJavaScriptRuntime *)runtime
22                                   value:(std::shared_ptr<jsi::Value>)value;
23 
24 /**
25  \return the underlying `jsi::Value`.
26  */
27 - (nonnull jsi::Value *)get;
28 #endif // __cplusplus
29 
30 #pragma mark - Type checking
31 
32 - (BOOL)isUndefined;
33 - (BOOL)isNull;
34 - (BOOL)isBool;
35 - (BOOL)isNumber;
36 - (BOOL)isString;
37 - (BOOL)isSymbol;
38 - (BOOL)isObject;
39 - (BOOL)isFunction;
40 - (BOOL)isTypedArray;
41 
42 #pragma mark - Type casting
43 
44 - (nullable id)getRaw;
45 - (BOOL)getBool;
46 - (NSInteger)getInt;
47 - (double)getDouble;
48 - (nonnull NSString *)getString;
49 - (nonnull NSArray<EXJavaScriptValue *> *)getArray;
50 - (nonnull NSDictionary<NSString *, id> *)getDictionary;
51 - (nonnull EXJavaScriptObject *)getObject;
52 - (nullable EXJavaScriptTypedArray *)getTypedArray;
53 
54 #pragma mark - Helpers
55 
56 - (nonnull NSString *)toString;
57 
58 @end
59