How to use eval - 8 common examples

To help you get started, we’ve selected a few eval examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github superawesomelabs / leo / packages / leo-core / src / plugins / static-site-plugin / index.js View on Github external
*/
      const scopeGlobals = {
        self: {
          XMLHttpRequest: XMLHttpRequest
        },
        XMLHttpRequest: XMLHttpRequest,
        _globalJSONAsset: function writeJSON({ name, json }) {
          debug(`writeJSON ${name}`);
          // the filename here should be the URL of the "current
          // page", because the client-side relay network layer relies
          // on the URL hash to fetch the json file
          compiler.assets[name] = createAssetFromContents(JSON.stringify(json));
        }
      }

      let render = evaluate(source, /* filename: */ renderSrc, /* scope: */ scopeGlobals, /* includeGlobals: */ true);
      // if the exported function is an es6 default export, use it
      if (render.hasOwnProperty('__esModule')) {
        render = render['default'];
      }
      if (typeof render !== 'function') {
        throw new Error(`Export from "${renderSrc}" must be a function that returns an HTML string`);
      }

      each(outputPaths, (outputPath, cb) => {
        var outputFileName = outputPath.replace(/^(\/|\\)/, ''); // Remove leading slashes for webpack-dev-server

        // jsonOutputFileName should be in scaffolding-relay
        var jsonOutputFileName = path.join('api', md5('/' + outputFileName) + '.json');
        if (!/\.(html?)$/i.test(outputFileName)) {
          outputFileName = path.join(outputFileName, 'index.html');
        }
github MoOx / rc-loader / src / parser.js View on Github external
export default function parser(content, file) {
  try {
    return yaml.safeLoad(stripJsonComments(content))
  }
  catch (e) {
    // `(module.)exports` = JS ?
    if (/exports/.test(content)) {
      return evalModule(content)
    }

    throw new Error(
      "Cannot parse runtime configuration as YAML, JSON or JS" +
      (file ? `from '${file}'` : "")
    )
  }
}
github superawesomelabs / leo / packages / graphql-directory-api / src / gen-database / index.js View on Github external
const jsonStats = stats.toJson();
    if (jsonStats.errors.length > 0) {
      //soft failure
      debug('webpack stats errors', jsonStats.errors[0]);
      callback(jsonStats.errors);
      return;
    }
    if (jsonStats.warnings.length > 0) {
      debug('webpack stats warnings', jsonStats.warnings);
      callback(jsonStats.warnings);
      return;
    }
    // End Error Checking
    debug('dist output', fs.readdirSync(distFolder));
    const apiJSONAsString = fs.readFileSync(resolve(distFolder, 'database-bundle.js'), 'utf-8');
    const apiJSON = evaluate(apiJSONAsString, 'api-database.json', null, true);
    letPluginsPostProcessData(plugins, apiJSON, (err, resultingData) => {
      if(err) {
        debug('caught err', err);
        // facilitate callback if error is thrown
        return callback(err);
      }
      debug('resultingData count', resultingData.length);
      return callback(null, resultingData);
    })

  }
github andreypopp / sitegen / src / compiler / utils.js View on Github external
}
  function localRequire(module) {
    // $FlowIssue: ...
    return require(localResolve(module));
  }
  localRequire.resolve = localResolve;
  scope = {
    console,
    process,
    require: localRequire,
    setTimeout,
    __filename: filename,
    __dirname: dirname,
    ...scope,
  };
  return evaluate(source, filename, scope);
}
github superawesomelabs / leo / packages / leo-core / src / utils / gen-database.js View on Github external
if (jsonStats.errors.length > 0) {
        //soft failure
        debug('webpack stats errors', jsonStats.errors[0])
        return console.warn(jsonStats.errors);
      }
      if (jsonStats.warnings.length > 0) {
        debug('webpack stats warnings', jsonStats.warnings)
        return console.warn(jsonStats.warnings);
      }
      /**
       * End Error Checking
       */
      debug('dist output', fs.readdirSync(distFolder));
      const str = fs.readFileSync(distFolder + '/bundle.js').toString('utf-8');
      callback(null, {
        data: evaluate(str, 'api-database.json', null, true),
        plugins: conf.plugins
      });
    })
  })
github superawesomelabs / leo / packages / leo-core / src / develop / gen-database--watch.js View on Github external
const jsonStats = stats.toJson();
    if (jsonStats.errors.length > 0) {
      //soft failure
      debug('webpack stats errors', jsonStats.errors[0])
        return console.warn(jsonStats.errors);
    }
    if (jsonStats.warnings.length > 0) {
      debug('webpack stats warnings', jsonStats.warnings)
        return console.warn(jsonStats.warnings);
    }
    /**
     * End Error Checking
     */
    debug('dist output', fs.readdirSync(distFolder));
    const apiJSONAsString = fs.readFileSync(distFolder + '/bundle.js', 'utf-8');
    const apiJSON = evaluate(apiJSONAsString, 'api-database.json', null, true);
    letPluginsPostProcessData(conf.plugins, apiJSON, (err, resultingData) => {
      callback(null, {
        data: resultingData,
        plugins: conf.plugins
      });
    })
  })
}
github andreypopp / sitegen / src / compile.js View on Github external
function evalBundle(assets) {
  let source = assetSource(assets['bundle.js']);
  let scope = {
    console,
    process,
    require,
    setTimeout,
  };
  return evaluate('module.exports = ' + source, '', scope);
}
github andreypopp / sitegen / src / webpack / RenderStaticPlugin.js View on Github external
compiler.plugin('emit', (compilation, done) => {
      let bundle = compilation.assets[JS_BUNDLE_NAME];
      let source = bundle._source ?
        bundle._source.source() :
        bundle.source();
      let window = {};
      let scope = {
        console,
        process,
        setTimeout,
        window
      };
      let routes = evaluate('module.exports = ' + source, '', scope);

      cleanAssets(compilation.assets);

      function addToAssets(path, markup) {
        compilation.assets[routePathToAssetPath(path)] = createAssetFromContents(markup);
      }

      let collectedRoutes = collectRoutes(routes);

      collectedRoutes
        .then(childRoutes => {
          let linkRegistry = LinkRegistry.createFromRoutes(childRoutes);
          let pageRegistry = PageRegistry.createFromRoutes(childRoutes);
          linkRegistry.install(window);
          pageRegistry.install(window);
          return forEachSeq(childRoutes, route =>

eval

Evaluate node require() module content directly

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis

Popular eval functions