nol13 / fuzzball.js

Easy to use and powerful fuzzy string matching, port of fuzzywuzzy.
MIT License
516 stars 40 forks source link

How to - Install with systemjs #1

Closed natcohen closed 7 years ago

natcohen commented 7 years ago

I would like to install fuzzball in angular 2 using systemjs (not require) how can I do?

nol13 commented 7 years ago

Hmm, well for one thing just realized I hadn't included /lib in the package.json after a recent refactor, which certainly would have caused some issues. Have just updated the package to fix that.

Have not used those exactly, but guessing would need to run through either systemjs-builder or jspm.

Not sure about your exact workflow, and havent really used jspm much, but something along these lines seemed to work..

in test.html..

<!doctype html>
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script src="build.js"></script>
<script>
    System.import('app/main.js');
</script>

in app/main.js..

import * as fuzz from 'fuzzball';
alert(fuzz.ratio('fuzz', 'fuzzy'));

then to build..

sudo npm install jspm -g
jspm init
jspm install npm:fuzzball
jspm bundle app/main build.js

Can take a look again when I get a chance probably later this week. Would like to make it easy to use with most of the common formats though.

nol13 commented 7 years ago

So looks like making the main entry point for this a pre-bundled UMD style file might be the way to go.. which you could then use with SystemJS like below without any additional build steps. Not merged into master yet but have just pushed a 'umd' branch with these changes. This more or less how you'd be using? Pretty sure the jspm way above would still work too but have not yet tested. Also out of curiosity are you using TypeScript with Angular 2? Probably will add some type defs eventually.

<!doctype html>
<script src="system.js"></script>
<script>
    System.import('fuzzball.umd.min.js').then(function(fuzz){
        alert(fuzz.ratio('fuzz', 'fuzzy'));
    });
</script>
natcohen commented 7 years ago

Yes, the umd file is what I use with the other libraries! And yes, I'm using Angular 2 with typescript... I will try as soon as you release it on the main branch!

nol13 commented 7 years ago

main branch now officially umd

natcohen commented 7 years ago

Works great! However, in some cases I don't get the expected results... you should really add a demo page so we can test online. It will really help to track bugs!

nol13 commented 7 years ago

hmm, example? Not full demo but there is a "try on runkit" button at the top of the readme.

nol13 commented 7 years ago

fwiw if using, making that the main potentially causes issues with other build systems, so the bundled umd file now in /dist

natcohen commented 7 years ago

I'm sometimes surprised by the results... if you provide a test page where we can define the options and and test our strings we could see if there is a bug.

nol13 commented 7 years ago

Right on, not 100% sure when I'd have a chance to get to it but might try something along those lines.