insane-jo / talib-wasm

MIT License
27 stars 6 forks source link

Browser support #1

Closed mjafarpour closed 4 years ago

mjafarpour commented 4 years ago

Hi, Do you want to export a browser version of this library? If supported, How can I use this in browser environment?

insane-jo commented 4 years ago

You can use it inside browser. This library compiled with emscripten and tested inside FF, Chrome and Opera. But you need to use webpack or something similar to it because it uses require inside modules. If you don't know how to use webpack - let me know, i'll give you example of config, or standalone library.

mjafarpour commented 4 years ago

I didn't use webpack, can you explain some example to use it in easy way. Thanks

insane-jo commented 4 years ago

You can view config and build version of talib-wasm: talib-webpack.zip

To build you can use npm install && npm run build

Or you can use standalone version of library located in archive: dist/app.js

This file defines global variable TALIB

Code example:

window.TALIB.then((funcs) => {
        const totalLength = 50;
        const inputArray1 = new Array(totalLength);
        const inputArray2 = new Array(totalLength);

        for (let i = 0; i < totalLength; i++) {
            inputArray1[i] = Math.random() * 100;
            inputArray2[i] = Math.random() * 100;
        }

        const result = funcs.CORREL({
            startIdx: 0,
            begIdx: totalLength - 1,
            inReal0: inputArray1,
            inReal1: inputArray2,
            optInTimePeriod: 5
        });

        console.log(
            result        
        );
    });
rahulamalkar commented 3 years ago

[rahul @localhost 11:26:37 talib-webpack] $ npm run build

talib-webpack@1.0.0 build /home/rahul/talib-webpack webpack

Browserslist: caniuse-lite is outdated. Please run the following command: npm update Hash: 02317cde384c27b2cf9e Version: webpack 4.42.0 Time: 13787ms Built at: 02/17/2021 11:26:56 AM 1 asset Entrypoint app = app.js [8] (webpack)/buildin/global.js 472 bytes {0} [built] [78] ./src/index.js 37 bytes {0} [built] [82] external "\"No fs node module used\"" 42 bytes {0} [built] [85] util (ignored) 15 bytes {0} [built] [87] util (ignored) 15 bytes {0} [built] [118] (webpack)/buildin/module.js 497 bytes {0} [built] [119] buffer (ignored) 15 bytes {0} [optional] [built] [120] crypto (ignored) 15 bytes {0} [optional] [built]

WARNING in configuration The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment. You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

ERROR in ./node_modules/talib-wasm/main.js Module not found: Error: Empty dependency (no request) @ ./node_modules/talib-wasm/main.js 1:36350-36361 @ ./src/index.js npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! talib-webpack@1.0.0 build: webpack npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the talib-webpack@1.0.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /home/rahul/.npm/_logs/2021-02-17T05_56_56_974Z-debug.log

insane-jo commented 3 years ago

@rahulamalkar seems you need to set right links - version of package changed. Simply use import 'talib-wasm' in head of your file. And you need to add external blank dependencies for fs and ws modules in webpack (this is only for nodejs modules)

rahulamalkar commented 3 years ago

@insane-jo thanks for reply. I am not expert In web assembly and we pack.

I am developing application puerile on html and js, just looking for final artifact to use in index.html to run analysis on handful of data.

I am looking for some thing similar to sql.js.

insane-jo commented 3 years ago

@rahulamalkar Open new issue (do not use closed issues) and write your problem (or target) and how can I help. I will try to help you.