define-lazy-prop
Advanced tools
Comparing version 1.0.0 to 2.0.0
18
index.js
'use strict'; | ||
module.exports = (obj, prop, fn) => { | ||
const define = value => Object.defineProperty(obj, prop, {value, enumerable: true, writable: true}); | ||
module.exports = (object, propertyName, fn) => { | ||
const define = value => Object.defineProperty(object, propertyName, {value, enumerable: true, writable: true}); | ||
Object.defineProperty(obj, prop, { | ||
Object.defineProperty(object, propertyName, { | ||
configurable: true, | ||
enumerable: true, | ||
get() { | ||
const ret = fn(); | ||
define(ret); | ||
return ret; | ||
const result = fn(); | ||
define(result); | ||
return result; | ||
}, | ||
set(val) { | ||
define(val); | ||
set(value) { | ||
define(value); | ||
} | ||
}); | ||
return obj; | ||
return object; | ||
}; |
{ | ||
"name": "define-lazy-prop", | ||
"version": "1.0.0", | ||
"description": "Define a lazily evaluated property on an object", | ||
"license": "MIT", | ||
"repository": "sindresorhus/define-lazy-prop", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"lazy", | ||
"property", | ||
"properties", | ||
"prop", | ||
"define", | ||
"object", | ||
"obj", | ||
"value", | ||
"lazily", | ||
"laziness", | ||
"val", | ||
"evaluation", | ||
"eval", | ||
"execute", | ||
"getter", | ||
"function", | ||
"fn", | ||
"memoize", | ||
"cache", | ||
"defer", | ||
"deferred" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "define-lazy-prop", | ||
"version": "2.0.0", | ||
"description": "Define a lazily evaluated property on an object", | ||
"license": "MIT", | ||
"repository": "sindresorhus/define-lazy-prop", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"lazy", | ||
"property", | ||
"properties", | ||
"prop", | ||
"define", | ||
"object", | ||
"value", | ||
"lazily", | ||
"laziness", | ||
"evaluation", | ||
"eval", | ||
"execute", | ||
"getter", | ||
"function", | ||
"fn", | ||
"memoize", | ||
"cache", | ||
"defer", | ||
"deferred" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -11,3 +11,3 @@ # define-lazy-prop [![Build Status](https://travis-ci.org/sindresorhus/define-lazy-prop.svg?branch=master)](https://travis-ci.org/sindresorhus/define-lazy-prop) | ||
``` | ||
$ npm install --save define-lazy-prop | ||
$ npm install define-lazy-prop | ||
``` | ||
@@ -22,3 +22,3 @@ | ||
const unicorn = { | ||
// ... | ||
// … | ||
}; | ||
@@ -36,5 +36,5 @@ | ||
### defineLazyProp(obj, prop, fn) | ||
### defineLazyProp(object, propertyName, fn) | ||
#### obj | ||
#### object | ||
@@ -45,3 +45,3 @@ Type: `Object` | ||
#### prop | ||
#### propertyName | ||
@@ -56,3 +56,3 @@ Type: `string` | ||
Called the first time `prop` is accessed. Expected to return a value. | ||
Called the first time `propertyName` is accessed. Expected to return a value. | ||
@@ -63,3 +63,3 @@ | ||
- [lazy-value](https://github.com/sindresorhus/lazy-value) - Create a lazily evaluated value | ||
- [lazy-req](https://github.com/sindresorhus/lazy-req) - Require modules lazily | ||
- [import-lazy](https://github.com/sindresorhus/import-lazy) - Import a module lazily | ||
- [p-lazy](https://github.com/sindresorhus/p-lazy) - Create a lazy promise | ||
@@ -66,0 +66,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4446
5
44
3