Not working in Browser
aahedi opened this issue · 5 comments
<script src="https://requirejs.org/docs/release/2.3.6/minified/require.js"></script>
<script src="https://unpkg.com/string-comparison@1.1.0/dist/index.js"></script>
<script>
let stringComparison = require('string-comparison')
const Thanos = 'healed'
const Rival = 'sealed'
const Avengers = ['edward', 'sealed', 'theatre']
// use by cosine
let cos = stringComparison.cosine
console.log(cos.similarity(Thanos, Rival))
console.log(cos.distance(Thanos, Rival))
console.log(cos.sortMatch(Thanos, Avengers))
</script>
First, sorry for the late reply...
In Browser, we recommend using 'module':
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Static Template</title>
<!-- <script type="module" src="https://unpkg.com/string-comparison@1.1.0/dist/index.mjs"></script> -->
</head>
<body>
<h1>
This is a static template, there is no bundler or bundling involved!
</h1>
<script type="module">
# like this.
import {cosine as cos} from 'https://unpkg.com/string-comparison@1.1.0/dist/index.mjs'
const Thanos = "healed";
const Rival = "sealed";
const Avengers = ["edward", "sealed", "theatre"];
console.log(cos.similarity(Thanos, Rival));
console.log(cos.distance(Thanos, Rival));
console.log(cos.sortMatch(Thanos, Avengers));
</script>
</body>
</html>
unfortunately, https://unpkg.com/string-comparison@1.1.0/dist/index.mjs
doesn't work on locale, it always has to use host
unfortunately,
https://unpkg.com/string-comparison@1.1.0/dist/index.mjs
doesn't work on locale, it always has to use host
why???
I use this for offline.
<script type="module" src="index.mjs"></script>
and in console.log
Access to script at 'file:///D:/../index.mjs' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted. test.html:11
GET file:///D:/../index.mjs net::ERR_FAILED test.html:25 Uncaught ReferenceError: cos is not defined at test.html:25:19
StringComparision did not bind to the window
, so you should use import from 'url'
...
if you want to use it on the window object, you can do this:
import sp from 'https://unpkg.com/string-comparison@1.1.0/dist/index.mjs'
window.sp = sp;