Bijoujs / Bijou.js

Bijou.js: Useful JavaScript snippets in one simple library
https://bijou.js.org
GNU General Public License v3.0
32 stars 8 forks source link

We need more features for NodeJS #16

Closed Explosion-Scratch closed 3 years ago

Explosion-Scratch commented 3 years ago

Currently a lot of the features of Bijou.js rely on DOM/window/document elements. This means that only about half of functions work in NodeJS. Even though I suggest in the error thrown to use JSDom I don't want to make this dependent on it. This means that we need new ideas! What snippets do people use frequently in Node? Comment below anything that you use/think is helpful! Thanks in advance!

--Explosion--

williamhorning commented 3 years ago

Ok, first thing first what doesn't work on node.js without JSDom, do they rely on document/window/dom and can't be used without them and does JSDom make these features work in node.js? Would these features be widely used and should be able to use these features without installing JSDom?

Explosion-Scratch commented 3 years ago

Ok, first thing first what doesn't work on node.js without JSDom,

Lots of functions, like parseHTML, fetch, formData and many others, just search for isNode in bijou.js to see all of them.

do they rely on document/window/dom and can't be used without them and does JSDom make these features work in node.js?

Yes. To my knowledge JSDom allows everything that client-side JS does.

Would these features be widely used and should be able to use these features without installing JSDom?

I don't know. As Bijou.js is still in the early stages it's quite possible that these would be used widely or not. Some things (Like a copy(text) function) would be widely used but are useless in NodeJS, other things, (like syntaxHighlight) rely on the DOM for manipulation of HTML elements, while more use event listeners and would be useless even if they worked in NodeJS (onScrollStop, or addStyles).

williamhorning commented 3 years ago

Lots of functions, like parseHTML, fetch, formData and many others, just search for isNode in bijou.js to see all of them.

Ok, here is what won't work in node and these need the document element

Yes. To my knowledge JSDom allows everything that client-side JS does.

Really? Have you tried the above list using JSDom?

I don't know. As Bijou.js is still in the early stages it's quite possible that these would be used widely or not. Some things (Like a copy(text) function) would be widely used but are useless in NodeJS, other things, (like syntaxHighlight) rely on the DOM for manipulation of HTML elements, while more use event listeners and would be useless even if they worked in NodeJS (onScrollStop, or addStyles).

Fair point, this makes sense.

Explosion-Scratch commented 3 years ago

Yes. To my knowledge JSDom allows everything that client-side JS does.

Really? Have you tried the above list using JSDom?

No, I assuming.

williamhorning commented 3 years ago

Yes. To my knowledge JSDom allows everything that client-side JS does.

Really? Have you tried the above list using JSDom?

No, I assuming.

Makes enough sense, and most of these would be useless for node.js

Explosion-Scratch commented 3 years ago

@wgyt Also note that highlightel is an internal function and cannot be used outside of the syntaxHighlight scope.

williamhorning commented 3 years ago

@wgyt Also note that highlightel is an internal function and cannot be used outside of the syntaxHighlight scope.

Oh really? What does highlightel do?

Explosion-Scratch commented 3 years ago

@wgyt Also note that highlightel is an internal function and cannot be used outside of the syntaxHighlight scope.

Oh really? What does highlightel do?

syntaxHighlight returns the syntax highlighted HTML for a string of code (E.g. alert("hello")), highlightel syntax highlights an element and applies it to the element, an unfavorable alternative to highlighting a string, as it's less customize-able.

williamhorning commented 3 years ago

@wgyt Also note that highlightel is an internal function and cannot be used outside of the syntaxHighlight scope.

Oh really? What does highlightel do?

syntaxHighlight returns the syntax highlighted HTML for a string of code (E.g. alert("hello")), highlightel syntax highlights an element and applies it to the element, an unfavorable alternative to highlighting a string, as it's less customize-able.

oh ok makes sense

TheColaber commented 3 years ago

Take a look at https://github.com/TheColaber/Text2HTML it parses HTML without using dom parsers or innerHTML. It's useful if you're trying to submit a chrome extension or something that disallows innerHTML and dom parsers.

GrahamSH-LLK commented 3 years ago

Here's an idea: add a dependency of jsdom.

williamhorning commented 3 years ago

Here's an idea: add a dependency of jsdom.

@Explosion-Scratch said:

Even though I suggest in the error thrown to use JSDom I don't want to make this dependent on it.

Explosion-Scratch commented 3 years ago

Here's an idea: add a dependency of jsdom.

Yeah, JSDom would enable some features that we have in vanilla JS, but so many would just be totally useless in NodeJS, like _$.copy("Hello"), or notify(). Instead of focusing on extending existing functions to work with NodeJS, I'd rather find new functions that are helpful to NodeJS.

ghost commented 3 years ago

hmmmmmmm