npm

Share private packages across your team with npm Orgs, now with simplified billing via the aws marketplace!Learn more »

object-to-class

0.1.4 • Public • Published

object-to-class

source issues documentation

node package manager travis-ci lgtm david-dm david-dm

Generate a dynamically named es6 class from any JS object.

Install

Node
npm i object-to-class

Usage

Simply pass the object you wish to convert to a class, and an optional name.

const o2c = require('object-to-class')
const myObj = {
  'prop': 'my property'
  'fn': function () {
    return 'my function'
  }
}
const MyClass = o2c(myObj, 'MyClass')
MyClass.name // MyClass
const myinst = new MyClass()
myinst.prop // my property
myinst.fn() // my function

The result can be used like any other ES6 class, with normal inheritance.

class MySubclass extends MyClass {}
let myinst = new MySubclass()
mysubinst instanceof MyClass // true
mysubinst.prop // my property
mysubinst.fn() // my function

License

MIT Copyright isysd public@iramiller.com

Keywords

install

npm i object-to-class

Downloadsweekly downloads

5

version

0.1.4

license

MIT

homepage

guld.tech

repository

Gitbitbucket

last publish

collaborators

  • avatar
Report a vulnerability