Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stamp/convert-class

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stamp/convert-class

Converts ES6 class to stamp

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

@stamp/convert-class

Converts an ES6 class to a stamp respecting the class's inheritance chain. The prototype chain is squashed into the methods of a stamp.

npm i -S @stamp/convert-class

Example

class CParent {
  constructor(arg1) {
    this.parentProp = arg1
  }

  commonMethod() { return 'parent' }
  parentMethod() { return 'parent' }

  static commonStaticMethod() { return 'parent' }
  static parentStaticMethod() { return 'parent' }
}

class CChild extends CParent {
  constructor(arg1, arg2) {
    super(arg1)
    this.childProp = arg2
  }

  commonMethod() { return super.commonMethod() } // overriding parent method 
  childMethod() { return 'child' }

  static commonStaticMethod() { return super.commonStaticMethod() } // overriding parent static method
  static childStaticMethod() { return 'child' }
}

const convertClass = require('@stamp/convert-class');

const Stamp = convertClass(CChild);

// parent class method
Stamp.compose.methods.parentMethod === CParent.prototype.parentMethod;
// child class method
Stamp.compose.methods.childMethod === CChild.prototype.childMethod;
// the overridden method
Stamp.compose.methods.commonMethod === CChild.prototype.commonMethod;
// The `super` inside regular method is delegated to parent
Stamp().commonMethod() === (new CChild()).commonMethod() === 'parent';

// parent static method
Stamp.parentStaticMethod === CParent.parentStaticMethod;
// child static method
Stamp.childStaticMethod === CChild.childStaticMethod;
// the overridden static method
Stamp.commonStaticMethod === CChild.commonStaticMethod;
// The `super` inside static methods of child classes is also delegated to parent 
Stamp.commonStaticMethod() === CChild.commonStaticMethod() === 'parent';

FAQs

Package last updated on 22 May 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc