{"_id":"array-index","_rev":"81630","name":"array-index","description":"Invoke getter/setter functions on array-like objects","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"time":{"modified":"2021-06-03T10:26:03.000Z","created":"2012-06-14T07:01:43.859Z","1.0.0":"2016-01-03T03:22:26.529Z","0.9.1":"2015-12-29T19:46:32.763Z","0.9.0":"2015-12-28T07:39:04.928Z","0.2.0":"2015-12-02T21:35:05.242Z","0.1.1":"2014-11-03T19:53:55.250Z","0.1.0":"2013-12-02T04:12:10.463Z","0.0.4":"2012-09-27T21:14:13.809Z","0.0.3":"2012-09-16T01:26:12.066Z","0.0.2":"2012-09-15T18:56:49.121Z","0.0.1":"2012-06-14T07:01:43.859Z"},"users":{},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"versions":{"1.0.0":{"name":"array-index","description":"Invoke getter/setter functions on array-like objects","keywords":["index","array","getter","setter","proxy"],"version":"1.0.0","license":"MIT","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"main":"index.js","scripts":{"test":"node test"},"dependencies":{"debug":"^2.2.0","es6-symbol":"^3.0.2"},"engines":{"node":"*"},"gitHead":"4b3cc059c70eefd8ef2a0d4213d681b671eb3d11","bugs":{"url":"https://github.com/TooTallNate/array-index/issues"},"homepage":"https://github.com/TooTallNate/array-index#readme","_id":"array-index@1.0.0","_shasum":"ec56a749ee103e4e08c790b9c353df16055b97f9","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.3.0","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"dist":{"shasum":"ec56a749ee103e4e08c790b9c353df16055b97f9","size":5653,"noattachment":false,"key":"/array-index/-/array-index-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/array-index/download/array-index-1.0.0.tgz"},"directories":{},"publish_time":1451791346529,"_cnpm_publish_time":1451791346529,"_hasShrinkwrap":false},"0.9.1":{"name":"array-index","description":"Invoke getter/setter functions on array-like objects","keywords":["index","array","getter","setter","proxy"],"version":"0.9.1","license":"MIT","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"main":"index.js","scripts":{"test":"node test"},"dependencies":{"debug":"*","es6-symbol":"^3.0.2","util-deprecate":"^1.0.2"},"engines":{"node":"*"},"gitHead":"3c213321cb3485b97e04d8a334866ae53d8da0eb","bugs":{"url":"https://github.com/TooTallNate/array-index/issues"},"homepage":"https://github.com/TooTallNate/array-index#readme","_id":"array-index@0.9.1","_shasum":"dc04302ce5afd005b685031f2013701e00f2a61b","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.0","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"dist":{"shasum":"dc04302ce5afd005b685031f2013701e00f2a61b","size":5845,"noattachment":false,"key":"/array-index/-/array-index-0.9.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/array-index/download/array-index-0.9.1.tgz"},"directories":{},"publish_time":1451418392763,"_cnpm_publish_time":1451418392763,"_hasShrinkwrap":false},"0.9.0":{"name":"array-index","description":"Invoke getter/setter functions on array-like objects","keywords":["index","array","getter","setter","proxy"],"version":"0.9.0","license":"MIT","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"main":"index.js","scripts":{"test":"node test"},"dependencies":{"debug":"*","es6-symbol":"^3.0.2","util-deprecate":"^1.0.2"},"engines":{"node":"*"},"gitHead":"a4bba00a92c8cecfd478c25151870a94f58fd245","bugs":{"url":"https://github.com/TooTallNate/array-index/issues"},"homepage":"https://github.com/TooTallNate/array-index#readme","_id":"array-index@0.9.0","_shasum":"d8a65c73cbd8c1a8c7581739453ee6c2645419f0","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.0","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"dist":{"shasum":"d8a65c73cbd8c1a8c7581739453ee6c2645419f0","size":5584,"noattachment":false,"key":"/array-index/-/array-index-0.9.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/array-index/download/array-index-0.9.0.tgz"},"directories":{},"publish_time":1451288344928,"_cnpm_publish_time":1451288344928,"_hasShrinkwrap":false},"0.2.0":{"name":"array-index","description":"Invoke getter/setter functions on array-like objects","keywords":["index","array","getter","setter","proxy"],"version":"0.2.0","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"main":"index.js","scripts":{"test":"node test"},"dependencies":{"debug":"*"},"engines":{"node":"*"},"gitHead":"9c02a7b7280824765ae9f279da5d9fa495340832","bugs":{"url":"https://github.com/TooTallNate/array-index/issues"},"homepage":"https://github.com/TooTallNate/array-index#readme","_id":"array-index@0.2.0","_shasum":"8c1249aa7edde55cc2de45660aad0cbe0de39d67","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.0","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"dist":{"shasum":"8c1249aa7edde55cc2de45660aad0cbe0de39d67","size":5019,"noattachment":false,"key":"/array-index/-/array-index-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/array-index/download/array-index-0.2.0.tgz"},"directories":{},"publish_time":1449092105242,"_cnpm_publish_time":1449092105242,"_hasShrinkwrap":false},"0.1.1":{"name":"array-index","description":"Invoke getter/setter functions on array-like objects","keywords":["index","array","getter","setter","proxy"],"version":"0.1.1","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"main":"index.js","scripts":{"test":"node test"},"dependencies":{"debug":"*"},"engines":{"node":"*"},"gitHead":"65a5d884f25b4b7a1608e367d715d713dbd3b3d6","bugs":{"url":"https://github.com/TooTallNate/array-index/issues"},"homepage":"https://github.com/TooTallNate/array-index","_id":"array-index@0.1.1","_shasum":"4d5eaf06cc3d925847cd73d1535c217ba306d3e1","_from":".","_npmVersion":"2.1.3","_nodeVersion":"0.10.32","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"dist":{"shasum":"4d5eaf06cc3d925847cd73d1535c217ba306d3e1","size":4837,"noattachment":false,"key":"/array-index/-/array-index-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/array-index/download/array-index-0.1.1.tgz"},"directories":{},"publish_time":1415044435250,"_cnpm_publish_time":1415044435250,"_hasShrinkwrap":false},"0.1.0":{"name":"array-index","description":"Invoke getter/setter functions on array-like objects","keywords":["index","array","getter","setter","proxy"],"version":"0.1.0","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"main":"index.js","scripts":{"test":"node test"},"dependencies":{"debug":"*"},"engines":{"node":"*"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/TooTallNate/array-index/issues"},"homepage":"https://github.com/TooTallNate/array-index","_id":"array-index@0.1.0","dist":{"shasum":"8a628918f802cf32bb696d7fc7762e135e7d926d","size":4700,"noattachment":false,"key":"/array-index/-/array-index-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/array-index/download/array-index-0.1.0.tgz"},"_from":".","_npmVersion":"1.3.14","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1385957530463,"_hasShrinkwrap":false,"_cnpm_publish_time":1385957530463},"0.0.4":{"name":"array-index","description":"Invoke getter/setter functions on array-like objects","keywords":["index","array","getter","setter","proxy"],"version":"0.0.4","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"main":"./index.js","scripts":{"test":"node test"},"dependencies":{"debug":"*"},"engines":{"node":"*"},"_id":"array-index@0.0.4","dist":{"shasum":"a31894074689d2f852ea33bc24a04124ed2b9927","size":4265,"noattachment":false,"key":"/array-index/-/array-index-0.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/array-index/download/array-index-0.0.4.tgz"},"_npmVersion":"1.1.62","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1348780453809,"_hasShrinkwrap":false,"_cnpm_publish_time":1348780453809},"0.0.3":{"name":"array-index","description":"Invoke getter/setter functions on array-like objects","keywords":["index","array","getter","setter","proxy"],"version":"0.0.3","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"main":"./index.js","scripts":{"test":"node test"},"dependencies":{"debug":"*"},"engines":{"node":"*"},"_id":"array-index@0.0.3","dist":{"shasum":"6ad1230aab45a000933b0737ff0a15e13a33a5e6","size":3263,"noattachment":false,"key":"/array-index/-/array-index-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/array-index/download/array-index-0.0.3.tgz"},"_npmVersion":"1.1.57","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1347758772066,"_hasShrinkwrap":false,"_cnpm_publish_time":1347758772066},"0.0.2":{"name":"array-index","description":"Invoke getter/setter functions on array-like objects","keywords":["index","array","getter","setter","proxy"],"version":"0.0.2","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"main":"./index.js","scripts":{"test":"node test"},"dependencies":{"debug":"*"},"engines":{"node":"*"},"_id":"array-index@0.0.2","dist":{"shasum":"7c163e2055b617820b8c43b655d33c471dcd2154","size":2832,"noattachment":false,"key":"/array-index/-/array-index-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/array-index/download/array-index-0.0.2.tgz"},"_npmVersion":"1.1.57","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1347735409121,"_hasShrinkwrap":false,"_cnpm_publish_time":1347735409121},"0.0.1":{"name":"array-index","description":"Invoke getter/setter functions on array-like objects","keywords":["index","array","getter","setter","proxy"],"version":"0.0.1","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/array-index.git"},"main":"./index.js","scripts":{"test":"node test"},"dependencies":{"debug":"*"},"engines":{"node":"*"},"_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"_id":"array-index@0.0.1","devDependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.25","_nodeVersion":"v0.7.10","_defaultsLoaded":true,"dist":{"shasum":"50fb00acc519286b828db7721aeb84b4c4513b84","size":2415,"noattachment":false,"key":"/array-index/-/array-index-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/array-index/download/array-index-0.0.1.tgz"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1339657303859,"_hasShrinkwrap":false,"_cnpm_publish_time":1339657303859}},"readme":"array-index\n===========\n### Invoke getter/setter functions on array-like objects\n[![Build Status](https://secure.travis-ci.org/TooTallNate/array-index.svg)](http://travis-ci.org/TooTallNate/array-index)\n\n\nThis little module provides an `ArrayIndex` constructor function that you can\ninherit from with your own objects. When a numbered property gets read, then the\n`ArrayIndex.get` function on the object will be invoked. When a numbered property gets\nset, then the `ArrayIndex.set` function on the object will be invoked.\n\n\nInstallation\n------------\n\nInstall with `npm`:\n\n``` bash\n$ npm install array-index\n```\n\n\nExamples\n--------\n\nA quick silly example, using `Math.sqrt()` for the \"getter\":\n\n``` js\nvar ArrayIndex = require('array-index');\n\n// let's just create a singleton instance.\nvar a = new ArrayIndex();\n\n// the \"ArrayIndex.get\" function is invoked for each \"a[n]\" access.\n// it is given a single argument, the \"index\" currently being accessed.\n// so here, we're passing in the `Math.sqrt()` function, so accessing\n// \"a[9]\" will return `Math.sqrt(9)`.\na[ArrayIndex.get] = Math.sqrt;\n\n// the \"ArrayIndex.get\" and \"ArrayIndex.set\" functions are only invoked up\n// to \"a.length\", so we must set that manually.\na.length = 10;\n\nconsole.log(a);\n// [ 0,\n//   1,\n//   1.4142135623730951,\n//   1.7320508075688772,\n//   2,\n//   2.23606797749979,\n//   2.449489742783178,\n//   2.6457513110645907,\n//   2.8284271247461903,\n//   3 ]\n```\n\nHere's an example of creating a subclass of `ArrayIndex` using `util.inherits()`:\n\n``` js\nvar ArrayIndex = require('array-index');\nvar inherits = require('util').inherits;\n\nfunction MyArray (length) {\n  // be sure to call the ArrayIndex constructor in your own constructor\n  ArrayIndex.call(this, length);\n\n  // the \"set\" object will contain values at indexes previously set,\n  // so that they can be returned in the \"getter\" function. This is just a\n  // silly example, your subclass will have more meaningful logic.\n  Object.defineProperty(this, 'set', {\n    value: Object.create(null),\n    enumerable: false\n  });\n}\n\n// inherit from the ArrayIndex's prototype\ninherits(MyArray, ArrayIndex);\n\nMyArray.prototype[ArrayIndex.get] = function (index) {\n  if (index in this.set) return this.set[index];\n  return index * 2;\n};\n\nMyArray.prototype[ArrayIndex.set] = function (index, v) {\n  this.set[index] = v;\n};\n\n\n// and now you can create some instances\nvar a = new MyArray(15);\na[9] = a[10] = a[14] = '_';\na[0] = 'nate';\n\nconsole.log(a);\n// [ 'nate', 2, 4, 6, 8, 10, 12, 14, 16, '_', '_', 22, 24, 26, '_' ]\n```\n\nAPI\n---\n\nThe `ArrayIndex` base class is meant to be subclassed, but it also has a few\nconvenient functions built-in.\n\n### \"length\" → Number\n\nThe length of the ArrayIndex instance. The `ArrayIndex.get` and `ArrayIndex.set` functions will\nonly be invoked on the object up to this \"length\". You may set this length at any\ntime to adjust the amount range where the getters/setters will be invoked.\n\n### \"toArray()\" → Array\n\nReturns a new regular Array instance with the same values that this ArrayIndex\nclass would have. This function calls the `ArrayIndex.get` function repeatedly from\n`0...length-1` and returns the \"flattened\" array instance.\n\n### \"toJSON()\" → Array\n\nAll `ArrayIndex` instances get basic support for `JSON.stringify()`, which is\nthe same as a \"flattened\" Array being stringified.\n\n### \"toString()\" → String\n\nThe `toString()` override is basically just `array.toArray().toString()`.\n\n### \"format()\" → String\n\nThe `inspect()` implementation for the REPL attempts to mimic what a regular\nArray looks like in the REPL.\n\n\nLicense\n-------\n\n(The MIT License)\n\nCopyright (c) 2012 Nathan Rajlich &lt;nathan@tootallnate.net&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_attachments":{},"homepage":"https://github.com/TooTallNate/array-index#readme","bugs":{"url":"https://github.com/TooTallNate/array-index/issues"},"license":"MIT"}