jsir 2.2.4 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deps/evalCode.js +2 -0
- package/deps/util.js +14 -5
- package/package.json +1 -1
package/deps/evalCode.js
CHANGED
|
@@ -22,6 +22,8 @@ module.exports = async ($text = '', $cmdName = '', $args = [],
|
|
|
22
22
|
$currentSpace, $homeDir, $lib, $cmdMap
|
|
23
23
|
}
|
|
24
24
|
let console = $lib.createConsole($cmdName);
|
|
25
|
+
// 兼容module.exports
|
|
26
|
+
$text = $text.replace(/^module\.exports\s*=\s*/m, 'return ')
|
|
25
27
|
return await eval(`(async ()=>{${$text};
|
|
26
28
|
})()`)
|
|
27
29
|
}
|
package/deps/util.js
CHANGED
|
@@ -498,7 +498,7 @@ function timeStr(fmt, date) {
|
|
|
498
498
|
function vl(obj) {
|
|
499
499
|
let type= typeof obj;
|
|
500
500
|
if (type === 'number') {
|
|
501
|
-
return !Number.isNaN(obj)
|
|
501
|
+
return !Number.isNaN(obj);
|
|
502
502
|
}
|
|
503
503
|
if (typeof obj === 'string') {
|
|
504
504
|
obj = obj.trim()
|
|
@@ -763,8 +763,8 @@ function requireG(moduleName){
|
|
|
763
763
|
} catch (e) {}
|
|
764
764
|
let path = moduleDir + '/' + moduleName;
|
|
765
765
|
if (!fs.existsSync(path)) {
|
|
766
|
-
console.log(warnStr(
|
|
767
|
-
throw `${moduleName} not found, use
|
|
766
|
+
console.log(warnStr(`npm install ${moduleName}`))
|
|
767
|
+
throw `${moduleName} not found, use npm install to add it`;
|
|
768
768
|
}
|
|
769
769
|
return require(path);
|
|
770
770
|
}
|
|
@@ -784,8 +784,8 @@ async function importG(moduleName) {
|
|
|
784
784
|
} catch (e) {}
|
|
785
785
|
let path = moduleDir + '/' + moduleName;
|
|
786
786
|
if (!fs.existsSync(path)) {
|
|
787
|
-
console.log(warnStr(
|
|
788
|
-
throw `${moduleName} not found, use
|
|
787
|
+
console.log(warnStr(`npm install ${moduleName}`))
|
|
788
|
+
throw `${moduleName} not found, use npm install to add it`;
|
|
789
789
|
}
|
|
790
790
|
return await import(require.resolve(path));
|
|
791
791
|
}
|
|
@@ -918,11 +918,20 @@ function toBigNum(str) {
|
|
|
918
918
|
}
|
|
919
919
|
|
|
920
920
|
function reget(str, reg) {
|
|
921
|
+
`
|
|
922
|
+
reget(str, /aaa(bbb)ccc/)
|
|
923
|
+
return bbb
|
|
924
|
+
`
|
|
921
925
|
let r = reg.exec(str)
|
|
922
926
|
return r ? (r[1] || "").trim(): ""
|
|
923
927
|
}
|
|
924
928
|
|
|
925
929
|
function regEach(str, reg, fn) {
|
|
930
|
+
`
|
|
931
|
+
regEach(str, /aaa(bbb)ccc/, fn)
|
|
932
|
+
fn([aaa(bbb)ccc, bbb])
|
|
933
|
+
return void
|
|
934
|
+
`
|
|
926
935
|
let r = reg.exec(str)
|
|
927
936
|
while (r != null) {
|
|
928
937
|
fn(r)
|