Types
AsyncActionStatus = enum asyncActionSuccess, asyncActionFail
- Source Edit
Module = ref object val*: napi_value env*: napi_env
- Source Edit
NapiErrorType {.pure.} = enum napiError, napiTypeError, napiRangeError, napiCustomError
- Source Edit
PromiseData[T] = object status*: AsyncActionStatus deferred*: napi_deferred work*: napi_async_work jsData*: T
- Source Edit
Procs
proc `$`(o: napi_value): string {....raises: [NapiStatusError, KeyError, ValueError, NapiStatusError, KeyError, ValueError], tags: [], forbids: [].}
- Convenient procedure to convert napi_value to string representation Source Edit
proc `[]`(obj: napi_value; index: int): napi_value {. ...raises: [NapiStatusError, ValueError], tags: [], forbids: [].}
- Alias for getElement; raises exception Source Edit
proc `[]`(obj: napi_value; key: string): napi_value {. ...raises: [KeyError, ValueError, NapiStatusError], tags: [], forbids: [].}
- Alias for getProperty Source Edit
proc `[]=`(obj: napi_value; index: int; value: napi_value) {. ...raises: [NapiStatusError, ValueError], tags: [], forbids: [].}
- Alias for setElement; raises exception Source Edit
proc `[]=`(obj: napi_value; key: string; value: napi_value) {. ...raises: [NapiStatusError, ValueError], tags: [], forbids: [].}
- Alias for setProperty, raises exception Source Edit
proc addDocBlock(fnName: string; args: openArray[(string, string, NapiValueType, bool)]) {. ...raises: [ValueError, KeyError], tags: [], forbids: [].}
- Source Edit
proc assert(status: NapiStatus) {....raises: [NapiStatusError], tags: [], forbids: [].}
- Asserts that a call returns correctly; Source Edit
proc callFunction(fn: napi_value; args: openArray[napi_value] = []; this: napi_value = %*emptyArr): napi_value {.discardable, ...raises: [NapiStatusError], tags: [], forbids: [].}
- Call a function by napi_value with given args and this context. Source Edit
proc callMethod(instance: napi_value; methd: string; args: openArray[napi_value] = []): napi_value {.discardable, ...raises: [NapiStatusError, KeyError, ValueError], tags: [], forbids: [].}
- Call a method from instance by name with given args Source Edit
proc create[T](n: Module; t: T): napi_value
- Source Edit
proc createFn(env: napi_env; fname: string; cb: napi_callback): napi_value {. ...raises: [NapiStatusError], tags: [], forbids: [].}
- Create a new function Source Edit
proc defineProperties(obj: Module) {....raises: [NapiStatusError], tags: [], forbids: [].}
- Source Edit
proc expect(env: napi_env; n: napi_value; expectKind: NapiValueType): bool {. ...raises: [NapiStatusError], tags: [], forbids: [].}
- Source Edit
proc expect(env: napi_env; v: seq[napi_value]; errorName, fnIdent: string): bool {. ...raises: [KeyError, NapiStatusError, Exception, ValueError], tags: [RootEffect], forbids: [].}
- Source Edit
proc get(key: string): napi_value {....raises: [NapiStatusError, KeyError, ValueError], tags: [], forbids: [].}
- Alias of getProperty for accessing global properties. This proc supports dot annotations: get("JSON.parse") Source Edit
proc get(key: string; default: napi_value): napi_value {. ...raises: [NapiStatusError], tags: [], forbids: [].}
- Alias for getProperty with default support Source Edit
proc get(obj: napi_value; key: string): napi_value {. ...raises: [KeyError, ValueError, NapiStatusError], tags: [], forbids: [].}
- Alias of getProperty for accessing a property from a specific object Source Edit
proc getBool(n: napi_value): bool {....raises: [NapiStatusError], tags: [], forbids: [].}
- Return a bool value from n Source Edit
proc getBool(n: napi_value; default: bool): bool {....raises: [], tags: [], forbids: [].}
- Return a bool from n. Returns default on failure Source Edit
proc getElement(obj: napi_value; index: int): napi_value {. ...raises: [NapiStatusError, ValueError], tags: [], forbids: [].}
- Retrieves value from index in obj; raises exception if obj is not an array or index is out of bounds Source Edit
proc getElement(obj: napi_value; index: int; default: napi_value): napi_value {. ...raises: [], tags: [], forbids: [].}
- Source Edit
proc getGlobal(): napi_value {....raises: [NapiStatusError], tags: [], forbids: [].}
- Returns NodeJS global variable Source Edit
proc getInt32(n: napi_value): int32 {....raises: [NapiStatusError], tags: [], forbids: [].}
- Retrieves value from node; raises exception on failure Source Edit
proc getInt32(n: napi_value; default: int32): int32 {....raises: [], tags: [], forbids: [].}
- Retrieves value from node; returns default on failure Source Edit
proc getInt64(n: napi_value): int64 {....raises: [NapiStatusError], tags: [], forbids: [].}
- Retrieves value from node; raises exception on failure Source Edit
proc getInt64(n: napi_value; default: int64): int64 {....raises: [], tags: [], forbids: [].}
- Retrieves value from node; returns default on failure Source Edit
proc getNull(): napi_value {....raises: [NapiStatusError], tags: [], forbids: [].}
- Returns JavaScript null value Source Edit
proc getProperty(obj: napi_value; key: string): napi_value {. ...raises: [KeyError, ValueError, NapiStatusError], tags: [], forbids: [].}
- Retrieves property key from obj; Panics if obj is not an object Source Edit
proc getProperty(obj: napi_value; key: string; default: napi_value): napi_value {. ...raises: [], tags: [], forbids: [].}
- Retrieves property key from obj; returns default if obj is not an object or does not contain key Source Edit
proc getPropertyNames(obj: napi_value): napi_value {. ...raises: [ValueError, NapiStatusError], tags: [], forbids: [].}
- Checks whether or not obj has a property key; Panics if obj is not an object Source Edit
proc getPropertyNamesArr(obj: napi_value): seq[napi_value] {. ...raises: [ValueError, NapiStatusError], tags: [], forbids: [].}
- Checks whether or not obj has a property key; Panics if obj is not an object Source Edit
proc getPropertyNamesArrStr(obj: napi_value): seq[string] {. ...raises: [ValueError, NapiStatusError], tags: [], forbids: [].}
- Checks whether or not obj has a property key; Panics if obj is not an object Source Edit
proc getStr(n: napi_value): string {....raises: [NapiStatusError], tags: [], forbids: [].}
- Return a string from n Source Edit
proc getStr(n: napi_value; default: string; bufsize: int = 40): string {. ...raises: [], tags: [], forbids: [].}
- Retrieves utf8 encoded value from node; returns default on failure Maximum return string length is equal to bufsize Source Edit
proc getUndefined(): napi_value {....raises: [NapiStatusError], tags: [], forbids: [].}
- Returns JavaScript undefined value Source Edit
proc hasElement(obj: napi_value; index: int): bool {. ...raises: [NapiStatusError, ValueError], tags: [], forbids: [].}
- Checks whether element is contained in obj; raises exception if obj is not an array Source Edit
proc hasOwnProperty(obj: napi_value; key: string): bool {. ...raises: [ValueError, NapiStatusError], tags: [], forbids: [].}
- Checks whether or not obj has a property key; Panics if obj is not an object Source Edit
proc hasProperty(obj: napi_value; key: string): bool {. ...raises: [ValueError, NapiStatusError], tags: [], forbids: [].}
- Checks whether or not obj has a property key; Panics if obj is not an object Source Edit
proc isArray(obj: napi_value): bool {....raises: [NapiStatusError], tags: [], forbids: [].}
- Source Edit
proc kind(val: napi_value): NapiValueType {....raises: [NapiStatusError], tags: [], forbids: [].}
- Source Edit
proc len(arr: napi_value): int {....raises: [NapiStatusError, ValueError, KeyError], tags: [], forbids: [].}
- Source Edit
proc napiCall(fname: string; args: openArray[napi_value] = []): napi_value {. discardable, ...raises: [NapiStatusError, KeyError, ValueError], tags: [], forbids: [].}
- A short-hand procedure for calling global Napi functions by string. You can use dot annotation for accessing and calling from object properties. For example napiCall("JSON.parse", "{}") Source Edit
proc napiCreate[T](t: T): napi_value
- Create a new napi_value of T Source Edit
proc newNodeValue(val: napi_value; env: napi_env): Module {....raises: [], tags: [], forbids: [].}
- Used internally, disregard Source Edit
proc newPromiseData[T](jsData: T): ref PromiseData[T]
- Source Edit
proc register(obj: Module; name: string; cb: napi_callback; attr: NapiPropertyAttributes = napi_default) {. ...raises: [NapiStatusError], tags: [], forbids: [].}
- Register a new property field to obj Module. Source Edit
proc register[T: int | uint | string | napi_value](obj: Module; name: string; value: T; attr: NapiPropertyAttributes = napi_default)
- Adds field to exports object obj Source Edit
proc register[T: int | uint | string | napi_value](obj: Module; name: string; values: openArray[(string, T)]; attr: NapiPropertyAttributes = napi_default)
- Register a new property field to obj Module. Source Edit
proc register[T: int | uint | string | napi_value](obj: Module; name: string; values: openArray[T]; attr: NapiPropertyAttributes = napi_default)
- Adds field to exports object obj Source Edit
proc setElement(obj: napi_value; index: int; value: napi_value) {. ...raises: [NapiStatusError, ValueError], tags: [], forbids: [].}
- Sets value at index; raises exception if obj is not an array Source Edit
proc setProperty(obj: napi_value; key: string; value: napi_value) {. ...raises: [NapiStatusError, ValueError], tags: [], forbids: [].}
- Sets property key in obj to value; raises exception if obj is not an object Source Edit
proc throwError(env: napi_env; msg: string; code = ""; errorType: NapiErrorType = napiError; customError: napi_value = nil): NapiStatus {....raises: [], tags: [], forbids: [].}
- Source Edit
proc toBool(n: napi_value): napi_value {....raises: [NapiStatusError], tags: [], forbids: [].}
- Source Edit
proc toNumber(n: napi_value): napi_value {....raises: [NapiStatusError], tags: [], forbids: [].}
- Source Edit
proc toSeq(n: napi_value): seq[napi_value] {. ...raises: [NapiStatusError, ValueError, KeyError], tags: [], forbids: [].}
- Return unpacked Array object to seq[napi_value] Source Edit
proc toString(n: napi_value): napi_value {....raises: [NapiStatusError], tags: [], forbids: [].}
- Source Edit
proc tryGetJson(n: napi_value): JsonNode {....raises: [NapiStatusError, KeyError, ValueError, IOError, OSError, JsonParsingError], tags: [ReadIOEffect, WriteIOEffect], forbids: [].}
- Source Edit
proc undefined(): napi_value {....raises: [NapiStatusError], tags: [], forbids: [].}
- Returns an undefined napi_value Source Edit
Iterators
iterator items(n: napi_value): napi_value {. ...raises: [NapiStatusError, ValueError, KeyError], tags: [], forbids: [].}
- Source Edit
iterator pairs(n: napi_value): (string, napi_value) {. ...raises: [NapiStatusError, ValueError, KeyError], tags: [], forbids: [].}
- Yields every key and value Source Edit
Macros
macro `.`(val: napi_value; field: untyped): untyped
- Source Edit
macro `.()`(val: napi_value; field: untyped; args: varargs[typed]): untyped
- Source Edit
macro `.=`(val: napi_value; field: untyped; value: napi_value): untyped
- Source Edit
macro `.=`(val: napi_value; field: untyped; value: typed): untyped
- Source Edit
macro export_napi(fn: untyped; withModule: untyped = nil)
-
A fancy compile-time macro to export NAPI functions
proc hello(name: string): string {.export_napi.} = return %* args.get("name")
If you want use it within module than use withModule arg:
proc hello(name: string): string {.export_napi: false.} = return %* args.get("name")
Source Edit macro export_napi(vName, vType: untyped; vVal: typed)
-
A fancy compile-time macro to export object properties
var name {.export_napi.} = "Denim is Awesome!"
Source Edit macro toJsObject(x: typed): untyped
- An elegant way to convert Nim types to napi_value. Source Edit
Templates
template error(msg: string; code = ""; errorType: NapiErrorType = napiError; customError: napi_value = nil): untyped
- Throw an exception using napi_throw_error Source Edit
template getIdentStr(n: untyped): string
- Source Edit
template getInt(n: napi_value): int
- Return int value from n Source Edit
template getInt(n: napi_value; default: int): int
- Return int value from n. Returns default on failure Source Edit
template registerFn(exports: Module; paramCt: int; name: string; cushy: untyped): untyped {. dirty.}
- Register and export a function Source Edit
Exports
-
napi_env, napi_object, napi_deferred, napi_symbol, napi_ref, napi_external, NapiPropertyDescriptor, napi_callback, NApiTypedArrayType, napi_number, napi_finalize, NapiValueType, napi_bigint, napi_callback_info, napi_string, NapiPropertyAttributes, napi_function, napi_threadsafe_function_call_js, NapiStatus, NapiExtendedErrorInfo, napi_undefined, napi_null, NapiThreadSafeFunction, napi_value, napi_escapable_handle_scope, napi_handle_scope, napi_boolean, napi_set_property, napi_is_date, napi_get_and_clear_last_exception, napi_define_properties, napi_create_uint64, napi_unrwap, napi_create_range_error, napi_create_error, napi_typeof, napi_create_external_arraybuffer, napi_get_value_bool, napi_get_array_length, napi_strict_equals, napi_create_array_with_length, napi_coerce_to_number, napi_get_arraybuffer_info, napi_coerce_to_string, napi_get_version, napi_call_function, napi_get_value_double, napi_is_arraybuffer, napi_throw_type_error, napi_has_property, napi_get_value_int64, napi_get_null, napi_create_promise, napi_remove_wrap, napi_create_dataview, napi_is_typedarray, napi_throw_error, napi_is_exception_pending, napi_has_named_property, napi_has_own_property, napi_is_array, napi_create_typedarray, napi_throw, napi_delete_property, napi_get_date_value, napi_set_named_property, napi_create_object, napi_add_finalizer, napi_is_promise, napi_get_value_string_latin1, napi_get_boolean, napi_get_cb_info, napi_get_last_error_info, napi_wrap, napi_get_value_string_utf8, napi_is_error, napi_get_property, napi_is_dataview, napi_throw_range_error, napi_get_value_external, napi_get_typedarray_info, napi_create_symbol, napi_has_element, napi_get_undefined, napi_coerce_to_object, napi_get_global, napi_run_script, napi_get_property_names, napi_get_value_int32, napi_adjust_external_memory, napi_create_string_latin1, napi_create_int32, napi_create_string_utf8, napi_create_function, napi_coerce_to_bool, napi_get_prototype, napi_new_instance, napi_create_external, napi_resolve_deferred, napi_get_dataview_info, napi_create_array, napi_define_class, napi_get_value_uint32, napi_reject_deferred, napi_create_double, napi_delete_element, napi_set_element, napi_create_uint32, napi_create_date, napi_create_type_error, napi_get_new_target, napi_get_element, napi_get_named_property, napi_instanceof, napi_create_arraybuffer, napi_create_int64, napi_create_external_buffer, napi_async_execute_callback, NapiNodeVersion, napi_async_context, napi_async_destroy, napi_create_async_work, napi_async_init, napi_threadsafe_function, napi_get_buffer_info, napi_make_callback, napi_addon_register_func, napi_cancel_async_work, napi_get_node_version, napi_queue_async_work, napi_callback_scope, napi_is_buffer, napi_create_buffer, NapiModule, napi_delete_async_work, napi_module_register, napi_async_work, napi_create_buffer_copy, napi_fatal_error, napiModule, napi_async_complete_callback