Nominating Presidential Muppets
    Wondering what’s next for npm?Check out our public roadmap! »

    safeify
    TypeScript icon, indicating that this package has built-in type declarations

    5.0.5 • Public • Published

    Safeify

    npm NPM Version Build Status Coverage Status npm

    说明

    Safeify 可让 Node 应用安全的隔离执行非信任的用户自定义代码,了解详细

    安装

    npm install safeify -S

    使用

    import { Safeify } from "safeify";
     
    (async ()=>{
     
      // 创建 safeify 实例
      const safeVm = new Safeify({
        timeout: 3000,
        asyncTimeout: 60000
      });
     
      // 定义 context
      const context = {
        a: 1,
        b: 2,
        system: {
          add(a: number, b: number) {
            return (a + b) * 2;
          }
        }
      };
     
      // 执行动态代码
      const result= await safeVm.run(`return system.add(1,2)`, context);
      console.log('result', result);
     
      // 释放资源
      safeVm.destroy();
      
    })();

    Keywords

    none

    Install

    npm i safeify

    DownloadsWeekly Downloads

    4

    Version

    5.0.5

    License

    Apache License 2.0

    Unpacked Size

    76.6 kB

    Total Files

    62

    Last publish

    Collaborators

    • avatar