pax_global_header00006660000000000000000000000064123304514720014513gustar00rootroot0000000000000052 comment=86fd4138b7c54b474b9be06101a03efdb5fd8173 lazy-property-86fd4138b7c54b474b9be06101a03efdb5fd8173/000077500000000000000000000000001233045147200213545ustar00rootroot00000000000000lazy-property-86fd4138b7c54b474b9be06101a03efdb5fd8173/.gitignore000066400000000000000000000001531233045147200233430ustar00rootroot00000000000000lib-cov *.seed *.log *.csv *.dat *.out *.pid *.gz pids logs results npm-debug.log node_modules/* build/* lazy-property-86fd4138b7c54b474b9be06101a03efdb5fd8173/.npmignore000066400000000000000000000001511233045147200233500ustar00rootroot00000000000000lib-cov *.seed *.log *.csv *.dat *.out *.pid *.gz pids logs results npm-debug.log node_modules/* test/*lazy-property-86fd4138b7c54b474b9be06101a03efdb5fd8173/LICENSE000066400000000000000000000020721233045147200223620ustar00rootroot00000000000000 The MIT License (MIT) Copyright (c) 2013 Mikola Lysenko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. lazy-property-86fd4138b7c54b474b9be06101a03efdb5fd8173/README.md000066400000000000000000000014461233045147200226400ustar00rootroot00000000000000lazy-property ============= Adds a lazily initialized property to an object. ## Example ```javascript var addLazyProperty = require("lazy-property") var obj = {} addLazyProperty(obj, "foo", function() { console.log("initialized!") return "bar" }) //Access the property console.log(obj.foo) console.log(obj.foo) //Prints out: // // initialized! // bar // bar // ``` ## Install npm install lazy-property ## API ### `require("lazy-property")(obj, name, init[, enumerable])` Adds a lazily initialized property to the object. * `obj` is the object to add the property to * `name` is the name of the property * `init` is a function that computes the value of the property * `enumerable` if the property is enumerable (default `false`) ## Credits (c) 2013 Mikola Lysenko. MIT License lazy-property-86fd4138b7c54b474b9be06101a03efdb5fd8173/component.json000066400000000000000000000002611233045147200242500ustar00rootroot00000000000000{ "name": "lazy-property", "version": "0.0.2", "description": "Lazily initialized properties for objects", "main": "lazyProperty.js", "scripts": ["lazyProperty.js"] } lazy-property-86fd4138b7c54b474b9be06101a03efdb5fd8173/lazyProperty.js000066400000000000000000000010241233045147200244330ustar00rootroot00000000000000"use strict" function addLazyProperty(object, name, initializer, enumerable) { Object.defineProperty(object, name, { get: function() { var v = initializer.call(this) Object.defineProperty(this, name, { value: v, enumerable: !!enumerable, writable: true }) return v }, set: function(v) { Object.defineProperty(this, name, { value: v, enumerable: !!enumerable, writable: true }) return v }, enumerable: !!enumerable, configurable: true }) } module.exports = addLazyProperty lazy-property-86fd4138b7c54b474b9be06101a03efdb5fd8173/package.json000066400000000000000000000013521233045147200236430ustar00rootroot00000000000000{ "name": "lazy-property", "version": "1.0.0", "description": "Lazily initialized properties for objects", "main": "lazyProperty.js", "directories": { "test": "test" }, "dependencies": {}, "devDependencies": { "tape": "^2.12.3" }, "scripts": { "test": "tape test/*.js" }, "repository": { "type": "git", "url": "git://github.com/mikolalysenko/lazy-property.git" }, "keywords": [ "lazy", "property", "object", "initialize", "array", "dictionary" ], "author": "Mikola Lysenko", "license": "MIT", "readmeFilename": "README.md", "gitHead": "850a27f710ec72f05b534805c31f095ff590f1ea", "bugs": { "url": "https://github.com/mikolalysenko/lazy-property/issues" } } lazy-property-86fd4138b7c54b474b9be06101a03efdb5fd8173/test/000077500000000000000000000000001233045147200223335ustar00rootroot00000000000000lazy-property-86fd4138b7c54b474b9be06101a03efdb5fd8173/test/test.js000066400000000000000000000005361233045147200236540ustar00rootroot00000000000000var tape = require("tape") var addLazyProperty = require("../lazyProperty.js") tape("lazy-property", function(t) { var obj = {} var count = 0 addLazyProperty(obj, "foo", function() { ++count return "bar" }) t.same(count, 0) t.same(obj.foo, "bar") t.same(count, 1) t.same(obj.foo, "bar") t.same(count, 1) t.end() })