amida
![browserslist](https://badgen.net/badge/browserslist/chrome,edge/ffd539?list=1)
Usage
import Amida from 'amida';
or
<script src="https://unpkg.com/amida/amida.js"></script>
<script>
</script>
Example
interface BehaviorObject {
size: string;
}
const theme = {
size: 123,
};
const wm = new WeakMap();
wm.set(theme, theme);
const amida = new Amida<BehaviorObject>({
size: into => [
into((v: string) => v).if.string(),
into((num: number) =>
Math.round(num) === num ? `${num}px` : `${num}em`,
).if.number() ,
into((obj: BehaviorObject) => `${obj.size}px`).if.object(),
into((wm: WeakMap<object, BehaviorObject>) => {
return `${wm.get(theme)!.size}px`;
}).if.weakmap() ,
],
});
const obj = amida.from(theme);
expect(obj.size).toBe('123px');
obj.size = '100%';
expect(obj.size).toBe('100%');
(obj.size as unknown) = theme;
expect(obj.size).toBe('123px');
(obj.size as unknown) = 999;
expect(obj.size).toBe('999px');
(obj.size as unknown) = 2.1;
expect(obj.size).toBe('2.1em');
(obj.size as unknown) = wm;
expect(obj.size).toBe('123px');
const amida2 = new Amida<BehaviorObject>({
size: into => [
into((v: string) => v).if.string(),
into((v: object) => v).if.object(),
]
});
amida2.from({});
(amida2.size as any) = 123;