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

ham

v0.1.1

Published

A Hammier Javascript

Downloads

4

Readme

Ham -- an altJS language

Ham is another altJS language, similar to CoffeeScript. What makes Ham different is that it is written as a PEG, and does not have significant whitespace. Ham looks very similar to Javascript at first, but offers (hopefully) many useful features.

Ham was written using the Canopy PEG Parser Generator, and Javascript. I am currently working towards self-hosting Ham but it is not quite there yet.

Ham is written in an MVC style manner, where model is the AST, view is the javascript translations (using ejs templates), and the controller is the tree translators. This makes Ham extremely easy to hack on, and fun!

Syntax

Since Ham is extremely similar to Javascript, you can get almost perfect syntax hilighting for free by using the Javascript hilighters, which is a pretty neat side effect.

Array Ranges and Slices

Ham supports python style list ranges and slicing.

var range = [1..5];

range === [1, 2, 3, 4, 5];    // true
range[1:] === [2, 3, 4, 5];   // true
range[:4] === [1, 2, 3, 4];   // true
range[::2] === [1, 3, 5];     // true

List Comprehensions

Ham supports list comprehensions, similar in style to Haskell.

var cross = [x*y | x <- range, y <- range[::-1]];

Friendly Lambda's

Ham makes it fun to use lambda's.

var sum = |x, y| { return x + y; }

// If the body of the lambda is a single expression, 
// then the `return` statement and semicolon can be dropped.
var sum = |x, y| { x + y }

// Lambda's are an easy way to iterate a list:
[1, 2, 3].each(|| { console.log('repeating'); });

// If the lambda takes no parameters, the `||` can be dropped.
[1, 2, 3].each({ console.log('repeating');});

// When invoking a function with a lambda as the _only_ parameter, the parentheses can be dropped
[1, 2, 3].each {
   console.log('repeating');
};

Classical Style Inheritence

Some people would prefer to use Classical Inheritence instead of Javascript's prototypical inheritence, that's fine:

class Hamburger extends MeatMeal {
   eat: { console.log('om nom nom'); }
};

// Ham just uses Backbone style .extend() for inheritence, so this translates easily to:
// var Hamburger = MeatMeal.extend({ ... });

Prototype shortcut

Stolen from Coffeescript, is the prototype shortcut:

String::startsWith = |str| { this.substr(0, str.length) === str };

What else is comming?

Types

Would be nice to have some inference at compile time, with contracts at runtime for what couldn't be inferred.

var x:string = 3; // TypeError -> typeof "x" is string.
var sum = |x:num, y:num| { x + y }; // we could infer the return type easily here
var idk = ||:string { "hello" }; // I'm not sold on the return type syntax here

Imports

I like python style imports, but I think it might be hard/impossible to reconcile it with CommonJS style require. Another option is to rewrite a CommonJS style require for the browser, similar to browserify.

import Backbone, _ from 'vendor/backbone'; // would work great for browser, but hard for CommonJS

Decorators

I also sometimes find myself with a need for python style Decorators, so Ham will have some form of them.

@watch(notify_change)
var the_ghost_man = 3;

Unary Operators

Yeah, I haven't gotten around to unary operators yet. I've been focussing on the cool stuff for now.

Loops

I haven't implemented while or for loops yet, as I am still experimenting with syntax for them. I've been getting by largely with the combination of ranges and list comprehensions with .each.

Usage

npm install -g ham Then write some Ham.js code, and ham <filename> to run it.