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

cla6

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cla6 - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

lib/extensionsFactory.js

2

bower.json
{
"name": "cla6",
"description": "ES6 style class system",
"version": "1.2.2",
"version": "1.3.0",
"main": "client/cla6.js",

@@ -6,0 +6,0 @@ "repository": {

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Cla6 = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var Extender = require('./extender');
var ClassFactory = require('./classFactory');
var Extender = require('./extender');
var PluginsManager = require('./pluginsManager');

@@ -34,3 +35,3 @@ function Cla6(name, props) {

ClassFactory.use(plugin);
PluginsManager.add(plugin);
};

@@ -43,31 +44,7 @@

module.exports = Cla6;
},{"./classFactory":2,"./extender":3}],2:[function(require,module,exports){
},{"./classFactory":2,"./extender":3,"./pluginsManager":5}],2:[function(require,module,exports){
var _ = require('./utils');
var ExtensionsFactory = require('./extensionsFactory');
var PluginsManager = require('./pluginsManager');
var plugins = [];
var classExtensions = {
mixin: function(props) {
if (arguments.length > 1) {
Array.prototype.forEach.call(arguments, function(props) {
this.mixin(props);
}, this);
} else {
if (props == null)
throwErr('properties must be provided');
if (typeof props != 'object')
throwErr('properties must be defined using an object');
descriptors = _.toDescriptors(props);
applyPlugins(descriptors);
Object.defineProperties(this.prototype, descriptors);
}
return this;
}
};
var createClass = function(name, props, Parent) {

@@ -85,6 +62,7 @@ props = _.clone(props);

var descriptors = _.toDescriptors(props);
applyPlugins(descriptors);
PluginsManager.manipulate(descriptors, Parent);
var Child = _.nameFn(descriptors.constructor.value, name);
_.extend(Child, classExtensions);
var extensions = ExtensionsFactory.create(Parent);
_.extend(Child, extensions);

@@ -97,27 +75,6 @@ descriptors.constructor.value = Child;

var addPlugin = function(plugin) {
plugins.push(plugin);
};
var removePlugin = function(plugin) {
var index = plugins.indexOf(plugin);
plugins.splice(index, 1);
};
var applyPlugins = function(descriptors) {
plugins.forEach(function(plugin) {
plugin(descriptors);
});
};
var throwErr = function(msg) {
throw Error('Cla6 Class error - ' + msg);
};
module.exports = {
create: createClass,
use: addPlugin,
unuse: removePlugin
create: createClass
};
},{"./utils":4}],3:[function(require,module,exports){
},{"./extensionsFactory":4,"./pluginsManager":5,"./utils":6}],3:[function(require,module,exports){
var ClassFactory = require('./classFactory');

@@ -157,2 +114,65 @@

},{"./classFactory":2}],4:[function(require,module,exports){
var _ = require('./utils');
var PluginsManager = require('./pluginsManager');
var createExtensions = function(Parent) {
var mixin = function(props) {
if (arguments.length > 1) {
Array.prototype.forEach.call(arguments, function(props) {
this.mixin(props);
}, this);
return this;
}
if (props == null)
throwErr('properties must be provided');
if (typeof props != 'object')
throwErr('properties must be defined using an object');
descriptors = _.toDescriptors(props);
PluginsManager.manipulate(descriptors, Parent);
Object.defineProperties(this.prototype, descriptors);
return this;
};
return {
mixin: mixin
};
};
var throwErr = function(msg) {
throw Error('Cla6 mixin error - ' + msg);
};
module.exports = {
create: createExtensions
};
},{"./pluginsManager":5,"./utils":6}],5:[function(require,module,exports){
var plugins = [];
var add = function(plugin) {
plugins.push(plugin);
};
var remove = function(plugin) {
var index = plugins.indexOf(plugin);
plugins.splice(index, 1);
};
var manipulate = function(descriptors, Parent) {
plugins.forEach(function(plugin) {
plugin(descriptors, Parent);
});
};
module.exports = {
add: add,
remove: remove,
manipulate: manipulate
};
},{}],6:[function(require,module,exports){
var clone = function(obj) {

@@ -159,0 +179,0 @@ return Object.keys(obj).reduce(function(result, k) {

@@ -1,1 +0,1 @@

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Cla6=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var ClassFactory=require("./classFactory");var Extender=require("./extender");function Cla6(name,props){if(name==null)throwErr("a name must be provided");if(typeof name!="string")throwErr("name must be a string");if(props!=null){if(typeof props!="object")throwErr("properties must be defined using an object");if(props.hasOwnProperty("constructor")&&typeof props.constructor!="function")throwErr("constructor must be a function")}if(props==null)return new Extender(name);else return ClassFactory.create(name,props)}Cla6.use=function(plugin){if(plugin==null)throwErr("a plugin must be provided");if(typeof plugin!="function")throwErr("plugin must be a function");ClassFactory.use(plugin)};var throwErr=function(msg){throw Error("Cla6 error - "+msg)};module.exports=Cla6},{"./classFactory":2,"./extender":3}],2:[function(require,module,exports){var _=require("./utils");var plugins=[];var classExtensions={mixin:function(props){if(arguments.length>1){Array.prototype.forEach.call(arguments,function(props){this.mixin(props)},this)}else{if(props==null)throwErr("properties must be provided");if(typeof props!="object")throwErr("properties must be defined using an object");descriptors=_.toDescriptors(props);applyPlugins(descriptors);Object.defineProperties(this.prototype,descriptors)}return this}};var createClass=function(name,props,Parent){props=_.clone(props);if(typeof Parent!="function")Parent=Object;if(!props.hasOwnProperty("constructor"))props.constructor=function(){Parent.apply(this,arguments)};var descriptors=_.toDescriptors(props);applyPlugins(descriptors);var Child=_.nameFn(descriptors.constructor.value,name);_.extend(Child,classExtensions);descriptors.constructor.value=Child;Child.prototype=Object.create(Parent.prototype,descriptors);return Child};var addPlugin=function(plugin){plugins.push(plugin)};var removePlugin=function(plugin){var index=plugins.indexOf(plugin);plugins.splice(index,1)};var applyPlugins=function(descriptors){plugins.forEach(function(plugin){plugin(descriptors)})};var throwErr=function(msg){throw Error("Cla6 Class error - "+msg)};module.exports={create:createClass,use:addPlugin,unuse:removePlugin}},{"./utils":4}],3:[function(require,module,exports){var ClassFactory=require("./classFactory");var Extender=ClassFactory.create("Extender",{constructor:function(name){this.name=name},extend:function(Parent,props){if(Parent==null)throwErr("a parent must be provided");if(typeof Parent!="function")throwErr("parent must be a function");if(props==null)throwErr("properties must be provided");if(typeof props!="object")throwErr("properties must be defined using an object");if(props.hasOwnProperty("constructor")&&typeof props.constructor!="function")throwErr("constructor must be a function");return ClassFactory.create(this.name,props,Parent)}});var throwErr=function(msg){throw Error("Cla6 extension error - "+msg)};module.exports=Extender},{"./classFactory":2}],4:[function(require,module,exports){var clone=function(obj){return Object.keys(obj).reduce(function(result,k){var descriptor=Object.getOwnPropertyDescriptor(obj,k);return Object.defineProperty(result,k,descriptor)},{})};var extend=function(obj,extension){Object.keys(extension).forEach(function(k){obj[k]=extension[k]})};var nameFn=function(fn,name){return eval("(function "+name+"() {return fn.apply(this, arguments);})")};var toDescriptors=function(props){return Object.keys(props).reduce(function(result,k){var descriptor=Object.getOwnPropertyDescriptor(props,k);delete descriptor.enumerable;if(descriptor.value==null)delete descriptor.writable;result[k]=descriptor;return result},{})};module.exports={clone:clone,extend:extend,nameFn:nameFn,toDescriptors:toDescriptors}},{}]},{},[1])(1)});
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Cla6=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var Extender=require("./extender");var ClassFactory=require("./classFactory");var PluginsManager=require("./pluginsManager");function Cla6(name,props){if(name==null)throwErr("a name must be provided");if(typeof name!="string")throwErr("name must be a string");if(props!=null){if(typeof props!="object")throwErr("properties must be defined using an object");if(props.hasOwnProperty("constructor")&&typeof props.constructor!="function")throwErr("constructor must be a function")}if(props==null)return new Extender(name);else return ClassFactory.create(name,props)}Cla6.use=function(plugin){if(plugin==null)throwErr("a plugin must be provided");if(typeof plugin!="function")throwErr("plugin must be a function");PluginsManager.add(plugin)};var throwErr=function(msg){throw Error("Cla6 error - "+msg)};module.exports=Cla6},{"./classFactory":2,"./extender":3,"./pluginsManager":5}],2:[function(require,module,exports){var _=require("./utils");var ExtensionsFactory=require("./extensionsFactory");var PluginsManager=require("./pluginsManager");var createClass=function(name,props,Parent){props=_.clone(props);if(typeof Parent!="function")Parent=Object;if(!props.hasOwnProperty("constructor"))props.constructor=function(){Parent.apply(this,arguments)};var descriptors=_.toDescriptors(props);PluginsManager.manipulate(descriptors,Parent);var Child=_.nameFn(descriptors.constructor.value,name);var extensions=ExtensionsFactory.create(Parent);_.extend(Child,extensions);descriptors.constructor.value=Child;Child.prototype=Object.create(Parent.prototype,descriptors);return Child};module.exports={create:createClass}},{"./extensionsFactory":4,"./pluginsManager":5,"./utils":6}],3:[function(require,module,exports){var ClassFactory=require("./classFactory");var Extender=ClassFactory.create("Extender",{constructor:function(name){this.name=name},extend:function(Parent,props){if(Parent==null)throwErr("a parent must be provided");if(typeof Parent!="function")throwErr("parent must be a function");if(props==null)throwErr("properties must be provided");if(typeof props!="object")throwErr("properties must be defined using an object");if(props.hasOwnProperty("constructor")&&typeof props.constructor!="function")throwErr("constructor must be a function");return ClassFactory.create(this.name,props,Parent)}});var throwErr=function(msg){throw Error("Cla6 extension error - "+msg)};module.exports=Extender},{"./classFactory":2}],4:[function(require,module,exports){var _=require("./utils");var PluginsManager=require("./pluginsManager");var createExtensions=function(Parent){var mixin=function(props){if(arguments.length>1){Array.prototype.forEach.call(arguments,function(props){this.mixin(props)},this);return this}if(props==null)throwErr("properties must be provided");if(typeof props!="object")throwErr("properties must be defined using an object");descriptors=_.toDescriptors(props);PluginsManager.manipulate(descriptors,Parent);Object.defineProperties(this.prototype,descriptors);return this};return{mixin:mixin}};var throwErr=function(msg){throw Error("Cla6 mixin error - "+msg)};module.exports={create:createExtensions}},{"./pluginsManager":5,"./utils":6}],5:[function(require,module,exports){var plugins=[];var add=function(plugin){plugins.push(plugin)};var remove=function(plugin){var index=plugins.indexOf(plugin);plugins.splice(index,1)};var manipulate=function(descriptors,Parent){plugins.forEach(function(plugin){plugin(descriptors,Parent)})};module.exports={add:add,remove:remove,manipulate:manipulate}},{}],6:[function(require,module,exports){var clone=function(obj){return Object.keys(obj).reduce(function(result,k){var descriptor=Object.getOwnPropertyDescriptor(obj,k);return Object.defineProperty(result,k,descriptor)},{})};var extend=function(obj,extension){Object.keys(extension).forEach(function(k){obj[k]=extension[k]})};var nameFn=function(fn,name){return eval("(function "+name+"() {return fn.apply(this, arguments);})")};var toDescriptors=function(props){return Object.keys(props).reduce(function(result,k){var descriptor=Object.getOwnPropertyDescriptor(props,k);delete descriptor.enumerable;if(descriptor.value==null)delete descriptor.writable;result[k]=descriptor;return result},{})};module.exports={clone:clone,extend:extend,nameFn:nameFn,toDescriptors:toDescriptors}},{}]},{},[1])(1)});

@@ -0,3 +1,4 @@

var Extender = require('./extender');
var ClassFactory = require('./classFactory');
var Extender = require('./extender');
var PluginsManager = require('./pluginsManager');

@@ -33,3 +34,3 @@ function Cla6(name, props) {

ClassFactory.use(plugin);
PluginsManager.add(plugin);
};

@@ -36,0 +37,0 @@

var _ = require('./utils');
var ExtensionsFactory = require('./extensionsFactory');
var PluginsManager = require('./pluginsManager');
var plugins = [];
var classExtensions = {
mixin: function(props) {
if (arguments.length > 1) {
Array.prototype.forEach.call(arguments, function(props) {
this.mixin(props);
}, this);
} else {
if (props == null)
throwErr('properties must be provided');
if (typeof props != 'object')
throwErr('properties must be defined using an object');
descriptors = _.toDescriptors(props);
applyPlugins(descriptors);
Object.defineProperties(this.prototype, descriptors);
}
return this;
}
};
var createClass = function(name, props, Parent) {

@@ -41,6 +17,7 @@ props = _.clone(props);

var descriptors = _.toDescriptors(props);
applyPlugins(descriptors);
PluginsManager.manipulate(descriptors, Parent);
var Child = _.nameFn(descriptors.constructor.value, name);
_.extend(Child, classExtensions);
var extensions = ExtensionsFactory.create(Parent);
_.extend(Child, extensions);

@@ -53,25 +30,4 @@ descriptors.constructor.value = Child;

var addPlugin = function(plugin) {
plugins.push(plugin);
};
var removePlugin = function(plugin) {
var index = plugins.indexOf(plugin);
plugins.splice(index, 1);
};
var applyPlugins = function(descriptors) {
plugins.forEach(function(plugin) {
plugin(descriptors);
});
};
var throwErr = function(msg) {
throw Error('Cla6 Class error - ' + msg);
};
module.exports = {
create: createClass,
use: addPlugin,
unuse: removePlugin
create: createClass
};
{
"name": "cla6",
"description": "ES6 style class system",
"version": "1.2.2",
"version": "1.3.0",
"main": "lib/cla6.js",

@@ -6,0 +6,0 @@ "repository": {

@@ -133,3 +133,3 @@ # Cla6.js

A Cla6 plugin is a manupulation function which gets the classe's descriptors anytime before it gets created, thus the properties can be manipulated. Multipile plugins can be applied and will be called by their use order.
A Cla6 plugin is a manupulation function which gets the classe's descriptors and parent anytime before it gets created, thus the properties can be manipulated. Multipile plugins can be applied and will be called by their use order.

@@ -147,2 +147,3 @@ Note, each plugin will affect the descriptors object for the next plugin in the plugins chain.

## Download
The source is available for download from

@@ -149,0 +150,0 @@ [GitHub](http://github.com/DAB0mB/cla6).

var Chai = require('chai');
var Cla6 = require('..');
var ClassFactory = require('../lib/classFactory');
var PluginsManager = require('../lib/pluginsManager');
var expect = Chai.expect;
var spy = Chai.spy;
var unuse = ClassFactory.unuse;
var unuse = PluginsManager.remove;

@@ -10,0 +10,0 @@ describe('Cla6', function() {

var Chai = require('chai');
var Cla6 = require('..');
var ClassFactory = require('../lib/classFactory');
var PluginsManager = require('../lib/pluginsManager');
var expect = Chai.expect;
var spy = Chai.spy;
var unuse = ClassFactory.unuse;
var unuse = PluginsManager.remove;

@@ -23,3 +23,3 @@ describe('Cla6', function() {

it('should call plugin with class descriptors', function() {
it('should call plugin with class\'es descriptors and parent', function() {
var props = {

@@ -31,3 +31,3 @@ method: function() {},

var plugin = spy(function(descriptors) {
var plugin = spy(function(descriptors, Parent) {
expect(descriptors).to.have.all.keys('constructor', 'method', 'accessor');

@@ -39,6 +39,8 @@ expect(descriptors.method.value).to.equal(props.method);

expect(descriptors.accessor.set).to.equal(accessorDescriptor.set);
expect(Parent).to.equal(Array);
});
Cla6.use(plugin);
Cla6('Klass', props);
Cla6('Klass').extend(Array, props);
expect(plugin).to.have.been.called.once;

@@ -45,0 +47,0 @@

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