Haxe externs for JS libraries - javascript

Does there exist any central place where all Haxe bindings for JS libraries are meant to be stored? Both if I want to find one, or submit one.
Is there some not outdated working tool to generate these bindings from TypeScript definitions?
Is there a binding for nodejs ws library?

http://lib.haxe.org also known as haxelib, the Haxe package manager. Other than that there are also libraries on Github, which you can install with haxelib git libname https://github.com/bla/bla.git
This kinda sounds like all libs are out of date. There is https://github.com/Simn/ts2hx as you might understand it is not a simple task to create such tool since TypeScript is a different (more dynamic) language and has a different type system which doesnt easily translate to haxe externs. In my experience this lib does 90% of the work. Also it isnt hard to create own externs, but I get you expect free direct-use libs. If tool/lib doesnt work please repot or contribute at the lib; Thats how opensource projects work.
I dont know
Hope this helps! Have a nice day!

Besides Haxelib, you can usually find a ton of stuff on GitHub (e.g. by searching for jsrequire <foo> language:haxe or other keywords). There are also some privately curated extern collections like clemos/js-kit, haxe-node-modules, abedev/npm
Simn/ts2hx is the only one that comes to mind
I found some externs, some of them inside other projects/libraries

Related

Guide for extending the Javascript language on VsCode for a 3rd party API

So I've started using VsCode over Atom recently and love it, the issue is I develop for software that uses its own JS API with no proper integration into anything.
I've started trying to implement my own autocomplete/intellisense structure using their pdf into VsCode to speed up my workflow, currently I'm simply using a JS file that is full of empty functions and objects with a bunch of JSDoc comments to help VsCode Intellisense identify what's what, that seems to be working fine so far but it means importing this "useless" file into every project I work on.
I looked into extending the JS language using a language server but that seems way too complex for what I need (plus it looks like I'd be building the entire Javascript language from scratch).
Does anyone have any recommendations ect?
Kind regards.
Edit
Sorry I also would like the ability for it to pass linting as right now it gets a bit funky with it.
You likely do not need an extension for that your example use case.
VS Code's intellisense for libraries is powered by .d.ts typing declaration files. The declaration files for the library you are using can either be written in your current workspace as you are currently doing, or—preferably—shipped with the library itself. Many npm modules ship their with typing definitions files, while other libraries have typing definition files provided by the community through DefinitelyTyped.
You alternatively bundle d.ts types file into as a separate npm package that you include in any project that needs them

Using .js file extensions whilst writing scripts that return jsx

I started using react as my ui framework of choice. Upon my adventure through the documentation I noticed that when using the create-react-app script to spin up a new react boilerplate, they used .js file extension on scripts that where returning jsx code. When I asked my buddy he told me that you should use the .jsx extension on scripts that are returning this kind of code.
Im a bit lost here as if both works, wouldn't it just be better to go with the .js extension as at the end of the day its javascript we writing.
Please help me with what is considered best practise. (I kinda have a feeling it would be to use the .jsx extensions on these types of scripts, but I'd love to hear the community's view on this)
Thanks in advance :)
It's really up to personal preference.
My personal opinion is JavaScript is JavaScript, and I just use .js. Others will prefer to use .jsx in files that are JSX and .js in for things like utilities, in order to differentiate. The only important thing is to be consistent in whatever you choose (at least within one project).
In general, it doesn't matter.
The only time it might actually matter is based on your build pipeline. Some build pipelines may be configured to compile .js and .jsx with slightly different rules, but that would be based on your application (things like create-react-app don't care).
At the end of the day, you could use a .cookiemonster extension and it'd work just fine (as long as your build pipeline is configured to handle it).
Actually it doesn't matter, is up to you to decide I prefer to use .jsx when I return the mix between HTML and JS and use .js only when I'm using plain JS or ES6.
I recommend you to read about this on this issue on github.

Typescript extract knowledge from js object

I'm creating a ionic (cordova) product and I'd like to utilize typescript and its benefits for autocompletion optimally. But since many of the plugin objects don't stem from concrete classes I don't know how/if there is a way to utilize the knowledge from the plugin files (which are .js). If there is a way to do this I'd of course like to know this.
As mentioned in my comment you can use Typescript definition files to provide type information.
There are definition files for common Cordova plugins on Definitly Typed.
If you can't find type information for the plugin you're looking for, you can write your own definition file.
If there is a way to do this I'd of course like to know this.
Yes. Just add allowJS to true in the tsconfig.json compilerOptions. Your IDE should magically start working with .js files ;)
More
Give http://alm.tools/ a go. I wrote it with such workflows in mind 🌹

TypeScript d.ts and .js consistency

Using these definitions:
https://github.com/borisyankov/DefinitelyTyped
So, say, I use angularJS 1.3.14, how to know for sure that there is proper definition for that particular angular version?
Or how to know for sure that DefinitelyTyped *.d.ts file is consistent to its *.js one?
Or If I use older version of AangularJS, how to find proper ts file?
How do I know it is a proper definition?
You use it and see if you come across a bug. Definitely Typed is open source and accepts issues and contributions so it is easy to remedy any errors in the definitions.
In the case of Angular, the large community will typically result in fewer errors in the definitions as many people are already using them.
How do I know the .d.ts is consistent to its .js one?
This is largely the same as above. This is a community endeavour, so there are many people updating type definitions to keep them correct. If you find a problem it is usually simple to solve (the type definition itself usually looks a lot like the API documentation for a library).
If I use an older version of Angular, how do I find the .d.ts file.
You can see the history on GitHub, for example the angular.d.ts history.
You can usually see when the commits go in to update the library versions here.

How do you attach JSdoc in Eclipse so that I can have autocomplete for a personal library

I have a JavaScript library that I am working on currently. I have structured it into lots of files and I use the module approach to define each 'module'.
var ns = generateNamespace("me.mycompany.mypackage.MyFile");
(function (ns, undefined) {
// some module
}(ns));
The modules are dynamically named using a namespacing function meaning that autocomplete is almost impossible as things stand (unless Eclipse can run my code and figure out the namespaces, Visual Studio can!).
Therefore I intend to generate JSdoc for my project in the hope that if I include this into Eclipse (somehow) Eclipse can use this to give me content assist.
Firstly I do not know if this is possible... however I think that it is as I can see that it is maybe how this works? However I tried to follow this along and struggled to get something working, by this I mean it didn't work. The interesting info from the link:
"JSDT libraries are collections of JavaScript source files that have prototyped object/class definitions and JSDoc. The inference engine then models these libraries... making them available to every JavaScript file in the project... Bindings for nonstandard and future runtimes are similarly easy to create... add the... library to their project and gain content completion and hover help"
I know how to write JSdoc annotations and I know how to generate JSdoc using one of the various tools.
What I need therefore is instructions on how to include JSdoc (as a library maybe) in Eclipse so that it will give auto complete for the stuff in the JSdoc.
Previous answer:
You can also run jsdoc_toolkit from within eclipse by setting up Run -
> External Tools -> Open External Tools Dialog...
Location
C:\Program Files\Java\jre1.5.0_12\bin\java.exe
Working Directory
C:\DirectoryToWhereJsDocToolkitIsLocated\jsdoc_toolkit
Arguments
-jar app/js.jar app/run.js -r=4 -t=templates/htm "-d=C:
\PathToWhereDocIsSaved" "C:\PathToWebsiteToDocument"
For more about the arguments check the jsdoc_toolkit documentation.
Have fun
Simon
Taken from this Google Groups thread.
Updated Answer:
Eclipse JavaScript Editor: content assist for js files, autocompletion
Disclaimer, I'm the author of tern.java.
I suggest you that you install tern.java. It provides a JSDoc support. Once you have selected this support, you can benefit
with completion :
and soon with validation:
This support is not perfect but it starts working.
I am not using it by myself, so I'm not sure if it works, but there exists a grunt-plugin for jsdoc3. Grunt is supported by Eclipse. So maybe it helps.
Grunt-PlugIn in npm

Categories

Resources