# ts-object-create

> Object creation that utilizes type information

Latest version **0.4.3** (published 2016-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-object-create
pnpm add ts-object-create
yarn add ts-object-create
bun add ts-object-create
```

## Health

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

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

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.3 |
| Published | 2016-07-30 |
| First published | 2016-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | David Sherret |
| Maintainers | dsherret |
| Keywords | typescript, code |

## Links

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

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^1.7.3

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.4.3 (latest) — 2016-07-30
- 0.4.2 — 2016-06-11
- 0.4.1 — 2016-05-13
- 0.4.0 — 2016-05-10
- 0.3.0 — 2016-05-10
- 0.2.2 — 2016-05-10
- 0.2.0 — 2016-05-10
- 0.1.0 — 2016-05-07

## README

TsObjectCreate
==============

[![Build Status](https://travis-ci.org/dsherret/ts-object-create.svg)](https://travis-ci.org/dsherret/ts-object-create)
[![Coverage Status](https://coveralls.io/repos/dsherret/ts-object-create/badge.svg?branch=master&service=github)](https://coveralls.io/github/dsherret/ts-object-create?branch=master)
[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)

This is a very experimental library that uses code generation to create functions for creating objects. **Currently it doesn't work in many scenarios so just don't use this yet.**

## Example

### Setup

Say you have some classes like this:

```typescript
// ./src/classes.ts
export class Main {
    name: string;
    other: Other;
}

export class Other {
    prop: string;
}
```

You could generate some code based on these classes:

```typescript
import * as fs from "fs";

const code = getGeneratedCode({
    srcRoot: "./src"
    files: ["./src/classes.ts"]
});

fs.writeFile("./src/objectFactory.ts", code);
```

### Use

Then this would allow you to do the following:

```typescript
// ./src/main.ts
import * as objectFactory from "./objectFactory";
import {Other, Main} from "./classes";

const main = objectFactory.Classes.Main.create({
    name: "my name",
    other: {
        prop: "my prop string"
    }
});

main instanceof Main;        // true
main.other instanceof Other; // true

// serialize it
const json = JSON.stringify(main);
// deserialize it
const newMain = objectFactory.Classes.Main.create(JSON.parse(json));

newMain instanceof Main;        // true
newMain.other instanceof Other; // true
```

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