From bddf9470d3148d3a4c549d4040cfbc3c312541c0 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Fri, 18 Apr 2025 09:41:00 -0700 Subject: [PATCH] update readme --- .npmrc | 1 + README.md | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..258cd85 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +message="bump package version to %s" diff --git a/README.md b/README.md index 12d6cdd..d0f7bf3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,26 @@ -# Lazy Property +# @squeep/lazy-property -Easily defer property initialization until first access. +Defer property initialization until first access. + +## API `lazy(obj, name, initializer, descriptor, objectBound = true)` -```js +Add `name` property to `obj`, which will invoke `initializer` on first access +and update `name` with the resulting value. +Property settings can be specified with `descriptor`, as in `Object.defineProperty()`. +If `objectBound` is true and the lazy property is set on a prototype object, +the property will be updated on the prototype object. If `objectBound` is false +and on a prototype object, the property will be updated on the inherited object +and the `initializer` will be invoked once for each inherited object accessed. +The `this` object in `initializer` will be explicitly `obj` when `objectBound` is set, +otherwise it will be `this`. +Returns `obj`. + + +## Example + +```javascript const { lazy } = require('@squeep/lazy-property'); const obj = {}; -- 2.49.0