3.0.1 • Published 5 months ago

@0x2e757/wrappers v3.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 months ago

Wrappers

TypeScript variable wrapper library, transpiled to ESNext JavaScript.

Install

npm i @0x2e757/wrappers

Usage

StaticWrapper

Simple wrapper that can be used as a value container. Has derived LocalStorageWrapper and SessionStorageWrapper implementation that read and save their values to corresponding storages.

Usage example:

import { StaticWrapper } from "@0x2e757/Wrappers";

const wNumber = new StaticWrapper(0);
wNumber.subscribe(console.log);

wNumber.value = 1;
wNumber.value = 2;
wNumber.value += 3;

Console output:

1
2
5

DynamicWrapper

Advanced wrapper which contains dynamically computed value (it can not be set manually). Values are being computed only before they are going to be used.

Usage example:

import { StaticWrapper, DynamicWrapper } from "@0x2e757/Wrappers";

const wUsername = new StaticWrapper("John");
const wBalance = new StaticWrapper(100);

const wAccountInfo = new DynamicWrapper(() => `${wUsername.value} has ${wBalance.value}$.`);
wAccountInfo.subscribe(console.log);

wBalance.value -= 50;

Console output:

John has 50$.

Generic Wrapper

Helper class that dynamically will return either StaticWrapper or DynamicWrapper, depending on value type (is function or not) passed to the constructor.

Usage example:

import { Wrapper } from "@0x2e757/Wrappers";

const staticWrapper = new Wrapper(0);
const dynamicWrapper = new Wrapper(() => staticWrapper.value * 2);
dynamicWrapper.subscribe(console.log);

staticWrapper.value = 5;

Console output:

10
3.0.1

5 months ago

3.0.0

5 months ago

2.2.5

1 year ago

2.2.4

1 year ago

2.2.6

1 year ago

2.2.3

3 years ago

2.2.1

3 years ago

2.2.2

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago