Extension Modules
Optional modules compiled into libemjs-exts.a. Must be explicitly bound at runtime (the CLI binds them automatically).
CMake options
| Option | Module |
|---|---|
BUILD_CONSOLE | console.* |
BUILD_GLOBAL | global.* (parseInt, parseFloat) |
BUILD_STRING | string.* (String.fromCharCode) |
BUILD_DATE | date.* |
BUILD_JSON | json.* |
BUILD_MATH | math.* |
Runtime binding
#include "extension/console.h"
#include "extension/global.h"
#include "extension/string.h"
#include "extension/date.h"
#include "extension/math.h"
#include "extension/json.h"
EConsole::bind(js);
EGlobal::bind(js);
EString::bind(js);
EDate::bind(js);
EMath::bind(js);
EJson::bind(js);
console
console.log(...args)console.time(label?)console.timeLog(label, ...args)console.timeEnd(label?)
global
parseInt(str[, radix])parseFloat(str)
String (global object)
String.fromCharCode(...codes)
Date
Date.now()Date.format([timestampMs][, format])
Default format: %Y-%m-%d %H:%i:%s
Math
Constants: E, LN10, LN2, LOG10E, LOG2E, PI, SQRT1_2, SQRT2
Functions: abs acos acosh asin asinh atan atan2 atanh cbrt ceil clz32 cos cosh exp expm1 f16round floor fround hypot imul log log10 log1p log2 max min pow random round sign sin sinh sqrt sumPrecise tan tanh trunc
JSON
let o = JSON.parse('{"a":1,"b":[2,3]}');
JSON.stringify(o); // {"a":1,"b":[2,3]}
Core array/string methods work without extensions — see JavaScript Features.