module imghelper.js_helper

Inheritance diagram of pyquickhelper.imghelper.js_helper

Short summary

module pyquickhelper.imghelper.js_helper

Helpers around images and javascript. See also:

source on GitHub

Classes

class

truncated documentation

NodeJsException

Raised if node.js fails.

Functions

function

truncated documentation

install_node_js_modules

Installs missing dependencies to compile a convert a javascript libraries.

nodejs_version

Returns node.js version.

require

Modified version of function require in node_import.py. …

run_js_fct

Assuming script contains some javascript which produces SVG. This functions runs the code.

run_js_with_nodejs

Runs a javascript script with node.js.

Documentation

Helpers around images and javascript. See also:

source on GitHub

exception pyquickhelper.imghelper.js_helper.NodeJsException[source]

Bases: Exception

Raised if node.js fails.

source on GitHub

pyquickhelper.imghelper.js_helper.install_node_js_modules(dest, module_list=None, fLOG=<function noLOG>)[source]

Installs missing dependencies to compile a convert a javascript libraries.

Parameters:
  • dest – installation folder

  • module_list – list of modules to install

  • fLOG – logging function

If module_list is None, it is replaced by:

['babel-core', 'babel-cli', 'babel-preset-env',
 'babel-polyfill', 'babelify', 'browserify',
 'babel-preset-es2015']

source on GitHub

pyquickhelper.imghelper.js_helper.nodejs_version()[source]

Returns node.js version.

source on GitHub

pyquickhelper.imghelper.js_helper.require(module_name, cache_folder='.', suffix='_pyq', update=False, fLOG=<function noLOG>)[source]

Modified version of function require in node_import.py.

Parameters:
  • module_name – required library name

  • cache_folder – location of the files the function creates

  • suffix – change the suffix if you use the same folder for multiple files

  • update – update the converted script

  • fLOG – logging function

Returns:

outcome of the javascript script

The function is not fully tested.

source on GitHub

pyquickhelper.imghelper.js_helper.run_js_fct(script, required=None)[source]

Assuming script contains some javascript which produces SVG. This functions runs the code.

Parameters:
  • scriptjavascript

  • required – required libraries (does not guaranteed to work)

Returns:

python function

The module relies on js2py and node.js. Dependencies must be installed with npm:.

npm install babel-core babel-cli babel-preset-es2015 babel-polyfill babelify browserify babel-preset-env

Function install_node_js_modules can be run with admin right for that. js2py tries to convert a dependency into Python

source on GitHub

pyquickhelper.imghelper.js_helper.run_js_with_nodejs(script, path_dependencies=None, fLOG=<function noLOG>)[source]

Runs a javascript script with node.js.

Parameters:
  • script – script to run

  • path_dependencies – where dependencies can be found if needed

  • fLOG – logging function

Returns:

output of the script

source on GitHub