npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

haxe-js-kit

v0.0.12

Published

Haxe tools and externs for Javascript and Node.js

Downloads

4

Readme

A Javascript Toolkit for Haxe

A collection of externs and tools to quickly get started with Haxe/JS, including Node.js

A full step-by-step tutorial is available here, thanks to @MatthijsKamstra :)

Installation

Using haxelib :

haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib

Or you can just download / clone the repo manually, and add the folder to your project's classpath

Features

Type signatures

The library contains type signatures for :

  • The core node.js API
  • Common NPM libraries such as :
    • Mongoose elegant mongodb object modeling with optional strict-typing and support for typedef to schema modeling [example]
    • Express.js web application framework
    • Socket.io cross-browser websockets for realtime apps
    • Passport.js simple, unobtrusive authentication
    • Atom-shell cross-platform desktop application shell
    • and more to come ;)
  • Some major client-side libraries : up-to-date JQuery externs, socket.io client, etc

NPM integration

The library provides an easy way to manage NPM dependencies:

Basically, the NPM packages that correspond to the libraries used by your project will be automatically required at compile-time.

Exporting your project dependencies

All NPM packages included this way can also be automatically exported by the Haxe compiler, typically to a package.json file, so they can be automatically installed using npm install

You just add to add this flag to your build.hxml script :

--macro npm.Package.export("package.json")

Note that the macro will parse the package file, add dependencies to it, and then rewrite the whole json file.

This means that it may change formatting.

The process is incremental, though, which means that :

  • other dependencies you may have added manually will be kept.
  • unused dependencies will remain unless you remove them manually

Please also note that the dependency system currently doesn't manage package versions / SemVer.

Asynchronous programming (experimental)

Implementing util.Async allows to write typical asynchronous code in a "flat" way using the @async inline metadata.

This is very useful, avoiding superfluous indentations and braces / parenthesis mess in the context of linear, "single threaded" scripts...

For instance :

class Exemple implements util.Async {
  static function main(){
     var err,doc = @async model.create({ /*...*/ });
     if( err != null ){
        trace("error",err);  
     }else{
        trace("created doc",doc);
     }
  }
}

is the equivalent of:

class Exemple {
  static function main(){
     model.create({ /* ... */ }, function(err,doc){
     	if( err != null ){
           trace("error",err);  
        }else{
           trace("created doc",doc);
        }
     });
  }
}

See the (small) mongoose example for a more practical and complete sample.

You can also scope the Async macro only to some block by using util.Async.run({ \* flat code block / @async *\ }).

Contributing

We try to keep the externs as close as possible to their native APIs, while sticking as much as possible to the Haxe type / package system.

This means :

  • Splitting the APIs in modules so the structure is as close as possible to the native API docs. This should also allow most code examples to look as similar as possible in JS and in Haxe.
  • Using extern classes rather than typedefs when possible (typedefs should be used only for simple JS key/value objects such as option objects)
  • Using packages rather than static variables when possible (new js.npm.connect.CookieParser() rather than js.npm.Connect.cookieParser())
  • Assuming that in most cases, instantiation using simple JS calls (like var app = express()) is similar to using new in Haxe (like var app = new Express())

Including NPM packages

You can map your extern classes to an NPM package by implementing npm.Package.Require or npm.Package.RequireNamespace.

For example :

// js/npm/MyPackage.hx
package js.npm;
extern class MyPackage
implements npm.Package.Require<"my-package","*">
// Test.hx
var test = new js.npm.MyPackage();
// resulting Javascript output:
var js_npm_MyPackage = require('my-package');
var test = new js_npm_MyPackage();

Sometimes, a single require exports several objects that can be considered individual classes in Haxe.

In such cases you can use RequireNamespace:

// js/node/http/Server.hx
package js.node.http;
extern class Server
implements npm.Package.RequireNamespace<"http","*">
// resulting Javascript output:
var js_node_http_Server = require('http').Server;

The @:native metadata is supported with RequireNamespace

Todo

  • Continue integrating / cleaning / completing externs, mainly from nodejs_externs
  • Remove the core Node API in favor of hxnodejs
  • Better browserify integration (?)
  • Improve NPM integration (SemVer, less intrusive dependency export)
  • Publish to haxelib (see also https://github.com/HaxeFoundation/haxelib/issues/238)