ohos.ark_interop_helper (ArkTS Interoperability Common Utility Functions)

Note:

Currently in the beta phase.

Provides common utility functions for data type conversion and interoperability, including conversion from JSValue to napi_value, format conversion between HashMap and JSValue, and other utility functions.

Import Module

import ohos.ark_interop_helper.*

Note:

Kit import methods are not supported and are expected to be supported in the next version.

func arktsValuetoNapiValue(napi_env, JSValue)

public func arktsValuetoNapiValue(env: napi_env, ark_value: JSValue): napi_value

Description: Converts a JSValue type to napi_value type.

Since: 22

Parameters:

Parameter Type Required Default Description
env napi_env Yes - Environment context.
ark_value JSValue Yes - The value to be converted.

Return Value:

Type Description
napi_value The converted napi_value.

func isStageMode(napi_env, napi_value)

public func isStageMode(env: napi_env, context: napi_value): Bool

Description: Determines whether it is in application mode.

Since: 22

Parameters:

Parameter Type Required Default Description
env napi_env Yes - Environment information.
context napi_value Yes - Context information.

Return Value:

Type Description
Bool Whether it is in application mode.

func mapFromJSValue<T>(JSContext, JSValue, (JSContext,JSValue) -> T)

public func mapFromJSValue<T>(
    context: JSContext,
    value: JSValue,
    convert: (JSContext, JSValue) -> T
): ?HashMap<String, T>

Description: Converts JSValue formatted data into HashMap.

Since: 22

Parameters:

Parameter Type Required Default Description
context JSContext Yes - Interoperation context.
value JSValue Yes - The JSValue data to be converted.
convert (JSContext, JSValue)->T Yes - Converts the value corresponding to the HashMap's key into type T after treating JSValue as a HashMap.

Return Value:

Type Description
?HashMap<String, T> The converted HashMap data.

func mapToJSValue<T>(JSContext, ?HashMap<String,T>, (JSContext,T) -> JSValue)

public func mapToJSValue<T>(
    context: JSContext,
    parameter: ?HashMap<String, T>,
    convert: (JSContext, T) -> JSValue
): JSValue

Description: Converts HashMap formatted data into JSValue.

Since: 22

Parameters:

Parameter Type Required Default Description
context JSContext Yes - Interoperation context.
parameter ?HashMap<String, T> Yes - The HashMap data to be converted.
convert (JSContext, T)->JSValue Yes - Converts the HashMap's T type into JSValue.

Return Value:

Type Description
JSValue The converted JSValue data.