{"id":16329974,"url":"https://github.com/luin/teascript","last_synced_at":"2025-03-22T22:31:34.526Z","repository":{"id":22480908,"uuid":"25820029","full_name":"luin/teascript","owner":"luin","description":"Synchronous JavaScript","archived":false,"fork":false,"pushed_at":"2014-11-02T07:08:15.000Z","size":252,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T15:21:33.839Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"misega/HTML5-Banners-Review-Site","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-27T13:21:24.000Z","updated_at":"2016-01-14T17:23:53.000Z","dependencies_parsed_at":"2022-08-21T05:31:10.087Z","dependency_job_id":null,"html_url":"https://github.com/luin/teascript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luin%2Fteascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luin%2Fteascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luin%2Fteascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luin%2Fteascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luin","download_url":"https://codeload.github.com/luin/teascript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245028605,"owners_count":20549545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T23:17:57.781Z","updated_at":"2025-03-22T22:31:34.266Z","avatar_url":"https://github.com/luin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TeaScript\nTeaScript 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.\n\n[![Build Status](https://travis-ci.org/luin/teascript.png?branch=master)](https://travis-ci.org/luin/teascript)\n\n## Sample\n\n```javascript\nvar count = 0;\nfunction delayTask(interval, callback) {\n  setTimeout(function() {\n    callback(null, count++);\n  }, interval);\n}\n\nfor (var i = 0; i \u003c 10; ++i) {\n  console.log(new Date(), delayTask(1000, ~));\n  console.log('step' + i);\n}\n```\n\nOutput:\n\n    Mon Oct 27 2014 20:58:26 GMT+0800 (CST) 0\n    step0\n    Mon Oct 27 2014 20:58:27 GMT+0800 (CST) 1\n    step1\n    Mon Oct 27 2014 20:58:28 GMT+0800 (CST) 2\n    step2\n    Mon Oct 27 2014 20:58:29 GMT+0800 (CST) 3\n    step3\n    Mon Oct 27 2014 20:58:30 GMT+0800 (CST) 4\n    step4\n    Mon Oct 27 2014 20:58:31 GMT+0800 (CST) 5\n    step5\n    Mon Oct 27 2014 20:58:32 GMT+0800 (CST) 6\n    step6\n    Mon Oct 27 2014 20:58:33 GMT+0800 (CST) 7\n    step7\n    Mon Oct 27 2014 20:58:34 GMT+0800 (CST) 8\n    step8\n    Mon Oct 27 2014 20:58:35 GMT+0800 (CST) 9\n    step9\n\n## Usage\n\n    // Install tea-script module globally\n    $ npm install -g tea-script\n    // Run a TeaScript file\n    $ tea script.tea\n    // Compile the tea script and save `.js` file to the same dir\n    $ tea --compile script.tea\n    // Learn more\n    $ tea --help\n\nWrite TeaScript is as easy as replacing callback functions the operator `~`, and the result will be returned synchronously. Any error will be throwed.\n\n## Node Version\n\nTeaScript 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](https://github.com/visionmedia/n), a node version manager to quickly install 0.11.x:\n\n    $ npm install -g n\n    $ n 0.11.12\n\n    $ tea script.tea\n\n    // or\n    $ tea --compile script.tea\n    $ node --harmony script.js\n\n## More examples\n\n### Before:\n\n```javascript\nvar async = require('async');\nvar userIds = [672, 282, 33, 4];\nasync.map(userIds, function(userId, callback) {\n  User.findById(userId, function(err, user) {\n    callback(err, user);\n  });\n}, function(err, users) {\n  res.json(users);\n});\n```\n\n### Now:\n\n```javascript\nvar userIds = [672, 282, 33, 4];\nres.json(userIds.map(function(userId) {\n  return User.findById(userId, ~);\n}));\n```\n\n### Before:\n\n```javascript\nUser.findById(req.query.userId, function(err, user) {\n    if (user) {\n      user.getTasks(function(err, tasks) {\n        if (tasks) {\n          res.json(tasks);\n        } else {\n          res.json({ error: 'No tasks' });\n        }\n      });\n    } else {\n      res.json({ error: 'No user' });\n    }\n});\n```\n\n### Now(with TeaScript):\n\n```javascript\nvar user = User.findById(req.query.userId, ~);\nif (user) {\n  var tasks = user.getTasks(~);\n  if (tasks) {\n    res.json(tasks);\n  } else {\n    res.json({ error: 'No tasks' });\n  }\n} else {\n  res.json({ error: 'No user' });\n}\n```\n\n\n## Roadmap\n\n1. Plugins for Grunt, Gulp, Vim...\n2. More tests\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluin%2Fteascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluin%2Fteascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluin%2Fteascript/lists"}