Skip to content

Commit ae1671e

Browse files
committed
feat(js): jsutils/consts from_js_const
1 parent 1d5e2a8 commit ae1671e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/pylib/jsutils/consts.nim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
const
3+
InNodeJs = defined(nodejs)
4+
import std/jsffi
5+
when InNodeJs:
6+
let econsts = require("constants")
7+
else:
8+
let econsts{.importjs: """(await import("node:constants")).errno""".}: JsObject
9+
10+
template from_js_const*(name; defval: int): int =
11+
bind econsts, isUndefined, to, `[]`
12+
let n = econsts[astToStr(name)]
13+
if n.isUndefined: defVal else: n.to(int)

0 commit comments

Comments
 (0)