npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

embryo

v0.1.6

Published

The most simple, customizable and easy to use JavaScript standard inheritance library

Downloads

42

Readme

Embryo.js SlugBay Badge

Stars Latest Stable Version NPM Downloads NPM Downloads

The most simple, customizable and easy to use JavaScript standard inheritance library.

Features

  • Support the new operator.
  • Support the instanceof operator.
  • Support the standard OO inheritance
  • Support super constructor automatic call
  • Support extending a class C via C.prototype
  • Support automatic 'getters', 'setters' methods generation
  • Support surcharged methods, call a specific method from arguments count
  • Support static methods, call from object as MyClass.method()
  • Support custom class definition format (configure all plugins)
  • Support customs plugins (create your own plugin or use defaults)
  • Support plugins management (whitelist, blacklist plugin from your class definition)

Inspiration

@ Inspired by Douglass Crockford’s website :(http://javascript.crockford.com/prototypal.html). @ Inspired by Cyril Agosta’s library : (https://github.com/cagosta/SeedHq). @ Inspired by Angular Framework : (https://github.com/angular/angular.js). @ Inspired by JQuery extend's function : (https://github.com/jquery/jquery).

Installation

  npm install embryo
<script src="dist/embryo-0.1.6.min.js" type="text/javascript"></script>

Usage

var Embryo = require('embryo')

var Human = Embryo.extend({

    '_type': 'Human',				// define class internal type

    properties : {				// define all class properties
        name: 'John',
        score: 1000,
        power: 2,
        options: [
            'super',
        ]
    },
    init: function() {				// define class constructor
        this.lifes = 3
    },
    walk: function() {
        console.log('walk', this.power)
    },
    run: function() {				// define a simple method
        console.log('0 arg')
    },
	'run|1': function( arg1 ) {		// define a surcharged method
        console.log('1 arg')			// when you call run( 'foo' )
    },
    'run|2': function( arg1, arg2 ) {		// define a surcharged method
        console.log('2 args')			// when you call run( 'foo', 'bar' )
    },
    'run|3': function( arg1, arg2, arg3 ) {
        console.log('3 args')
    },
    '$isDead': function (life) {        // prefix your method name with $ to make it static
        return life < 1
    }
})

Human.isDead(2)             // static method return false

var Superman = Human.extend({

    '_type': 'Superman',

    '_blacklist': [
    	'Attribute',				// Attribute plugin blacklisted for this class
    	'*'					// All plugins are blacklisted for this class
    ],

    properties : {
        name: 'Clark Kent',
        score: 5000,
        power: 10,
        options: [
            'super',
            'godness',
            'unlimited'
        ]
    },
    init: function() {
        this.lifes = 10
    },
    '-walk': function() {			// called before 'walk' call
        console.log('before walk')
    },
    '+walk': function() {			// called after 'walk' call
        console.log('after walk')
    },
    fly: function() {
        console.log('fly', this.power)
    }
})

var human = new Human()
human.walk()					// -> walk: 2
console.log( human.getScore() )			// -> 1000
console.log( human.getName() )			// -> John
console.log( human.getOptions() )		// -> ['super']

human.run()					// -> call method run()
human.run( '1' )				// -> call method human['run|1']()
human.run( '1', '2' )				// -> call method human['run|2']()
human.run( '1', '2', '3' )			// -> call method human['run|3']()
human.run( '1', '2', '3', '4' )			// -> call default method run()

var superman = new Superman()
superman.walk()					// -> before walk
						// -> walk: 10
						// -> after walk
superman.fly()					// -> fly: 10
superman.getFly()				// Error, Attribute plugin blacklisted,
						// there is no generated method with name 'getFly'

console.log( human instanceof Human ) 		// -> true
console.log( human instanceof Superman )	// -> false
console.log( superman instanceof Human )	// -> true

Configure

To configure Embryo :

Embryo.configure({
    cstrName: 'init',				// default class constructor name
    cstrArrayName: '_types',        		// default constructors array name
    forceCstr: true,				// class constructor required ?
    nameType: '_type',              		// default class type property name
    typeDefault: 'Embryo',          		// default class type value
    forceTyping: true,              		// add a default class type if not exists
    nameProperties: 'properties',   		// default property object name
    nameBlacklist: '_blacklist',		// array key witch contains disabled plugins names
    deleteBlacklist: true			// delete blacklist array before class instanciation ?
})

Plugins

Embryo enables by default 4 plugins :

  • Attribute : A plugin to generate "getters" and "setters" methods
  • BeforeAfter : A plugin to redefine/control super methods execution
  • Surcharge : A plugin to allow you call specific method with multiple arguments
  • Static : A plugin to allow you define static method
Embryo.plugins('Attribute').configure({
	getPrefix: 'get',			// default get prefix name
	setPrefix: 'set',			// default set prefix name
	camelize: true				// camelize generated methods names (getscore or getScore)
})
Embryo.plugins('BeforeAfter').configure({
	beforePrefix: '-',	    // default before trigger prefix in method name (ex: -score)
	afterPrefix: '+',	    // default after trigger prefix in method name (ex: +score)
	hiddenPrefix: '_bah_'	// default prefix for hidden method (ex: score() -> call _bah_score())
})
Embryo.plugins('Surcharge').configure({
	suffix: '|',		     // default trigger suffix in method name (ex: score|2)
	hiddenPrefix: '_pm_'	 // default prefix for hidden method (ex: score() -> call _pm_score())
})
Embryo.plugins('Static').configure({
	prefix: '$'		// default prefix name
})

Your plugin

var MyPlugin = Embryo.Plugin.extend({
    name: 'MyPlugin',				// your plugin's name
    options: {
        option1: 'value1',			// your plugin's options...
        option2: 'value2',
        option3: 'value3'
    },
    init: function() {				// your plugin's constructor

    },
    //
    // Embryo execute this function for all class creation
    // o: class properties
    // debug: debug mode for this plugin
    // child: class's prototype
    //
    exec: function( o, debug, child ) {

	// Check if your plugin is blacklisted for this class
        if (this.isBlacklisted( o )) {
            debug && console.log( '[' + this.name + '] - SKIPPED' )
            return o
        }

	// if debug mode is enabled for this plugin,
	// show all class property before class creation
        debug && debug( this.name, 'BEFORE', o )

        // your plugin's code...        

	// if debug mode is enabled for this plugin,
	// show all class property after class creation
        debug && debug( this.name, 'AFTER', o )

	// return new class properties
        return o
    }
})

// Create an instance of your plugin
var myPlugin = new MyPlugin()

// Tell embryo to use your new plugin
// use( plugin, debug )
Embryo.use( myPlugin, false )

// Now, you will able to reconfigure your plugin later...
Embryo.plugins('MyPlugin').configure({
	option1: 'value1',					// your plugin's options...
	option2: 'value2',
	option3: 'value3'
})

Donations

:heart: Donations are always welcome :heart:.

Coins | Symbols | Addresses --- | --- | --- | BTC | 3B52fbzNFQTaKZxWf5GrCUsASD2UP8na4A | ETH | 0x1C389f1f85Cdb3C2996b83fAc87E496A80698B7C