{"_id":"lazy-object","_rev":"8-ebc2a718a40319337a51731318e2d7f9","name":"lazy-object","description":"Define lazy properties on objects that are initialized once and only when accessed. Also known as a lazy initialization and cached/memoized getters.","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"lazy-object","version":"1.0.0","description":"Define lazy properties on objects that are initialized once and only when accessed. Also known as a lazy initialization and cached/memoized getters.","keywords":["cache","lazy","memoize","object","property"],"homepage":"https://github.com/moll/js-lazy-object","bugs":{"url":"https://github.com/moll/js-lazy-object/issues"},"author":{"name":"Andri Möll","email":"andri@dot.ee","url":"http://themoll.com"},"repository":{"type":"git","url":"git://github.com/moll/js-lazy-object.git"},"licenses":[{"type":"LAGPL","url":"https://github.com/moll/js-lazy-object/blob/master/LICENSE"}],"main":"index.js","scripts":{},"devDependencies":{"mocha":">= 1.18.2 < 2","must":"< 1","sinon":">= 1.10.3 < 2"},"gitHead":"9d295ba7ccb4aba157bd1842154760e94acd4eff","_id":"lazy-object@1.0.0","_shasum":"a00115d9df8e34a8df34c22eedc2ae300c704965","_from":".","_npmVersion":"2.0.2","_nodeVersion":"0.11.14","_npmUser":{"name":"moll","email":"andri@dot.ee"},"maintainers":[{"name":"moll","email":"andri@dot.ee"}],"dist":{"shasum":"a00115d9df8e34a8df34c22eedc2ae300c704965","tarball":"https://registry.npmjs.org/lazy-object/-/lazy-object-1.0.0.tgz","integrity":"sha512-YfDGYRXdIMZmYnGI92BZ6KEXYVRGpFBJA9rzFCQWv+2hoOOgkzS8rSi/0Kua9MRs28M4QbVUq3RIo5mHASnLvg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGRasspU9pT/nkBfBBkHfTddStd9on9xjWYlLvhlk3CWAiAq1KOOFh9VkXdgh+lxZgTUTkG0ZsL1lfQpK0ORbl5CAQ=="}]}},"1.0.1":{"name":"lazy-object","version":"1.0.1","description":"Define lazy properties on objects that are initialized once and only when accessed. Also known as a lazy initialization and cached/memoized getters.","keywords":["cache","lazy","memoize","object","property"],"homepage":"https://github.com/moll/js-lazy-object","bugs":{"url":"https://github.com/moll/js-lazy-object/issues"},"author":{"name":"Andri Möll","email":"andri@dot.ee","url":"http://themoll.com"},"repository":{"type":"git","url":"git://github.com/moll/js-lazy-object.git"},"licenses":[{"type":"LAGPL","url":"https://github.com/moll/js-lazy-object/blob/master/LICENSE"}],"main":"index.js","scripts":{},"devDependencies":{"mocha":">= 1.18.2 < 2","must":"< 1","sinon":">= 1.10.3 < 2"},"gitHead":"5d4e85a20b992555a804972cd361f3949359befb","_id":"lazy-object@1.0.1","_shasum":"3866434d42104aac699fd3998928cb3ca7faf249","_from":".","_npmVersion":"2.0.2","_nodeVersion":"0.11.14","_npmUser":{"name":"moll","email":"andri@dot.ee"},"maintainers":[{"name":"moll","email":"andri@dot.ee"}],"dist":{"shasum":"3866434d42104aac699fd3998928cb3ca7faf249","tarball":"https://registry.npmjs.org/lazy-object/-/lazy-object-1.0.1.tgz","integrity":"sha512-MKxxKThNg1xepNDOfh4muZYpfWCLDD6atGBbi+esg2pH/nwqr3P6P1binXXZ6M2Lq/pPxr5hfHAzCvgSng8/Nw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC1a2/+NLngn4IHO5LswXRYtKf5P9INWgZq+DPaM1s0GAIhAN2kndsTGfyC8LUUdOZp1ni43Ax5OrZtKyFNnI/YB63z"}]}}},"readme":"LazyObject.js\n=============\n[![NPM version][npm-badge]](http://badge.fury.io/js/lazy-object)\n[npm-badge]: https://badge.fury.io/js/lazy-object.png\n\nLazyObject.js lets you define properties on an object whose values are\ninitialized only when first accessed. From then on, values are cached/memoized.\n\nIts `defineLazyProperty` function follows the `Object.defineProperty` signature\nclosely and allows you to change whether the defined properties are\n`configurable`, `enumerable` and `writable`.\n\n\nInstalling\n----------\n```sh\nnpm install lazy-object\n```\n\nLazyObject.js follows [semantic versioning](http://semver.org/), so feel free to\ndepend on its major version with something like `>= 1.0.0 < 2` (a.k.a `^1.0.0`).\n\n\nUsing\n-----\n### Defining a lazily initialized property\n```javascript\nvar LazyObject = require(\"lazy-object\")\nvar Net = require(\"net\")\nvar server = {}\n\nLazyObject.defineLazyProperty(server, \"connection\", function() {\n  return Net.connect(23, \"example.com\")\n})\n```\n\nProperties are by default defined as `configurable`, `enumerable` and\n`writable`. To change that, pass an options object as the last argument.\nThen, like `Object.defineProperty`, all unset properties are set to `false`.\n\n```javascript\nLazyObject.defineLazyProperty(server, \"connection\", function() {\n  return Net.connect(23, \"example.com\")\n}, {configurable: true})\n```\n\nThe above creates a `configurable`, but `non-enumerable` and `non-writable`\nproperty (both before initialization and after). This prevents anyone from\noverwriting the property once initalized.\n\n### Defining multiple lazy properties\n```javascript\nvar LazyObject = require(\"lazy-object\")\nvar Pg = require(\"pg\")\nvar Redis = require(\"redis\")\nvar connections = {}\n\nLazyObject.defineLazyProperties(connections, {\n  pg: Pg.connect.bind(Pg, \"postgres://example.com/database\"),\n  redis: Redis.createClient.bind(Redis)\n})\n```\n\nYou can change the properties' enumerability by passing in an options object as\nthe last argument:\n\n```javascript\nLazyObject.defineLazyProperties(connections, {\n  pg: Pg.connect.bind(Pg, \"postgres://example.com/database\"),\n  redis: Redis.createClient.bind(Redis)\n}, {configurable: true, writable: true})\n```\n\nThe above creates the `pg` and `redis` properties as `configurable` and `writable`, but not `enumerable`.\n\n### Defining lazy properties on the prototype\nYou don't have to define properties directly on the object you want them on.\nTaking advantage of prototypical inheritance, you can do so only once on the\nprototype:\n\n```javascript\nvar LazyObject = require(\"lazy-object\")\nvar Net = require(\"net\")\n\nfunction Telnet(host, port) {\n  if (host != null) this.host = host\n  if (port != null) this.port = port\n}\n\nTelnet.prototype.host = null\nTelnet.prototype.port = 23\n\nLazyObject.defineLazyProperty(Telnet.prototype, \"connection\", function() {\n  return Net.connect(this.port, this.host)\n})\n```\n\nThen, only when you first access the `connection` property on a new `Telnet`\ninstance, will the connection be created. Different `Telnet` instances get their\nown connections.\n\n\nLicense\n-------\nLazyObject.js is released under a *Lesser GNU Affero General Public\nLicense*, which in summary means:\n\n- You **can** use this program for **no cost**.\n- You **can** use this program for **both personal and commercial reasons**.\n- You **do not have to share your own program's code** which uses this program.\n- You **have to share modifications** (e.g. bug-fixes) you've made to this\n  program.\n\nFor more convoluted language, see the `LICENSE` file.\n\n\nAbout\n-----\n**[Andri Möll][moll]** typed this and the code.  \n[Monday Calendar][monday] supported the engineering work.\n\nIf you find LazyObject.js needs improving, please don't hesitate to type to me\nnow at [andri@dot.ee][email] or [create an issue online][issues].\n\n[email]: mailto:andri@dot.ee\n[issues]: https://github.com/moll/js-lazy-object/issues\n[moll]: http://themoll.com\n[monday]: https://mondayapp.com\n","maintainers":[{"name":"moll","email":"andri@dot.ee"}],"time":{"modified":"2022-06-19T10:57:39.283Z","created":"2015-01-12T21:18:26.127Z","1.0.0":"2015-01-12T21:18:26.127Z","1.0.1":"2015-01-21T14:47:45.580Z"},"homepage":"https://github.com/moll/js-lazy-object","keywords":["cache","lazy","memoize","object","property"],"repository":{"type":"git","url":"git://github.com/moll/js-lazy-object.git"},"author":{"name":"Andri Möll","email":"andri@dot.ee","url":"http://themoll.com"},"bugs":{"url":"https://github.com/moll/js-lazy-object/issues"},"readmeFilename":"README.md","users":{"moll":true}}