From 2848ab60f54af09abee64d541677358a5445c4eb Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 14 Apr 2021 21:17:28 -0400 Subject: =?UTF-8?q?Validate=20=E2=80=A2BQN=20arguments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/bqn.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/bqn.js b/docs/bqn.js index bce0fb0a..007e22a1 100755 --- a/docs/bqn.js +++ b/docs/bqn.js @@ -311,11 +311,14 @@ let fmtErr = (s,e) => { return [w].concat(loc).join('\n'); } +let isstr = x => x.sh && x.sh.length==1 && x.every(c=>typeof c==="string"); let unixtime = (x,w) => Date.now()/1000; +let req1str = (e,x,w) => { + if (!isstr(x)) throw Error(e+" 𝕩: 𝕩 must be a string"); + if (has(w)) throw Error(e+": 𝕨 not allowed"); +} let dojs = (x,w) => { - if (!(x.sh && x.sh.length==1 && x.every(c=>typeof c==="string"))) - throw Error("•JS 𝕩: 𝕩 must be a string"); - if (has(w)) throw Error("•JS: 𝕨 not allowed"); + req1str("•JS",x,w); let r = Function("'use strict'; return ("+x.join("")+")")(); let toBQN = x => { if (isnum(x)) return x; @@ -327,7 +330,8 @@ let dojs = (x,w) => { return toBQN(r); } let sysvals = { - bqn, js:dojs, type, glyph, decompose, fmt:fmt1, unixtime, + bqn:(x,w)=>{req1str("•BQN",x,w);return bqn(x);}, js:dojs, + type, glyph, decompose, fmt:fmt1, unixtime, listsys: () => list(Object.keys(sysvals).map(str).sort()) }; sysvals.listsys.dynamic = 1; -- cgit v1.2.3