src/nodejs/jsutils

    Dark Mode
Search:
Group by:

  • Core, primitives, basic proc, string basics, for JavaScript.

Example:

import src/nodejs/jsutils
import sugar  # =>
doAssert base64encode("Como siempre: lo urgente no deja tiempo para lo importante".cstring) == "Q29tbyBzaWVtcHJlOiBsbyB1cmdlbnRlIG5vIGRlamEgdGllbXBvIHBhcmEgbG8gaW1wb3J0YW50ZQ==".cstring
doAssert base64decode("Q29tbyBzaWVtcHJlOiBsbyB1cmdlbnRlIG5vIGRlamEgdGllbXBvIHBhcmEgbG8gaW1wb3J0YW50ZQ==".cstring) == "Como siempre: lo urgente no deja tiempo para lo importante".cstring
doAssert deduplicate([9, 1, 2, 3, 4, 9, 9, 9, 0]) == @[9, 1, 2, 3, 4, 0]
doAssert deduplicate(@[9, 9, 9, 9]) == @[9]

for okis in ["y".cstring, "Y", "1",  "ON", "On", "oN", "on", "yes", "YES",
    "YEs", "YeS", "Yes", "yES", "yEs", "yeS", "TRUE", "TRUe", "TRuE", "TRue",
    "TrUE", "TrUe", "TruE", "True", "tRUE", "tRUe", "tRuE", "tRue", "trUE",
    "trUe", "truE", "true"]:
    doAssert parseBool(okis)

for nope in ["n".cstring, "N", "0", "NO", "No", "nO", "no", "OFF", "OFf",
  "OfF", "Off", "oFF", "oFf", "ofF", "off", "FALSE", "FALSe", "FALsE",
  "FALse", "FAlSE", "FAlSe", "FAlsE", "FAlse", "FaLSE", "FaLSe", "FaLsE",
  "FaLse", "FalSE", "FalSe", "FalsE", "False", "fALSE", "fALSe", "fALsE",
  "fALse", "fAlSE", "fAlSe", "fAlsE", "fAlse", "faLSE", "faLSe", "faLsE",
  "faLse", "falSE", "falSe", "falsE", "false"]:
  doAssert not parseBool(nope)

let exampl = "hello"
doAssert exampl[0] == 'h'
doAssert exampl[0 .. 3] == "hell".cstring
doAssert exampl[0 .. ^2] == "hell".cstring

Example: cmd: -r:off

import src/nodejs/jsutils
requireUtil()
block:
  doAssert cstring"%s:%s".format("example".cstring) == "example:%s".cstring
  doAssert getSystemErrorName(-1.cint) == "EPERM".cstring
  inspect("nim".cstring)
  proc foo() = echo 42
  discard callbackify(foo)
  discard deprecate(foo)
  doAssert isDeepStrictEqual(42.cint, 42.cint)
block:
  let enco: TextEncoder = newTextEncoder()
  doAssert enco.encoding == "utf-8".cstring
  doAssert enco.encode(input = "example".cstring) == @[101.uint8, 120, 97, 109, 112, 108, 101]
  var buffe: Uint8Array = newUint8Array(9.Natural)
  enco.encodeInto(src = "example".cstring, dest = buffe) ## encodeInto is {.discardable.} for convenience.
  doAssert buffe.toCstring is cstring
  doAssert $buffe == """{"0":101,"1":120,"2":97,"3":109,"4":112,"5":108,"6":101,"7":0,"8":0}"""
  let deco: TextDecoder = newTextDecoder(encoding = "utf-8".cstring, fatal = false, ignoreBOM = false)
  doAssert deco.encoding == "utf-8".cstring
  doAssert not(deco.fatal)
  doAssert not(deco.ignoreBOM)
  let data: ArrayBuffer = newArrayBuffer(9.Natural)
  doAssert deco.decode(input = data) is cstring
block:
  doAssert not isAnyArrayBuffer(false)
  doAssert not isArrayBufferView(false)
  doAssert not isArgumentsObject(false)
  doAssert not isArrayBuffer(false)
  doAssert not isBigInt64Array(false)
  doAssert not isBigUint64Array(false)
  doAssert not isBooleanObject(false)
  doAssert not isBoxedPrimitive(false)
  doAssert not isDataView(false)
  doAssert not isDate(false)
  doAssert not isExternal(false)
  doAssert not isFloat32Array(false)
  doAssert not isFloat64Array(false)
  doAssert not isGeneratorFunction(false)
  doAssert not isBigInt64Array(false)
  doAssert not isGeneratorObject(false)
  doAssert not isInt8Array(false)
  doAssert not isInt16Array(false)
  doAssert not isInt32Array(false)
  doAssert not isMap(false)
  doAssert not isMapIterator(false)
  doAssert not isModuleNamespaceObject(false)
  doAssert not isNativeError(false)
  doAssert not isNumberObject(false)
  doAssert not isPromise(false)
  doAssert not isProxy(false)
  doAssert not isRegExp(false)
  doAssert not isSet(false)
  doAssert not isSetIterator(false)
  doAssert not isSharedArrayBuffer(false)
  doAssert not isStringObject("string".cstring)
  doAssert not isSymbolObject(false)
  doAssert not isTypedArray(false)
  doAssert not isUint8Array(false)
  doAssert not isUint8ClampedArray(false)
  doAssert not isUint16Array(false)
  doAssert not isUint32Array(false)
  doAssert not isWeakMap(false)
  doAssert not isWeakSet(false)
  doAssert not isWebAssemblyCompiledModule(false)
  doAssert isBoolean(false)
  doAssert not isBuffer(false)
  doAssert not isFunction(false)
  doAssert not isNumber(false)
  doAssert isString("string".cstring)
  doAssert not isSymbol(false)

Types

ArrayBuffer = ref object of JsRoot
  byteLength*: cint
TextDecoder = ref object of JsRoot
  encoding*: cstring         ## https://nodejs.org/api/util.html#util_textdecoder_encoding
  fatal*: bool               ## https://nodejs.org/api/util.html#util_textdecoder_fatal
  ignoreBOM*: bool           ## https://nodejs.org/api/util.html#util_textdecoder_ignorebom
  
https://nodejs.org/api/util.html#util_class_util_textdecoder
TextEncoder = ref object of JsRoot
  encoding*: cstring         ## https://nodejs.org/api/util.html#util_textencoder_encoding
  
https://nodejs.org/api/util.html#util_class_util_textencoder
Uint8Array = ref object of JsRoot
  BYTES_PER_ELEMENT*: cint

Procs

func `$`(self: Uint8Array or ArrayBuffer): string
func `&`(a, b: cstring): cstring {.importjs: "(# + #)", ...raises: [], tags: [].}
func `&`(a: char; b: cstring): cstring {.
    importjs: "(String.fromCharCode(#) + #)", ...raises: [], tags: [].}
func `&`(a: cstring; b: char): cstring {.
    importjs: "(# + String.fromCharCode(#))", ...raises: [], tags: [].}
func `&&=`(lhs, rhs: auto): any {.importjs: "(# &&= #)", discardable,
                                  ...raises: [], tags: [].}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment
func `??=`(lhs, rhs: auto): any {.importjs: "(# ??= #)", discardable,
                                  ...raises: [], tags: [].}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_nullish_assignment
proc `[]`(s: cstring; slice: HSlice[SomeInteger, BackwardsIndex]): cstring {.
    asmNoStackFrame.}
proc `[]`(s: cstring; slice: HSlice[SomeInteger, SomeInteger]): cstring {.
    asmNoStackFrame.}
func `[]`(self: Uint8Array or ArrayBuffer; index: Natural): uint8 {.
    importjs: "#[#]", ...raises: [], tags: [].}
func `[]=`(self: Uint8Array or ArrayBuffer; index: Natural; value: uint8) {.
    importjs: "#[#] = #", ...raises: [], tags: [].}
func base64decode(strng: cstring; encoding = "utf-8".cstring): cstring {.
    importjs: "Buffer.from(#, \'base64\').toString(#)", ...raises: [], tags: [].}
Convenience func to Base64 decode a string.
func base64encode(strng: cstring; encoding = "utf-8".cstring): cstring {.
    importjs: "Buffer.from(#, #).toString(\'base64\')", ...raises: [], tags: [].}
Convenience func to Base64 encode a string.
proc callbackify[T](function: T): T {.importjs: "util.$1(#)", ...raises: [],
                                      tags: [].}
https://nodejs.org/api/util.html#util_util_callbackify_original
func capitalizeAscii(s: cstring): cstring {.importjs: """  (() => { const s = #; return s.charAt(0).toUpperCase() + s.slice(1) })()""",
    ...raises: [], tags: [].}
func contains(a, b: cstring): bool {.importjs: "(#.indexOf(#) >= 0)",
                                     ...raises: [], tags: [].}
func contains(a: cstring; b: char): bool {.
    importjs: "(#.indexOf(String.fromCharCode(#)) >= 0)", ...raises: [], tags: [].}
func decode(self: TextDecoder; input: ArrayBuffer): cstring {.importcpp,
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_textdecoder_decode_input_options
func deduplicate[T](arrai: openArray[T]): seq[T] {.importjs: "[...new Set(#)]",
    ...raises: [], tags: [].}
Convenience func to Deduplicate an array.
func deprecate[T](function: T): T {.importjs: "util.$1(#, \'\')", ...raises: [],
                                    tags: [].}
https://nodejs.org/api/util.html#util_util_deprecate_fn_msg_code
func deprecate[T](function: T; msg, code: cstring): T {.
    importjs: "util.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_deprecate_fn_msg_code
func deprecate[T](function: T; msg: cstring): T {.importjs: "util.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_deprecate_fn_msg_code
func encode(self: TextEncoder; input: cstring): seq[uint8] {.importcpp,
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_textencoder_encode_input
func encodeInto(self: TextEncoder; src: cstring; dest: Uint8Array): JsObject {.
    importcpp, discardable, ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_textencoder_encodeinto_src_dest
func find(s: cstring; ss: char): int {.importjs: "#.indexOf(String.fromCharCode(#))",
                                       ...raises: [], tags: [].}
func find(s: cstring; ss: cstring): int {.importjs: "#.indexOf(#)", ...raises: [],
    tags: [].}
func find(strng: cstring; regex: RegExp): cint {.importjs: "#.search(#)",
    ...raises: [], tags: [].}
func format(format: cstring; args: cstring): cstring {.
    importjs: "util.$1(#, @)", varargs, ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_format_format_args
func getSystemErrorName(err: cint): cstring {.importjs: "util.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_getsystemerrorname_err
func importUtil() {.importjs: "import * as util from \'util\'@", ...raises: [],
                    tags: [].}
Alias for import * as module_name from 'module_name';. Must be called once before using the module
func indentation(s: cstring): cint {.importjs: """  (() => {
    const m = #.match(/^[\s\\t]*/gm);
    let result = m[0].length;
    for (var i = 1; i < m.length; i++) { result = Math.min(m[i].length, result) }
    return result;
  })()""",
                                     ...raises: [], tags: [].}
Returns the amount of indentation all lines of s have in common, ignoring lines that consist only of whitespace.
func inherits[T](constructor, superConstructor: T) {.importjs: "util.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor
func inspect(objec: auto; showHidden = false; depth = 2.cint; colors = false) {.
    importjs: "util.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors
func isAnyArrayBuffer(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isanyarraybuffer_value
func isArgumentsObject(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isargumentsobject_value
func isArrayBuffer(value: auto): bool {.importjs: "util.types.$1(#)",
                                        ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isarraybuffer_value
func isArrayBufferView(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isarraybufferview_value
func isAsyncFunction(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isasyncfunction_value
func isBigInt64Array(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isbigint64array_value
func isBigUint64Array(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isbiguint64array_value
func isBoolean(value: auto): bool {.importjs: "(typeof # === \'boolean\')",
                                    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_isboolean_object
func isBooleanObject(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isbooleanobject_value
func isBoxedPrimitive(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isboxedprimitive_value
func isBuffer(value: auto): bool {.importjs: "Buffer.isBuffer(#)", ...raises: [],
                                   tags: [].}
https://nodejs.org/api/util.html#util_util_isbuffer_object
func isDataView(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                     tags: [].}
https://nodejs.org/api/util.html#util_util_types_isdataview_value
func isDate(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                 tags: [].}
https://nodejs.org/api/util.html#util_util_types_isdate_value
func isDeepStrictEqual(val1, val2: auto): bool {.importjs: "util.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_isdeepstrictequal_val1_val2
func isDigit(c: char): bool {.importjs: "(() => { const c = #; return (c >= \'0\' && c <= \'9\') })()",
                              ...raises: [], tags: [].}
func isExternal(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                     tags: [].}
https://nodejs.org/api/util.html#util_util_types_isexternal_value
func isFinite(n: SomeNumber): bool {.importjs: "Number.$1(#)", ...raises: [],
                                     tags: [].}
func isFloat32Array(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isfloat32array_value
func isFloat64Array(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isfloat64array_value
func isFunction(value: auto): bool {.importjs: "(typeof # === \'function\')",
                                     ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_isfunction_object
func isGeneratorFunction(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isgeneratorfunction_value
func isGeneratorObject(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isgeneratorobject_value
func isInt8Array(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                      tags: [].}
https://nodejs.org/api/util.html#util_util_types_isint8array_value
func isInt16Array(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                       tags: [].}
https://nodejs.org/api/util.html#util_util_types_isint16array_value
func isInt32Array(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                       tags: [].}
https://nodejs.org/api/util.html#util_util_types_isint32array_value
func isInteger(n: SomeNumber): bool {.importjs: "Number.$1(#)", ...raises: [],
                                      tags: [].}
func isMap(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                tags: [].}
https://nodejs.org/api/util.html#util_util_types_ismap_value
func isMapIterator(value: auto): bool {.importjs: "util.types.$1(#)",
                                        ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_ismapiterator_value
func isModuleNamespaceObject(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_ismodulenamespaceobject_value
func isNativeError(value: auto): bool {.importjs: "util.types.$1(#)",
                                        ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isnativeerror_value
func isNumber(value: auto): bool {.importjs: "(typeof # === \'number\')",
                                   ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_isnumber_object
func isNumberObject(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isnumberobject_value
func isPromise(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                    tags: [].}
https://nodejs.org/api/util.html#util_util_types_ispromise_value
func isProxy(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                  tags: [].}
https://nodejs.org/api/util.html#util_util_types_isproxy_value
func isRegExp(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                   tags: [].}
https://nodejs.org/api/util.html#util_util_types_isregexp_value
func isSafeInteger(n: SomeNumber): bool {.importjs: "Number.$1(#)", ...raises: [],
    tags: [].}
func isSet(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                tags: [].}
https://nodejs.org/api/util.html#util_util_types_isset_value
func isSetIterator(value: auto): bool {.importjs: "util.types.$1(#)",
                                        ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_issetiterator_value
func isSharedArrayBuffer(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_issharedarraybuffer_value
func isString(value: auto): bool {.importjs: "(typeof # === \'string\')",
                                   ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_isstring_object
func isStringObject(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isstringobject_value
func isSymbol(value: auto): bool {.importjs: "(typeof # === \'symbol\')",
                                   ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_issymbol_object
func isSymbolObject(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_issymbolobject_value
func isTypedArray(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                       tags: [].}
https://nodejs.org/api/util.html#util_util_types_istypedarray_value
func isUint8Array(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                       tags: [].}
https://nodejs.org/api/util.html#util_util_types_isuint8array_value
func isUint8ClampedArray(value: auto): bool {.importjs: "util.types.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isuint8clampedarray_value
func isUint16Array(value: auto): bool {.importjs: "util.types.$1(#)",
                                        ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isuint16array_value
func isUint32Array(value: auto): bool {.importjs: "util.types.$1(#)",
                                        ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_isuint32array_value
func isWeakMap(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                    tags: [].}
https://nodejs.org/api/util.html#util_util_types_isweakmap_value
func isWeakSet(value: auto): bool {.importjs: "util.types.$1(#)", ...raises: [],
                                    tags: [].}
https://nodejs.org/api/util.html#util_util_types_isweakset_value
func isWebAssemblyCompiledModule(value: auto): bool {.
    importjs: "(# instanceof WebAssembly.Module)", ...raises: [], tags: [].}
https://nodejs.org/api/util.html#util_util_types_iswebassemblycompiledmodule_value
func len(self: Uint8Array): int {.importjs: "(#.length)", ...raises: [], tags: [].}
func match(strng: cstring; regex: RegExp): seq[cstring] {.
    importjs: "#.match(#)", ...raises: [], tags: [].}
func matchAll(strng: cstring; regex: RegExp): seq[cstring] {.
    importjs: "Array.from(#.matchAll(#))", ...raises: [], tags: [].}
func newArrayBuffer(number: Natural): ArrayBuffer {.
    importjs: "new ArrayBuffer(#)", ...raises: [], tags: [].}
func newTextDecoder(encoding = "utf-8".cstring; fatal = false; ignoreBOM = false): TextDecoder {.
    importjs: "(new util.TextDecoder(#, {fatal: #, ignoreBOM: #}))", ...raises: [],
    tags: [].}
func newTextEncoder(): TextEncoder {.importjs: "(new util.TextEncoder(@))",
                                     ...raises: [], tags: [].}
func newUint8Array(number: Natural): Uint8Array {.importjs: "new Uint8Array(#)",
    ...raises: [], tags: [].}
func normalize(strng: cstring; form = "NFC".cstring): cstring {.
    importjs: "#.normalize(#)", ...raises: [], tags: [].}
func parseBool(s: cstring): bool {.asmNoStackFrame, ...raises: [], tags: [].}
Convenience func mimics Nim parseBool but optimized for NodeJS. Does NOT ignore '_', if you need to ignore '_' use stdlib or remove the '_'. The reason is that it is more strict than stdlib, because does not allow '_', is not the same as stdlib one.
proc parseFloat(s: cstring): BiggestFloat {.importjs: "parseFloat(#)",
    ...raises: [], tags: [].}
proc parseInt(s: char): cint {.importjs: "parseInt(String.fromCharCode(#), 10)",
                               ...raises: [], tags: [].}
proc parseInt(s: cstring): cint {.importjs: "parseInt(#, 10)", ...raises: [],
                                  tags: [].}
proc parseUInt(s: char): uint {.importjs: "parseInt(String.fromCharCode(#), 10)",
                                ...raises: [], tags: [].}
proc parseUInt(s: cstring): uint {.importjs: "parseInt(#, 10)", ...raises: [],
                                   tags: [].}
func repeat(s: cstring; n: Natural): cstring {.importjs: "#.repeat(#)",
    ...raises: [], tags: [].}
func replace(s, sub: cstring; by = "".cstring): cstring {.
    importjs: "#.replace(#, #)", ...raises: [], tags: [].}
func replace(s: cstring; sub: char; by = "".cstring): cstring {.
    importjs: "#.replace(String.fromCharCode(#), #)", ...raises: [], tags: [].}
func replace(s: cstring; sub: char; by: char): cstring {.
    importjs: "#.replace(String.fromCharCode(#), String.fromCharCode(#))",
    ...raises: [], tags: [].}
func replace(strng: cstring; regex: RegExp; by = "".cstring): cstring {.
    importjs: "#.replace(#, #)", ...raises: [], tags: [].}
func replaceAll(strng: cstring; regex: RegExp; by = "".cstring): cstring {.
    importjs: "#.replaceAll(#, #)", ...raises: [], tags: [].}
func requireUtil() {.importjs: "const util = require(\'util\')@", ...raises: [],
                     tags: [].}
Alias for const module_name = require('module_name');. Must be called once before using the module
func shuffle(arrai: openArray[auto]): seq[auto] {.
    importjs: "#.sort(() => { return Math.random() - 0.5})", ...raises: [],
    tags: [].}
Convenience func to Random shuffle an array.
func slice(s: cstring; start: cint; ends: cint): cstring {.
    importjs: "#.slice(#, #)", ...raises: [], tags: [].}
func split(a: cstring; b: char): seq[cstring] {.
    importjs: "#.split(String.fromCharCode(#))", ...raises: [], tags: [].}
func split(a: cstring; b: cstring): seq[cstring] {.importjs: "#.split(#)",
    ...raises: [], tags: [].}
func split(strng: cstring; regex: RegExp): seq[cstring] {.
    importjs: "#.split(#)", ...raises: [], tags: [].}
func strip(s: cstring): cstring {.importjs: "#.trim()", ...raises: [], tags: [].}
func strip(s: cstring; leading: bool; trailing: bool): cstring {.importjs: """  (() => {
    let result = #;
    if (#) { result = result.trimStart() }
    if (#) { result = result.trimEnd()   }
    return result;
  })()""",
    ...raises: [], tags: [].}
func structuredClone(value, transfer: auto) {.importjs: "$1(#, #)", ...raises: [],
    tags: [].}
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
func structuredClone(value: auto) {.importjs: "$1(#)", ...raises: [], tags: [].}
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
func toArray(self: ArrayBuffer): seq[int] {.
    importjs: "Array.from(new Uint8Array(#))", ...raises: [], tags: [].}
func toArray(self: Uint8Array): seq[uint8] {.importjs: "Array.from(#)",
    ...raises: [], tags: [].}
func toCstring(self: Uint8Array or ArrayBuffer): cstring {.
    importjs: "JSON.stringify(#)", ...raises: [], tags: [].}
func toExponential(n: SomeFloat; fractionDigits: Positive): cstring {.
    importjs: "#.$1(#)", ...raises: [], tags: [].}
func toFixed(n: SomeFloat; digits: 0 .. 20): cstring {.importjs: "#.$1(#)",
    ...raises: [], tags: [].}
func toLowerAscii(c: char): cstring {.importjs: "String.fromCharCode(#).toLowerCase()",
                                      ...raises: [], tags: [].}
func toLowerAscii(s: cstring): cstring {.importjs: "#.toLowerCase()",
    ...raises: [], tags: [].}
func toPrecision(n: SomeFloat; fractionDigits: Positive): cstring {.
    importjs: "#.$1(#)", ...raises: [], tags: [].}
func toUpperAscii(c: char): cstring {.importjs: "String.fromCharCode(#).toUpperCase()",
                                      ...raises: [], tags: [].}
func toUpperAscii(s: cstring): cstring {.importjs: "#.toUpperCase()",
    ...raises: [], tags: [].}
func `||=`(lhs, rhs: auto): any {.importjs: "(# ||= #)", discardable,
                                  ...raises: [], tags: [].}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment