0.1.3 • Published 9 months ago

cached_property v0.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

cached_property for Node and TypeScript

A @cached_property decorator for Node.

This package implements @cached_property for Node, inspired by Python 3.8 functools.cached_property.

The package also includes TypeScript typing.

Usage

yarn add cached_property
import { cached_property } from "cached_property";

Example

class CachedPropertyTest {
  private readonly multiplier: number;

  constructor() {
    this.multiplier = -Math.random() * 1000;
  }

  @cached_property
  public get seconds(): number {
    return Math.random() * this.multiplier;
  }

  @cached_property
  public get more_seconds(): number {
    return Math.random() * this.multiplier;
  }
}

const t1 = new CachedPropertyTest();
const t2 = new CachedPropertyTest();

console.log('t1', t1);
console.log('t2', t2);

console.log(t1.seconds);
console.log(t1.seconds);
console.log(t1.more_seconds);

console.log(t2.seconds);
console.log(t2.seconds);
console.log(t2.more_seconds);

prints:

t1 CachedPropertyTest { multiplier: -744.8363910755569 }
t2 CachedPropertyTest { multiplier: -740.5825190870856 }
-577.7473504371724
-577.7473504371724
-377.27881344400447
-139.17929406315005
-139.17929406315005
-648.857438477043
0.1.3

9 months ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.3

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago