qmljsify - Convert an NPM package into a QML friendly JavaScript file


  • Qt Champions 2016

    Hello,

    I would like to share a experimental project here. It is qmljsify , a tool that could converts an NPM package into a QML friendly JavaScript file.

    Project Site
    http://www.github.com/e-fever/qmljsify

    Usage: qmljsify [options] command package
    qmljsify - Download and convert an NPM package to a QML friendly JavaScript file
    
    Options:
      -h, --help   Displays this help.
      --no-minify  Turn off JavaScript Compression
    
    Arguments:
      command      Command [Available Commands: convert]
      package      NPM package to be qmljsified
    

    Example:

      qmljsify convert sprintf
    

    Then it will fetch sprintf from NPM and create two files

      sprintf.orig.js # A compiled and minified sprintf library
      sprintf.js # A Wrapper of the compiled sprintf library for QML
    

    That is what sprintf.js looks like:

    .pragma library
    Qt.include("sprintf.orig.js")
    var object_stringify = QML.object_stringify;
    var format = QML.format;
    var cache = QML.cache;
    var parse = QML.parse;
    var sprintf = QML.sprintf;
    var vsprintf = QML.vsprintf;
    

    Then you could use it in your QML file:

    import "./sprintf.js" as SPrintf
    
    // [snipped]
    SPrintf.sprintf("%d %d", 1 , 2);
    

    It is just the first release and not every package works. If you have any problem / suggestion , please feel free to tell me.


  • Lifetime Qt Champion

    Hi,

    Looks nice ! Thanks for sharing !


Log in to reply