Comments (7)
Srry about the title edit spam, running on insufficient sleep
from flatten-interval-tree.
Seems I need to learn this stuff dipper
from flatten-interval-tree.
Hi, David,
I have an example of consuming IntervalTree in plane ES6 HTML page in /examples section.
I slightly changed it to consume also Node and Interval classes, and it also works "as is" without any changes.
Look at the code, I think you just need to define attribute type="module" in script tag.
<script type="module">
import IntervalTree from "https://unpkg.com/@flatten-js/interval-tree?module";
import {Node, Interval} from "https://unpkg.com/@flatten-js/interval-tree?module";
const composers = [
{name: "Ludwig van Beethoven", period: [1770,1827]},
{name: "Johann Sebastian Bach", period: [1685, 1750]},
{name: "Wolfgang Amadeus Mozart", period: [1756, 1791]},
{name: "Johannes Brahms", period: [1833, 1897]},
{name: "Richard Wagner", period: [1813, 1883]},
{name: "Claude Debussy", period: [1862, 1918]},
{name: "Pyotr Ilyich Tchaikovsky", period: [1840, 1893]},
{name: "Frédéric Chopin", period: [1810, 1849]},
{name: "Joseph Haydn", period: [1732, 1809]},
{name: "Antonio Vivaldi", period: [1678, 1741]}
];
const compList = composers.reduce( (html,composer) => html + `<li>${composer.name} (${composer.period[0]} - ${composer.period[1]})</li>`, "" );
document.getElementById("list").innerHTML = compList;
// Composers who lived in 17th century
const tree = new IntervalTree();
for (let composer of composers)
tree.insert(composer.period, composer.name);
// const searchRes = tree.search( [1600,1700], (name, period) => {return {name : name, period: period.output()}} );
if (tree.root instanceof Node) {
const interval = new Interval(1600, 1700);
const searchRes = tree.search(interval, (name, period) => {
return {name: name, period: period.output()}
});
const resList = searchRes.reduce((html, composer) => html + `<li>${composer.name} (${composer.period[0]} - ${composer.period[1]})</li>`, "");
document.getElementById("results").innerHTML = resList;
}
</script>
Best,
Alex
from flatten-interval-tree.
I am sure it works fine through the entry point of /dist/main.esm.js
with just JS which is what the CDN unpkg.org/<...>?module
delivers, but I am entering through the npm package on the /index.js
file which gets automatically associated with the index.d.ts typed declaration file right next to it for Typescript which is ideal for my use case. For example in my TS/JS file:
import {IObserver, IPlayable, IPlayerController, PlayerStatus, Time} from "../../types/types.js";
import {ISequencer} from "../../types/sequencer.js";
import {TimerElapsed} from "../../classes.js";
import IntervalTree from "./../../../../node_modules/@flatten-js/interval-tree/index.js";
Again, not using @flatten-js/interval-tree
since I am not using a loader/packager who could resolve this with Typescript and the TS Compiler does not make these changes on its own, I need to explicitly go there with a relative path. If I don't insert the '.js' extension to the export statement in index.js the browsers will not be able to find the files:
Its not able to resolve these two paths in the export statements.
export {default as Node} from './src/classes/node';
export {default as Interval} from './src/classes/interval';
...
When I manually edit the package and insert the '.js' file extension as described in my original post the browser is able to resolve the paths in index.js.
Its fine if you do not wish to support this entry point with pure browser ES module system but I would certainly appreciate it. It shouldn't affect the package otherwise I am fairly sure. I could use the /dist/main.esm.js
but I am having issues with my IDEA IDE mapping /dist/main.esm.js
to /index.d.ts
. Its even worse with the CDN Url when I use it in a .js file context. My IDE/tslint is fine with it only if I use it from the context of an .html file but not from the context of a .js file. It complains with:
TS2792: Cannot find module 'https://unpkg.com/@flatten-js/interval-tree?module'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
- when using
"moduleResolution": "classic"
which is what I am currently using and
- when using
TS2307: Cannot find module 'https://unpkg.com/@flatten-js/interval-tree?module' or its corresponding type declarations.
- when using the tsconfig.json option
"moduleResolution": "node"
- when using the tsconfig.json option
These two options (main.esm.js and unpkg.com) work fine when accessed by the browser but I would have to disable and lose tslinting and auto completion for these files/objects in my IDE. If I can just use index.js I can keep both functionalities, which is what I am currently doing by editing index.js but its not something I can push to my github with good conscience if I need to include special instructions to manually edit a npm module file after someone pulls it and performs npm install
(I could technically attach a script that would do it but still).
Thank You!
- David
from flatten-interval-tree.
I got your point.
No problem, I will make a change soon
Alex
from flatten-interval-tree.
Hi, David,
I updated index.js in release v1.0.16
Thank you,
Alex
from flatten-interval-tree.
Much appreciated. Thank you for your work!
David
from flatten-interval-tree.
Related Issues (20)
- Wrong result when low or high is 0 HOT 1
- Use this package with TypeScript HOT 1
- Unable to remove/find some of the nodes HOT 2
- Storing '0' as a key value will return a key pair when searching HOT 2
- Brother Node left and right = null => cannot read color of undefined HOT 3
- Fast way to check if interval collides collides i.e intersects([low, high]): boolean HOT 3
- [Feature Request] addition of allowTouching mode HOT 1
- npm package size is too large (1.69MB) due to lack of proper .npmignore to exclude documentation files HOT 2
- Some useful functions that could be included HOT 2
- Question about cloning in IntervalTree HOT 2
- Question: are intervals returned by `search` sorted? HOT 2
- Remove all items within a range HOT 2
- Npm publish 1.1.1 HOT 2
- Typescript usage of SearchOutput is any?
- Support for bigint HOT 1
- Examples are all 1D HOT 1
- Deprecation warning HOT 2
- v0.3 return intervals as search response HOT 4
- Error with finding interval HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flatten-interval-tree.