New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

amida

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amida

[![github](https://badgen.net/badge//nju33,amida/000?icon=github&list=1)](https://github.com/nju33/amida) [![npm:version](https://badgen.net/npm/v/amida?icon=npm&label=)](https://www.npmjs.com/package/amida) [![typescript](https://badgen.net/badge/lang/ty

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

amida

github npm:version typescript ci:status document:typedoc license browserslist

Usage

/**
 * As to prepare of using the `amida`
 * 
 * ```sh
 * yarn add amida 
 * ```
 */
import Amida from 'amida';

or

<script src="https://unpkg.com/amida/amida.js"></script>
<script>
  // Can use the `Amida` here.
</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 => [
    // In case of `string`
    into((v: string) => v).if.string(),

    // In case of `number`
    into((num: number) =>
      Math.round(num) === num ? `${num}px` : `${num}em`,
    ).if.number() /* or if('number') */,

    // In case of `object`
    into((obj: BehaviorObject) => `${obj.size}px`).if.object(),

    // In case of `WeakMap`
    into((wm: WeakMap<object, BehaviorObject>) => {
      return `${wm.get(theme)!.size}px`;
    }).if.weakmap() /* or 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; // throw TypeError('size must be string, object')

FAQs

Package last updated on 23 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc