• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1{
2  "Napi double in": {
3    "prefix": "napidoublein",
4    "body": [
5      "double value0 = 0;",
6      "// Convert a JS number type value to a C double type.",
7      "napi_get_value_double(env, args[0], &value0);"
8    ]
9  },
10  "Napi int32_t in": {
11    "prefix": "napiint32in",
12    "body": [
13      "int32_t value0 = 0;",
14      "// Convert a JS number type value to a C int32_t type.",
15      "napi_get_value_int32(env, args[0], &value0);"
16    ]
17  },
18  "Napi uint32_t in": {
19    "prefix": "napiuint32in",
20    "body": [
21      "uint32_t value0 = 0;",
22      "// Convert a JS number type value to a C uint32_t type.",
23      "napi_get_value_uint32(env, args[0], &value0);"
24    ]
25  },
26  "Napi int64_t in": {
27    "prefix": "napiint64in",
28    "body": [
29      "int64_t value0 = 0;",
30      "// Convert a JS number type value to a C int64_t type.",
31      "napi_get_value_int64(env, args[0], &value0);"
32    ]
33  },
34  "Napi bool in": {
35    "prefix": "napiboolin",
36    "body": [
37      "bool value0 = false;",
38      "// Convert a JS boolean type value to a C bool type.",
39      "napi_get_value_bool(env, args[0], &value0);"
40    ]
41  },
42  "Napi string utf8 in": {
43    "prefix": "napistringutf8in",
44    "body": [
45      "size_t strUtf8Length = 0;",
46      "// Get the length of the js string.",
47      "napi_get_value_string_utf8(env, args[0], NULL, 0, &strUtf8Length);",
48      "char *value0 = new char[strUtf8Length + 1];",
49      "// Get the js string as a UTF-8 encoded C string.",
50      "napi_get_value_string_utf8(env, args[0], value0, strUtf8Length + 1, &strUtf8Length);",
51      "// Todo: Assign value0 to actual business value",
52      "delete[] value0;"
53    ]
54  },
55  "Napi string utf16 in": {
56    "prefix": "napistringutf16in",
57    "body": [
58      "size_t strUtf16Length = 0;",
59      "// Get the length of the js string.",
60      "napi_get_value_string_utf16(env, args[0], NULL, 0, &strUtf16Length);",
61      "char16_t *value0 = new char16_t[strUtf16Length + 1];",
62      "// Get the js string as a UTF-16 encoded C string.",
63      "napi_get_value_string_utf16(env, args[0], value0, strUtf16Length + 1, &strUtf16Length);",
64      "// Todo: Assign value0 to actual business value",
65      "delete[] value0;"
66    ]
67  },
68  "Napi is array": {
69    "prefix": "napiisarray",
70    "body": [
71      "bool isArray = false;",
72      "// Check if the provided napi_value is a JavaScript array.",
73      "napi_is_array(env, args[0], &isArray);"
74    ]
75  },
76  "Napi array in": {
77    "prefix": "napiarrayin",
78    "body": [
79      "uint32_t length = 0;",
80      "// Retrieve the length of a JavaScript array.",
81      "napi_get_array_length(env, args[0], &length);",
82      "for (uint32_t i = 0; i < length; i++) {",
83      "    napi_value element;",
84      "    // Get an element from a JavaScript array by index.",
85      "    napi_get_element(env, args[0], i, &element);",
86      "}"
87    ]
88  },
89  "Napi array out": {
90    "prefix": "napiarrayout",
91    "body": [
92      "napi_value resultArray;",
93      "size_t length = 3;",
94      "// Create a new JavaScript array with a specified length.",
95      "napi_create_array_with_length(env, length, &resultArray);",
96      "for (uint32_t i = 0; i < length; i++) {",
97      "    napi_value element;",
98      "    napi_create_int32(env, i, &element);",
99      "    // Set an element to a JavaScript array by index.",
100      "    napi_set_element(env, resultArray, i, element);",
101      "}"
102    ]
103  },
104  "Napi double out": {
105    "preix": "napidoubleout",
106    "body": [
107      "double doubleRes = 0;",
108      "napi_value doubleOut;",
109      "// Convert a C double type to a JavaScript number type.",
110      "napi_create_double(env, doubleRes, &doubleOut);"
111    ]
112  },
113  "Napi int32_t out": {
114    "prefix": "napiint32out",
115    "body": [
116      "int32_t int32Res = 0;",
117      "napi_value int32Out;",
118      "// Convert a C int32_t type to a JavaScript number type.",
119      "napi_create_int32(env, int32Res, &int32Out);"
120    ]
121  },
122  "Napi uint32_t out": {
123    "prefix": "napiuint32out",
124    "body": [
125      "uint32_t uint32Res = 0;",
126      "napi_value uint32Out;",
127      "// Convert a C uint32_t type to a JavaScript number type.",
128      "napi_create_uint32(env, uint32Res, &uint32Out);"
129    ]
130  },
131  "Napi int64_t out": {
132    "prefix": "napiint64out",
133    "body": [
134      "int64_t int64Res = 0;",
135      "napi_value int64Out;",
136      "// Convert a C int64_t type to a JavaScript number type.",
137      "napi_create_int64(env, int64Res, &int64Out);"
138    ]
139  },
140  "Napi bool out": {
141    "prefix": "napiboolout",
142    "body": [
143      "bool boolRes = false;",
144      "napi_value boolOut;",
145      "// Convert a C bool type to a JavaScript boolean type.",
146      "napi_get_boolean(env, boolRes, &boolOut);"
147    ]
148  },
149  "Napi string utf8 out": {
150    "prefix": "napistringutf8out",
151    "body": [
152      "const char* stringRes = \"hello world!\";",
153      "napi_value stringOut;",
154      "// Convert a C string uft8 type to a JavaScript string type",
155      "napi_create_string_utf8(env, stringRes, NAPI_AUTO_LENGTH, &stringOut);"
156    ]
157  },
158  "Napi string utf16 out": {
159    "prefix": "napistringutf16out",
160    "body": [
161      "const char16_t* stringRes = u\"hello world!\";",
162      "napi_value stringOut;",
163      "// Convert a C string uft16 type to a JavaScript string type",
164      "napi_create_string_utf16(env, stringRes, NAPI_AUTO_LENGTH, &stringOut);"
165    ]
166  }
167}