question to browserify ?

104 views
Skip to first unread message

Mike Zero

unread,
Nov 6, 2020, 3:54:34 AM11/6/20
to DroidScript
Hi, I want to create a file with Browserify, but how can I export the function?

var JSSoup = require("jssoup");
module.exports.getTxt = function(txt) {
    var soup = JSSoup(txt, 'lxml');
    ........
}
>> browserify file.js -s jssoup -o bundle.js

when I load the bundle.js with app.LoadScript("bundle.js"); I cannot use the function getTxt(); -> the function is not defined.
Has anyone an idea?
Thanks!!!

Steve Garman

unread,
Nov 6, 2020, 4:05:21 AM11/6/20
to DroidScript
Have you seen Dave's suggestion about the index.js file at https://groups.google.com/d/msg/androidscript/JI_Yw6Omgl0/38izmPIKCAAJ ?

Mike Zero

unread,
Nov 6, 2020, 7:41:46 AM11/6/20
to DroidScript
It doesnt work for me. The function "getTxt is not defined"

Dave

unread,
Nov 6, 2020, 5:10:19 PM11/6/20
to DroidScript
Please post your index file

Mike Zero

unread,
Nov 7, 2020, 2:57:49 AM11/7/20
to DroidScript
This is my file for Browserify:

var JSSoup = require("jssoup");

module.exports.getTxt = function(txt) {
var soup = JSSoup(txt, 'lxml')

for(tag in soup.select('div[class^="Lyrics__Container"], .song_body-lyrics p')) {
    t = tag.get_text(strip=true, separator='\n');
    }
   return t;
   }

and in the DroidScript file I include it with app.LoadScript("bundle.js");

Dave

unread,
Nov 16, 2020, 1:20:13 PM11/16/20
to DroidScript
try this instead for your Browserify index.js file:-

window.JSSoup = require("jssoup");

Then access the JSSoup object in DS like this

app.Script("bundle.js");
var soup = window.JSSoup(txt, 'lxml')
Reply all
Reply to author
Forward
0 new messages