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

tea-script

v1.0.5

Published

Synchronous JavaScript

Downloads

18

Readme

TeaScript

TeaScript is a superset of JavaScript(ES 5) and it can be compiled into JavaScript. TeaScript adds a new operator ~ to simply and powerfully streamline asynchronous control flow. Say goodbye to callback pyramids finally.

Build Status

Sample

var count = 0;
function delayTask(interval, callback) {
  setTimeout(function() {
    callback(null, count++);
  }, interval);
}

for (var i = 0; i < 10; ++i) {
  console.log(new Date(), delayTask(1000, ~));
  console.log('step' + i);
}

Output:

Mon Oct 27 2014 20:58:26 GMT+0800 (CST) 0
step0
Mon Oct 27 2014 20:58:27 GMT+0800 (CST) 1
step1
Mon Oct 27 2014 20:58:28 GMT+0800 (CST) 2
step2
Mon Oct 27 2014 20:58:29 GMT+0800 (CST) 3
step3
Mon Oct 27 2014 20:58:30 GMT+0800 (CST) 4
step4
Mon Oct 27 2014 20:58:31 GMT+0800 (CST) 5
step5
Mon Oct 27 2014 20:58:32 GMT+0800 (CST) 6
step6
Mon Oct 27 2014 20:58:33 GMT+0800 (CST) 7
step7
Mon Oct 27 2014 20:58:34 GMT+0800 (CST) 8
step8
Mon Oct 27 2014 20:58:35 GMT+0800 (CST) 9
step9

Usage

// Install tea-script module globally
$ npm install -g tea-script
// Run a TeaScript file
$ tea script.tea
// Compile the tea script and save `.js` file to the same dir
$ tea --compile script.tea
// Learn more
$ tea --help

Write TeaScript is as easy as replacing callback functions the operator ~, and the result will be returned synchronously. Any error will be throwed.

Node Version

TeaScript requires node 0.11.x for the --harmony flag which exposes generators to your script. If you're running an earlier version of node you may install n, a node version manager to quickly install 0.11.x:

$ npm install -g n
$ n 0.11.12

$ tea script.tea

// or
$ tea --compile script.tea
$ node --harmony script.js

More examples

Before:

var async = require('async');
var userIds = [672, 282, 33, 4];
async.map(userIds, function(userId, callback) {
  User.findById(userId, function(err, user) {
    callback(err, user);
  });
}, function(err, users) {
  res.json(users);
});

Now:

var userIds = [672, 282, 33, 4];
res.json(userIds.map(function(userId) {
  return User.findById(userId, ~);
}));

Before:

User.findById(req.query.userId, function(err, user) {
    if (user) {
      user.getTasks(function(err, tasks) {
        if (tasks) {
          res.json(tasks);
        } else {
          res.json({ error: 'No tasks' });
        }
      });
    } else {
      res.json({ error: 'No user' });
    }
});

Now(with TeaScript):

var user = User.findById(req.query.userId, ~);
if (user) {
  var tasks = user.getTasks(~);
  if (tasks) {
    res.json(tasks);
  } else {
    res.json({ error: 'No tasks' });
  }
} else {
  res.json({ error: 'No user' });
}

Roadmap

  1. Plugins for Grunt, Gulp, Vim...
  2. More tests