# create-ctx

> creates a simple context object

Latest version **0.0.3** (published 2021-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install create-ctx
pnpm add create-ctx
yarn add create-ctx
bun add create-ctx
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2021-12-21 |
| First published | 2021-11-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | WizardsOrb |
| Maintainers | wizardsorb |
| Keywords | ctx, util |

## Links

- npm: https://www.npmjs.com/package/create-ctx
- Repository: https://github.com/WizardsOrb/create-ctx
- Homepage: https://github.com/WizardsOrb/create-ctx#readme
- Issues: https://github.com/WizardsOrb/create-ctx/issues
- npm.io page: https://npm.io/package/create-ctx

## Dependencies (2)

- [ts-typed-events](https://npm.io/package/ts-typed-events.md) ^3.0.0
- [@vdeturckheim/asjson](https://npm.io/package/@vdeturckheim/asjson.md) ^0.2.2

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2021-12-21
- 0.0.2 — 2021-11-11
- 0.0.1 — 2021-11-11

## README

# create-ctx
creates a simple context object

### usage
```ts
import create from 'create-ctx'
import { Event } from 'ts-typed-events'

type Data = Partial<{
  [index: string]: any
  test: string
  data2: string
  circular: Event<string>
}>

const initial: Data = {}

const ctx = create(
  initial,
  { create: () => '100' },
  {
    test: new Event<string>()
  }
)

ctx.ev.test.on(test => ctx.set({ test }))
ctx.ev.test.emit('100')

ctx.set({ data2: '500', circular: new Event })
console.log(ctx.data)

console.log(ctx.clean)
```

### example of returned object
```ts
export interface ContextWrapper <Data, Methods> {
  data: Partial<Data>
  fn: Partial<Methods>
  ev: Events
  setFn(fn: Partial<Methods>): void
  get(): Context<Data, Methods>
  set (i: Partial<Data>): Partial<Data>
  clear(): void
  readonly clean: Partial<Data>
}
```

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