Gathering detailed insights and metrics for lazy-get-decorator
Gathering detailed insights and metrics for lazy-get-decorator
Gathering detailed insights and metrics for lazy-get-decorator
Gathering detailed insights and metrics for lazy-get-decorator
Lazily evaluates a getter on an object and caches the returned value
npm install lazy-get-decorator
Typescript
Module System
Node Version
NPM Version
TypeScript (96.33%)
JavaScript (3.67%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
LGPL-3.0 License
32 Stars
430 Commits
1 Forks
3 Watchers
3 Branches
4 Contributors
Updated on Apr 17, 2025
Latest Version
3.0.0
Package Id
lazy-get-decorator@3.0.0
Unpacked Size
23.35 kB
Size
6.54 kB
File Count
9
NPM Version
10.1.0
Node Version
20.8.1
Published on
Oct 20, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Getter decorator that memoises the return value
1npm install lazy-get-decorator
1import {LazyGetter} from 'lazy-get-decorator'; 2 3class MyClass { 4 @LazyGetter(/* optional config */) 5 get foo(): number { 6 // ... 7 } 8 9 @LazyGetter(/* optional config */) 10 static get bar(): string { 11 // ... 12 } 13}
All options are optional
Name | Type | Default | Description |
---|---|---|---|
global | boolean | false | If set to true, the lazy getter triggering on one class instance will end up saving the returned value on all class instances, current and future. Has no effect on static getters. |
select | <T, R>(this: T, output: R, self: T) => any | A function to determine whether we should save the results (returning a truthy value) or continue calling the original getter (returning a falsy value). The default behaviour is to always save the 1st result. |
The following example will save the value only if the counter is 10
or above. The selector executes after the getter
function, hence the offset of 1: the current value of 9 is returned and passed on to the result selector, but the
counter value is already incremented at this point.
1class MyClass { 2 #counter = 0; 3 4 @LazyGetter({select: v => v === 9}) 5 get timesAccessed(): number { 6 return this.#counter++; 7 } 8}
The library's only goal is to be compatible with Typescript 5 decorators which, at the time of writing, use the 2022-03 stage 3 decorators proposal. If you need experimental TS decorators or can't use a suitable Babel transform just stick to v2 - there are no new features in this release.
Typescript has further gotchas depending on the compiler target you've set.
ES2022 and higher allows you to use a class' method as a result selector:
1class MyClass { 2 static shouldMemoiseStatic = false; 3 shouldMemoiseInstance = true; 4 5 @LazyGetter({select: MyClass.bar}) 6 static get foo() {} 7 8 @LazyGetter({select: MyClass.prototype.bar2}) 9 get foo2() {} 10 11 static bar() { 12 return this.shouldMemoiseStatic; 13 } 14 15 bar2() { 16 return this.shouldMemoiseInstance; 17 } 18}
Attempting to do this on ES2021 or lower will result in a runtime error as of Typescript 5.2.
makeNonConfigurable
option removedsetProto
option renamed to global
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
7 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/6 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More