# amdine

> amdine is a dependency resolution for nodeJs.

Latest version **1.6.0** (published 2022-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install amdine
pnpm add amdine
yarn add amdine
bun add amdine
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2022-03-20 |
| First published | 2020-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | davidbernal |

## Links

- npm: https://www.npmjs.com/package/amdine
- npm.io page: https://npm.io/package/amdine

## Recent versions

- 1.6.0 (latest) — 2022-03-20
- 1.5.1 — 2022-03-20
- 1.5.0 — 2022-03-20
- 1.4.0 — 2022-03-03
- 1.3.0 — 2022-03-02
- 1.2.0 — 2022-03-02
- 1.1.1 — 2022-03-02
- 1.1.0 — 2022-03-02
- 1.0.1 — 2022-03-01
- 1.0.0 — 2022-02-28
- 0.1.0 — 2020-11-17

## README

# amdine (WIP)

amdine is a dependency resolution for nodeJs.

## Why

Import dependencies based on path (`require("../whatever")`, `import a from './foo'`) is a bad idea, cause is difficult mock.
Also, some people don't like classes on javascript.
This library try to solve doing resolution based on name, with AMD flavour (not in deep).

## How to initialize

```js
import amdine from 'amdine';

// import all your modules that use amdine

amdine.init();
```

## How to use

`define` function is the core. Use it to define modules.

### Signature

```ts
define = (factory: Function) => void;
define = (name: string, factoryOrValue: Function) => void;
define = (dependencies: string[], factory: Function) => void;
define = (name: string, dependencies: string[], factory: Function) => void;
```

Examples:

```js
define('my-object', function(){ return {} as myModule });

define('my-object', {value: 'hello'});

define('my-number', 42);

define('logger', function () {
  return { log: console.log };
});

define('my-task', ['logger'], function (logger) {
  logger.log('hello in task');
});

define('state', function () {
  function createState(){
    const state = {};
    function setState(newState) {
      state = newState;
    }
    return [state, setState];
  }
  return createState;
});

define('my-mod', ['state', 'logger'], function (createState, logger) {
  const [ state, setState ] = createState;
  logger.log(state);
});
```

For more examples look examples folder

### Get module resolved

Following last example:

```js
const state = admine.get('state');
state; // [state, setState]
```

---
_Source: https://npm.io/package/amdine · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
