{"_id":"genData","_rev":"26-3896fcb40d28e2113d63150b1507d88e","name":"genData","description":"A normalization pattern to build, query, and manipulate everything.","dist-tags":{"latest":"3.1.0"},"versions":{"1.2.0":{"name":"genData","version":"1.2.0","description":"A normalization pattern to build, query, and manipulate everything.","keywords":["data","dataset","parse","query","convert","translate","generator"],"author":{"name":"Bemi Faison","email":"bemson@gmail.com","url":"https://github.com/bemson"},"repository":{"type":"git","url":"git://github.com/bemson/genData.git"},"licenses":[{"type":"MIT","url":"https://github.com/bemson/genData/raw/master/LICENSE"}],"main":"src/gendata.js","_npmUser":{"name":"bemson","email":"bemson@gmail.com"},"_id":"genData@1.2.0","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.104","_nodeVersion":"v0.6.0","_defaultsLoaded":true,"dist":{"shasum":"72e31ffed7c01b7cae5f840589c2fff746d228b2","tarball":"https://registry.npmjs.org/genData/-/genData-1.2.0.tgz","integrity":"sha512-YaVA1e1JAPD+jJXTH5ATJE0CdmAXL4/LNIe4nE5f0pnIoHAZVxnWlMJOOZ+r/qZZ0CuIix8w/Ee8eGLVnm9qaw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEArAC3yPppN2vMufBHuWGrjtpkwhSE7G4IYUDH2zV5BAiEAuVxrLxTAhO2o7b3EAtBF9hVo1OJ0yb/PIqdb3Z1Bchw="}]},"maintainers":[{"name":"bemson","email":"bemson@gmail.com"}],"directories":{}},"1.2.1":{"name":"genData","version":"1.2.1","description":"A normalization pattern to build, query, and manipulate everything.","keywords":["data","dataset","parse","query","convert","translate","generator"],"author":{"name":"Bemi Faison","email":"bemson@gmail.com","url":"https://github.com/bemson"},"repository":{"type":"git","url":"git://github.com/bemson/genData.git"},"licenses":[{"type":"MIT","url":"https://github.com/bemson/genData/raw/master/LICENSE"}],"main":"src/gendata.js","_npmUser":{"name":"bemson","email":"bemson@gmail.com"},"_id":"genData@1.2.1","dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.10","_nodeVersion":"v0.6.13","_defaultsLoaded":true,"dist":{"shasum":"d4f50f1da9c9b42c75bd82c77477b881942a733b","tarball":"https://registry.npmjs.org/genData/-/genData-1.2.1.tgz","integrity":"sha512-aMH1PqjKrJaJ0gX8dVbANGgT0IpfcTmcIHvxcXfjfiS7XHvjxHGlvSTy8G4NJQHUZa55Gy1bIJd+l8s8BIeKtQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGTa0s4YGR2KgF2Drz+wk2fys9EyISaff3I1HnqMvp0AAiEA86vU1t424ZLmyBJRL/kBeZI1rqpTLahvwL5HsqaWNbY="}]},"maintainers":[{"name":"bemson","email":"bemson@gmail.com"}],"directories":{}},"2.0.0":{"name":"genData","version":"2.0.0","description":"A normalization pattern to build, query, and manipulate everything.","keywords":["data","filter","iterate","parse","query","generate"],"author":{"name":"Bemi Faison","email":"bemson@gmail.com","url":"https://github.com/bemson"},"repository":{"type":"git","url":"git://github.com/bemson/genData.git"},"licenses":[{"type":"MIT","url":"https://github.com/bemson/genData/raw/master/LICENSE"}],"main":"src/gendata.js","_npmUser":{"name":"bemson","email":"bemson@gmail.com"},"_id":"genData@2.0.0","dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.21","_nodeVersion":"v0.6.18","_defaultsLoaded":true,"dist":{"shasum":"58520e2a7d1b314e479de3ec96043c3df6341342","tarball":"https://registry.npmjs.org/genData/-/genData-2.0.0.tgz","integrity":"sha512-nO0WkdYpaApJz0aH5Y77895BqxYGCxiKd/sT6LK1Lu1X/U0vP7yneCBGAU17Y4V/Y035cQG6UavWMkWObxT5CQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDmlZVS0ueMien1kpfvOh2UKnvkKlFN9kfYWG4b+qNwVAiAk5RAcS2ips6kdK4L/tT8PSdBXJdx8K+j/AyvJaXkJuw=="}]},"maintainers":[{"name":"bemson","email":"bemson@gmail.com"}],"directories":{}},"2.0.1":{"name":"genData","version":"2.0.1","description":"A normalization pattern to build, query, and manipulate everything.","keywords":["data","filter","iterate","parse","query","generate"],"author":{"name":"Bemi Faison","email":"bemson@gmail.com","url":"https://github.com/bemson"},"repository":{"type":"git","url":"git://github.com/bemson/genData.git"},"licenses":[{"type":"MIT","url":"https://github.com/bemson/genData/raw/master/LICENSE"}],"main":"src/gendata.js","_npmUser":{"name":"bemson","email":"bemson@gmail.com"},"_id":"genData@2.0.1","dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.21","_nodeVersion":"v0.6.18","_defaultsLoaded":true,"dist":{"shasum":"1b929bc64b014dc4e6fcf4f4931aeb0515e57230","tarball":"https://registry.npmjs.org/genData/-/genData-2.0.1.tgz","integrity":"sha512-k9AAOqFO+oUIe2deL7Ob5hxCyC1jZ2fBMStU1Hz9TXS03azKzMXCAFSeQ8LHde99T2GXahGAAMpKuKfWFnOT6w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCjOLChFCUs3YZxg1dLzLqTZ/qRb6fpivdkyzJ9PH+DWwIgbE9TuH6b3gr/ST0uPpUSRbweB4eHD5yM+cnOindyHxE="}]},"maintainers":[{"name":"bemson","email":"bemson@gmail.com"}],"directories":{}},"3.0.0":{"name":"genData","version":"3.0.0","description":"A normalization pattern to build, query, and manipulate everything.","homepage":"github.com/bemson/genData","main":"src/gendata.js","scripts":{"test":"node_modules/.bin/mocha"},"devDependencies":{"mocha":"~1.7","sinon":"~1.5","chai":"~1.4","sinon-chai":"~2.3"},"keywords":["data","iterate","select","generate","recursive"],"author":{"name":"Bemi Faison","email":"bemson@gmail.com","url":"https://github.com/bemson"},"repository":{"type":"git","url":"https://github.com/bemson/genData.git"},"engines":{"node":">= 0.5.0"},"license":"MIT","_id":"genData@3.0.0","dist":{"shasum":"397d85e9385aaf8d6a6982c1d0f9ab51fff7c00a","tarball":"https://registry.npmjs.org/genData/-/genData-3.0.0.tgz","integrity":"sha512-rslY5fEyRhzsAdtpeQPWiX0DmZmY0rItP1xl24g09hge8fStFJXdeB03BerFC/jvDMEy6Vkpfe7Yx7dzuZFTjg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCNenIM3WlixnDpQGhpCsG0wslZdXsHPuaY9eZivVgQugIhAPpF3O0ZXBT5SZDIHJH7dk5bfPqT7wNTnnVcJK9tnCx9"}]},"_npmVersion":"1.1.63","_npmUser":{"name":"bemson","email":"bemson@gmail.com"},"maintainers":[{"name":"bemson","email":"bemson@gmail.com"}],"directories":{}},"3.1.0":{"name":"genData","version":"3.1.0","description":"A normalization pattern to build, query, and manipulate everything.","homepage":"github.com/bemson/genData","main":"src/gendata.js","scripts":{"test":"node_modules/.bin/mocha"},"devDependencies":{"mocha":"~1.7","sinon":"~1.5","chai":"~1.4","sinon-chai":"~2.3"},"keywords":["data","iterate","select","generate","recursive"],"author":{"name":"Bemi Faison","email":"bemson@gmail.com","url":"https://github.com/bemson"},"repository":{"type":"git","url":"https://github.com/bemson/genData.git"},"engines":{"node":">= 0.5.0"},"license":"MIT","_id":"genData@3.1.0","dist":{"shasum":"d91c163ef57ec71d452887b4c49ea35d3af2f058","tarball":"https://registry.npmjs.org/genData/-/genData-3.1.0.tgz","integrity":"sha512-rdUS7F0ORqPtTMz5y9zEvcpwJaTlFWlw9qlAwOSa3bPshqGArg+0JJz7tfSmvBrz7pcYkJ0EFwO6Ky4+y6p9Dg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDmeJTaP+MKoi2DuF63rr1qzDHQlAg8dWQWUm2+wGs5TwIhAMrey36k2kSAUGrWOQfmzOH9E+stOFBIxx2dLMrZVoJZ"}]},"_npmVersion":"1.1.63","_npmUser":{"name":"bemson","email":"bemson@gmail.com"},"maintainers":[{"name":"bemson","email":"bemson@gmail.com"}],"directories":{}}},"readme":"# genData\n\nAn iteration utility with a rich callback environment.\n\n[![Build Status](https://travis-ci.org/bemson/genData.png)](https://travis-ci.org/bemson/genData)\n\n(1/10/13)\nversion 3.1.0\nby Bemi Faison\n\n## Usage\n\ngenData iterates a _queue_, beginning with the first parameter, then it's non-inherited members, then their non-inherited members, and so on - recursively and in depth-first order. Below is what genData outputs when a callback simply returns the current iteration value.\n\n```js\ngenData(\n  [1,[2,3]],\n  function (name, value) {\n    return value;\n  }\n);\n// [[1,[2,3]], 1, [2,3], 2, 3]\n```\n\nNote how the first element is the original value, passed to genData. Also, note that genData returns an array, which is the default container for each callback's return value (except `undefined`).\n\n\n### Callbacks\n\nCallbacks are functions passed to genData, after the first parameter. genData executes them in order, and scoped to a uniquely generated \"data\" objects - representing the name and value of the current iteration. Your callback can use either the first two arguments, or the scope object in it's logic, as follows.\n\n```js\ngenData(\n  [1,2],\n  function () {\n    if (this.value === 2) {\n      return 'world!';\n    }\n  },\n  function (name, value) {\n    if (value === 1) {\n      return 'hello';\n    }\n  }\n);\n// ['hello', 'world!']\n```\n\n\n### Callback Signature\n\nCallbacks receive four arguments per iterated value:\n\n  1. The name (or key) corresponding this value. This is an empty string for the first iteration.\n  2. The value being iterated. This is the first parameter passed to genData, for the first iteration.\n  3. The data object which sourced the current iteration. This is `undefined`, for the first iteration.\n  4. The iteration object, with various flags to use in your logic.\n\n\n### Iteration Flags\n\n\n#### flags.allowUndefined\n\nSet this flag to a truthy value, if you want genData to capture the result of callbacks that return `undefined` (which includes callbacks with no `return` statement). This flag is reset to 0 before executing each callback. Below, a callback allows undefined values, which are then captured in the returned array.\n\n```js\ngenData(\n  ['foo', 'bar'],\n  function (name, value) {\n    return value;\n  },\n  function (name, value, parent, flags) {\n    flags.allowUndefined = 1;\n  }\n);\n// ['foo', undefined, 'bar', undefined]\n```\n\n\n#### flags.args\n\nA simple array of non-function values passed to genData, _after_ the first parameter (the value to iterate). Below, callbacks use arguments to build the array results.\n\n```js\ngenData(\n  ['John', 'Sally'],\n  'Hello ',\n  function (name, value, parent, flags) {\n    if (typeof value === 'string') {\n      return flags.args[0] + value + flags.args[1];\n    }\n  },\n  '. How are you?'\n);\n// ['Hello John. How are you?', 'Hello Sally. How are you?']\n```\n\n\n#### flags.breaks\n\nSimilar to the JavaScript `break` statement, genData will abort processing it's queue when this flag is truthy. This flag persists between callbacks, but is reset (to 0) at the beginning of each iteration. Below, a callback tells genData to stop and return the first number found.\n\n```js\ngenData(\n  ['a', 3, 'b', 'c', 'd'],\n  function (name, value, parent, flags) {\n    if (typeof value === 'number') {\n      flags.breaks = 1;\n      return value;\n    }\n  }\n);\n// [3]\n```\n\n\n#### flags.continues\n\nSimilar to the JavaScript `continue` statement, set this flag to a truthy value when you want to end the current iteration and begin the next one. Below, a callback uses this flag to avoid runtime errors.\n\n```js\ngenData(\n  [1.1, 'a', 2.5],\n  function (name, value, parent, flags) {\n    if (typeof value !== 'number') {\n      flags.callbacks = 1;\n    }\n  },\n  function (name, value) {\n    return value.toFixed(0);\n  }\n);\n// ['1','3']\n```\n\n#### flags.loop\n\nThis is a number, reflecting genData's iteration count. The value is 0 initially and increments per iteration.\n\n#### flags.params\n\nA simple array of what was passed to genData. Mutating this array has no impact on genData's iteration or other flags. Below, demonstrates how to use this flag, along with `flag.continues`, in order to custom invoke functions that genData would otherwise assume a callback.\n\n```js\nfunction logger(text) {\n  console.log(text);\n}\n\ngenData(\n  ['hello', 'world!'],\n  function (name, value, parent, flags) {\n    flags.continues = 1;\n    if (typeof value === 'string') {\n      flags.params[2](value);\n    }\n  },\n  logger\n);\n\n// (console output)\n// hello\n// world!\n\n```\n\n#### flags.queued\n\nThis is a number, reflecting genData's queue of pending iterations. Because genData adds to the queue after each iteration, a value of 0 does not mean the end of genData's process.\n\n#### flags.returns\n\nThis flag is an array by default, and is what genData returns. This flag persists between callbacks, until genData completes processing a given value. Note that genData will ignore returned callback values, when this flag is not an Array. Below, demonstrates how this flag can change genData's return value.\n\n```js\ngenData(\n  ['e', 'c', 'h', 'o'],\n  function (name, value, parent, flags) {\n    if (!flags.loop) {\n      flags.returns = '';\n    }\n    if (typeof value === 'string') {\n      flags.returns += value;\n    }\n  }\n);\n// 'echo'\n```\n\n#### flags.source\n\nThis value is scanned by genData (at the end of every iteration), in order to add more non-inherited members to genData's queue. By default, this flag reflects the second argument of the callback signature, or the `value` property of the callback scope. Below, this flag is used to make a non-object value iterable.\n\n```js\ngenData(\n  'hello world!',\n  function (name, value, parent, flags) {\n    if (typeof value === 'string' && value.length > 1) {\n      flags.source = value.split('');\n      flags.callbacks = false;\n    }\n  },\n  function (name, value) {\n    if (typeof value === 'string') {\n      return value.toUpperCase();\n    }\n  }\n);\n// ['H', 'E', 'L', 'L', 'O', ' ', 'W', 'O', 'R', 'L', 'D', '!']\n```\n\n\n### Spawning genData Generators\n\nThe static `.spawn()` method expands upon the concept of currying functions, by also extending genData's prototype chain. Functions _spawned_ by genData are called \"generators\", which also host the `.spawn()` method for further spawning. Below, two generators are spawned, in order to preserve callback configurations and isolate additions to genData's prototype.\n\n```js\nvar\n  nums = genData.spawn(function (name, value, parent, flags) {\n    if (typeof value !== 'number') {\n      flags.callbacks = false;\n    }\n  }),\n  calc = nums.spawn(function () {\n    return this.square();\n  })\n;\n\ncalc.prototype.square = function () {\n  return this.value * this.value;\n};\n\ncalc(['foo', 2, 'bar', 10]); // [4, 100]\n```\n\nGenerators accept the same argument signature as genData. Continuing with the example above, the `calc()` generator is refined to prune numbers below 100.\n\n```js\ncalc(,\n  ['foo', 2, 'bar', 10],\n  function (name, value, parent, flags) {\n    flags.returns = flags.returns.filter(function (value) {\n      return value >= 100;\n    });\n  }\n);\n// [100]\n```\n\nNote: While spawning does allow you to curry values to the iteration flag \"args\", this practice is not recommended.\n\n## Installation\n\n### Node\n\nUse [npm](http://npmjs.org/) to install the \"genData\" package, with `npm install genData`. Then, simply require and use the function directly.\n\n```js\nvar genData = require('genData');\n\n/* genData(stuff, callbacks, arguments, ...) */\n```\n\n### AMD\n\ngenData anonymously registers itself as an [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) function. Assuming you configured your loader to map the module id \"genData\" (recommended), then you could include genData in either a module or a top-level script, as follows:\n\n```js\n// module\ndefine(function (require, module, exports) {\n  var genData = require('genData');\n\n  /* genData(stuff, callbacks, arguments, ...) */  \n});\n\n// top-level logic\nrequire(['genData'], function (genData) {\n  /* genData(stuff, callbacks, arguments, ...) */  \n});\n```\n\n### Browser\n\nIf you include genData directly in a web page - via the `<script>` tag - it will be available in the global scope. For these kind of static deployments, the minified is recommended.\n\n```html\n  <script type=\"text/javascript\" src=\"somepath/gendata-min.js\"></script>\n  <script type=\"text/javascript\">\n    /* genData(stuff, callbacks, arguments, ...) */\n  </script>\n```\n\n\n## Files\n\n  * gendata-min.js - genData source file (minified with [UglifyJS](http://marijnhaverbeke.nl/uglifyjs))\n  * LICENSE - The legal terms and conditions under which this software may be used\n  * README.md - This readme file\n  * src/ - Directory containing the genData source code\n  * test/ - Directory containing test files written in the [Mocha](http://visionmedia.github.com/mocha/) framework\n\n\n## License\n\ngenData is available under the terms of the [MIT-License](http://en.wikipedia.org/wiki/MIT_License#License_terms).\n\nCopyright, Bemi Faison","maintainers":[{"name":"bemson","email":"bemson@gmail.com"}],"time":{"modified":"2022-06-18T05:17:53.822Z","created":"2011-11-22T20:12:33.043Z","1.2.0":"2011-11-22T20:12:39.860Z","1.2.1":"2012-04-20T21:36:56.726Z","2.0.0":"2012-05-22T21:25:27.389Z","2.0.1":"2012-06-30T21:34:53.065Z","3.0.0":"2013-01-08T10:47:23.890Z","3.1.0":"2013-01-14T20:57:17.578Z","3.1.1":"2013-08-27T07:52:34.200Z"},"author":{"name":"Bemi Faison","email":"bemson@gmail.com","url":"https://github.com/bemson"},"repository":{"type":"git","url":"https://github.com/bemson/genData.git"},"readmeFilename":""}