New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ts-object-create

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-object-create

Object creation that utilizes type information

latest
Source
npmnpm
Version
0.4.3
Version published
Maintainers
1
Created
Source

TsObjectCreate

Build Status Coverage Status experimental

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:

// ./src/classes.ts
export class Main {
    name: string;
    other: Other;
}

export class Other {
    prop: string;
}

You could generate some code based on these classes:

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:

// ./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

Keywords

typescript

FAQs

Package last updated on 30 Jul 2016

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