{"id":20000451,"url":"https://github.com/knpwrs/falafelify","last_synced_at":"2025-05-04T15:32:22.461Z","repository":{"id":26680766,"uuid":"30137492","full_name":"knpwrs/falafelify","owner":"knpwrs","description":"A browserify transform which lets you run your JavaScript files through falafel.","archived":false,"fork":false,"pushed_at":"2017-02-08T22:12:23.000Z","size":20,"stargazers_count":4,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-08T07:42:58.835Z","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":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/knpwrs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-01T05:38:12.000Z","updated_at":"2019-04-24T05:29:46.000Z","dependencies_parsed_at":"2022-09-02T05:23:27.399Z","dependency_job_id":null,"html_url":"https://github.com/knpwrs/falafelify","commit_stats":null,"previous_names":["kenpowers/falafelify"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knpwrs%2Ffalafelify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knpwrs%2Ffalafelify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knpwrs%2Ffalafelify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knpwrs%2Ffalafelify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knpwrs","download_url":"https://codeload.github.com/knpwrs/falafelify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252356122,"owners_count":21734885,"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-11-13T05:14:47.243Z","updated_at":"2025-05-04T15:32:22.147Z","avatar_url":"https://github.com/knpwrs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# falafelify [![Build Status](https://travis-ci.org/KenPowers/falafelify.svg?branch=master)](https://travis-ci.org/KenPowers/falafelify) [![Coverage Status](https://coveralls.io/repos/KenPowers/falafelify/badge.svg?branch=master)](https://coveralls.io/r/KenPowers/falafelify?branch=master)\n\nServe up fresh [falafel][f] from your [browserify][b] bundles.\n\n## What?\n\nThis is a [browserify][b] [transform][t] that runs your files through\n[falafel][f]. Basically you can alter your scripts by modifying the abstract\nsyntax tree that they are parsed in to.\n\n## Installation\n\n```sh\nnpm i --save falafelify\n```\n\nOr if you want something a little more fresh:\n\n```sh\nnpm i --save KenPowers/falafelify\n```\n\n## Usage\n\nHere are some examples that I ~~stole~~ ~~borrowed~~ adapted from [falafel][f]\nas well as an original example (also available under the `examples`\ndirectory):\n\n### Wrap Arrays\n\nThis example shows how to wrap arrays (including nested arrays) in a function\ncall.\n\n`arrays.js`:\n\n```js\n(function () {\n  var xs = [1, 2, [3, 4]];\n  var ys = [5, 6];\n  console.dir([xs, ys]);\n})();\n```\n\n`build.js`:\n\n```js\nvar browserify = require('browserify'),\n    falafelify = require('falafelify'),\n    fs = require('fs');\n\n// Browserify build\nbrowserify('./arrays')\n  .transform(falafelify(function (node) {\n    if (node.type === 'ArrayExpression') {\n      node.update('fn(' + node.source() + ')');\n    }\n  }))\n  .bundle()\n  .pipe(fs.createWriteStream('out.js'));\n```\n\nRun `node build` and get the following:\n\n`out.js`:\n\n```js\n(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"\u0026\u0026require;if(!u\u0026\u0026a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"\u0026\u0026require;for(var o=0;o\u003cr.length;o++)s(r[o]);return s})({1:[function(require,module,exports){\n(function () {\n  var xs = fn([1, 2, fn([3, 4])]);\n  var ys = fn([5, 6]);\n  console.dir(fn([xs, ys]));\n})();\n\n},{}]},{},[1]);\n```\n\n### Custom Keywords\n\nThis example shows how to create a custom keyword. In this case `beep` is a\nunary operator which converts its argument to a `String` and uppercases it:\n\n`keywords.js`:\n\n```js\nconsole.log(beep 'boop', 'BOOP');\n```\n\n`build.js`:\n\n```js\nvar browserify = require('browserify'),\n    falafelify = require('falafelify'),\n    fs = require('fs');\n\n// Determines if a given identifier is a keyword\nfunction isKeyword(id) {\n  return id === 'beep';\n}\n\n// Browserify build, notice the `isKeyword` option passed to falafelify.\nbrowserify('./keywords')\n  .transform(falafelify({isKeyword: isKeyword}, function (node) {\n    if (node.type === 'UnaryExpression' \u0026\u0026 node.keyword === 'beep') {\n      node.update('String(' + node.argument.source() + ').toUppercase()');\n    }\n  }))\n  .bundle()\n  .pipe(fs.createWriteStream('out.js'));\n```\n\nRun `node build` and get the following:\n\n`out.js`:\n\n```js\n(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"\u0026\u0026require;if(!u\u0026\u0026a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"\u0026\u0026require;for(var o=0;o\u003cr.length;o++)s(r[o]);return s})({1:[function(require,module,exports){\nconsole.log(String('boop').toUppercase(), 'BOOP');\n\n},{}]},{},[1]);\n```\n\n### Async\n\nUnlike the regular [falafel][f], falafelify lets you use async functions as\nyour iterator using standard node callbacks (by default running 10\nasynchronous operations at a time). This example shows how to update ast nodes\nasynchronously while changing the limit from 10 to 20:\n\n`async.js`:\n\n```js\nconsole.log(2 + 2);\nconsole.log(2 - 2);\nconsole.log(2 * 2);\nconsole.log(2 / 2);\n```\n\n`build.js`:\n\n```js\nvar browserify = require('browserify'),\n    falafelify = require('falafelify'),\n    fs = require('fs');\n\n// Determines if a node represents a binary math expression\nfunction basicMath(node) {\n  return node.type === 'BinaryExpression'\n    \u0026\u0026 '+-*/'.indexOf(node.operator) \u003e -1\n    \u0026\u0026 node.left.type === 'Literal'\n    \u0026\u0026 node.right.type === 'Literal';\n}\n\n// Async function which, given a BinaryExpression node, performs basic binary\n// math expressions and updates the node with the calculated value.\nfunction evaluate(node, done) {\n  var o = node.operator, left = node.left.value, right = node.right.value;\n  setTimeout(function () {\n    if (o === '+') {\n      node.update(left + right);\n    } else if (o === '-') {\n      node.update(left - right);\n    } else if (o === '*') {\n      node.update(left * right);\n    } else if (o === '/') {\n      node.update(left / right);\n    } else {\n      return done(new Error('Invalid operator.'));\n    }\n    // Make sure you ALWAYS call done.\n    done();\n  }, 250);\n}\n\n// Browserify build\nbrowserify('./async')\n  // First argument is the iterator, second argument is the parallel limit.\n  .transform(falafelify(function (node, done) {\n    if (basicMath(node)) {\n      evaluate(node, done);\n    } else {\n      // Make sure you ALWAYS call done.\n      done();\n    }\n  }, 20))\n  .bundle()\n  .pipe(fs.createWriteStream('out.js'));\n```\n\nRun `node build` and get the following:\n\n`out.js`:\n\n```js\n(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"\u0026\u0026require;if(!u\u0026\u0026a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"\u0026\u0026require;for(var o=0;o\u003cr.length;o++)s(r[o]);return s})({1:[function(require,module,exports){\nconsole.log(4);\nconsole.log(0);\nconsole.log(4);\nconsole.log(1);\n\n},{}]},{},[1]);\n```\n\nOf course you could also be [evil][e] and use `eval`:\n\n```js\nfunction evaluate(node, done) {\n  setTimeout(function () {\n    node.update(eval(node.source()));\n    done();\n  }, 250);\n}\n```\n\nBy default falafelify will only run 10 asynchronous operations at the same\ntime. If this isn't enough for you then see the next section, *API*.\n\n## API\n\nAll of the following invocations are valid:\n\n```js\n// Just a function (callback optional)\nfalafelify(fn);\n// Options and function\nfalafelify(opts, fn);\n// Function and parallel limit (number, defaults to 10)\nfalafelify(fn, limit);\n// Options, function, and parallel limit (number, defaults to 10)\nfalafelify(opts, fn, limit);\n```\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Kenneth Powers\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n[b]: http://browserify.org/ \"browserify\"\n[e]: http://jshint.com/docs/options/#evil \"JSHint evil Option\"\n[f]: https://www.npmjs.com/package/falafel \"falafel\"\n[t]: https://github.com/substack/node-browserify/wiki/list-of-transforms \"List of browserify transforms.\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknpwrs%2Ffalafelify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknpwrs%2Ffalafelify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknpwrs%2Ffalafelify/lists"}