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

class-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

class-wrapper - npm Package Compare versions

Comparing version 0.9.1 to 0.9.2

lib/ClassBuilder.js

47

dest/class-wrapper.js

@@ -0,3 +1,12 @@

(function (root, factory) {
if(typeof define === "function" && define.amd) {
define([], factory);
} else if(typeof module === "object" && module.exports) {
module.exports = factory();
} else {
root.classWrappers = factory();
}
})(this, function() {
// Set of wrappers for easier creation of different kinds of classes
// v0.9.1
// v0.9.2
// Copyright (c) 2016 Valerii Zinchenko

@@ -120,3 +129,3 @@ // License: http://valerii-zinchenko.github.io/class-wrapper/LICENSE.txt

if (key === '_defaults') {
// NOTE. This is only for cases when some instance of FClass will be encapsulated.
// NOTE. This is only for cases when some instance of ClassBuilder will be encapsulated.
utils.deepCopy(to.prototype._defaults, value);

@@ -149,3 +158,3 @@ } else {

/**
* @file Implementation of [FClass]{@link FClass}
* @file Implementation of [ClassBuilder]{@link ClassBuilder}
*

@@ -163,3 +172,3 @@ * @see {@link Class}

/**
* Main class factory.
* Main class builder.
* It takes the constructor function and wraps it to add few automated processes for constructing a new class.

@@ -182,3 +191,3 @@ *

*
* @throws {Error} Incorrect input arguments. It should be: FClass(Function, [Function], [Function | Object]*, Object)
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], [Function | Object]*, Object)
*

@@ -188,3 +197,3 @@ * @see {@link Class}

*/
function FClass(Constructor, Parent, props) {
function ClassBuilder(Constructor, Parent, props) {
// Last input argument is an object of properties for a new class

@@ -213,3 +222,3 @@ props = arguments[arguments.length - 1];

{
throw new Error('Incorrect input arguments. It should be: FClass(Function, [Function], [Function | Object]*, Object)');
throw new Error('Incorrect input arguments. It should be: ClassBuilder(Function, [Function], [Function | Object]*, Object)');
}

@@ -286,3 +295,3 @@ // todo: Validate proprties for a usage of reserverd locally variable names to avoid the interference

*
* @see {@link FClass}
* @see {@link ClassBuilder}
* @see {@link SingletonClass}

@@ -328,5 +337,5 @@ *

* Class
* This binds {@link Coreconstructor} function into FClass function as the first argument, so it will accept the other arguments.
* This binds {@link Coreconstructor} function into ClassBuilder function as the first argument, so it will accept the other arguments.
*
* @see {@link FClass}
* @see {@link ClassBuilder}
*

@@ -339,3 +348,3 @@ * @param {Function} [Parent = Object] - Parent class. Built-in 'Object' will be used if this argument will be omitted

*/
var Class = FClass.bind(null, CoreConstructor);
var Class = ClassBuilder.bind(null, CoreConstructor);

@@ -367,3 +376,3 @@ /*

*
* @see {@link FClass}
* @see {@link ClassBuilder}
* @see {@link Class}

@@ -381,5 +390,5 @@ *

* This additionally wraps the {@link CoreConstructor} to store and return already created instance.
* This binds addtional wrapper into FClass function as the first argument, so it will accept the other arguments.
* This binds addtional wrapper into ClassBuilder function as the first argument, so it will accept the other arguments.
*
* @see {@link FClass}
* @see {@link ClassBuilder}
*

@@ -392,3 +401,3 @@ * @param {Function} [Parent = Object] - Parent class. Built-in 'Object' will be used if this argument will be omitted

*/
var SingletonClass = FClass.bind(null, function() {
var SingletonClass = ClassBuilder.bind(null, function() {
// Return instance if it is already exist

@@ -404,1 +413,9 @@ if (this.constructor.instance) {

});
return {
utils: utils,
ClassBuilder: ClassBuilder,
Class: Class,
SingletonClass: SingletonClass
};
});
// Set of wrappers for easier creation of different kinds of classes
// v0.9.1
// v0.9.2
// Copyright (c) 2016 Valerii Zinchenko
// License: http://valerii-zinchenko.github.io/class-wrapper/LICENSE.txt
// All source files are available at: http://github.com/valerii-zinchenko/class-wrapper
"use strict";function FClass(Constructor,Parent,props){props=arguments[arguments.length-1],Parent==props&&(Parent=Object);var encapsulations=Array.prototype.slice.call(arguments,2,-1);if(arguments.length<2||"function"!=typeof Constructor||"[object Function]"!==Object.prototype.toString.call(Parent)||"[object Object]"!==Object.prototype.toString.call(props)||encapsulations.some(function(a){var b=Object.prototype.toString.call(a);return"[object Function]"!==b&&"[object Object]"!==b}))throw new Error("Incorrect input arguments. It should be: FClass(Function, [Function], [Function | Object]*, Object)");var Class;eval("Class = "+Constructor.toString()),Class.parent=Parent.prototype;var CoreClass=function(){};CoreClass.prototype=Parent.prototype,Class.prototype=new CoreClass,Class.prototype.constructor=Class,Class.prototype._defaults={},props.Encapsulate&&("[object Array]"==Object.prototype.toString.call(props.Encapsulate)?encapsulations=encapsulations.concat(props.Encapsulate):encapsulations.push(props.Encapsulate),delete props.Encapsulate),Parent.prototype._defaults&&encapsulations.unshift(Parent.prototype._defaults),encapsulations.push(props);for(var n=0,N=encapsulations.length;n<N;n++)utils.encapsulate(encapsulations[n],Class);return Class}function CoreConstructor(){utils.deepExtend(this,this.constructor.prototype._defaults),function a(b,c,d){var e=c.constructor.parent;e&&a(b,e,d),c.hasOwnProperty("initialize")&&c.initialize.apply(b,d)}(this,this.constructor.parent,arguments),this.constructor.prototype.hasOwnProperty("initialize")&&this.constructor.prototype.initialize.apply(this,arguments)}var utils={deepCopy:function(a,b){var c,d;for(c in b)switch(d=b[c],Object.prototype.toString.call(d)){case"[object Object]":a[c]||(a[c]={}),utils.deepCopy(a[c],d);break;default:a[c]=d}return a},deepExtend:function(a,b){var c,d;for(c in b)if(d=b[c],a.hasOwnProperty(c))"object"==typeof a[c]&&utils.deepExtend(a[c],d);else switch(Object.prototype.toString.call(d)){case"[object Object]":a[c]={},utils.deepExtend(a[c],d);break;case"[object Array]":a[c]=d.map(function(a){return a});break;default:a[c]=d}return a},encapsulate:function(a,b){"[object Function]"==Object.prototype.toString.call(a)&&(a=a.prototype);for(var c in a)if(a.hasOwnProperty(c)&&"constructor"!=c){var d=a[c];switch(Object.prototype.toString.call(d)){case"[object Function]":b.prototype[c]=d;break;case"[object Object]":"_defaults"===c?utils.deepCopy(b.prototype._defaults,d):(b.prototype._defaults[c]||(b.prototype._defaults[c]={}),utils.deepCopy(b.prototype._defaults[c],d));break;default:b.prototype._defaults[c]=d}}}},Class=FClass.bind(null,CoreConstructor),SingletonClass=FClass.bind(null,function(){return this.constructor.instance?this.constructor.instance:(this.constructor.instance=this,void CoreConstructor.apply(this,arguments))});
!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof module&&module.exports?module.exports=b():a.classWrappers=b()}(this,function(){"use strict";function ClassBuilder(Constructor,Parent,props){props=arguments[arguments.length-1],Parent==props&&(Parent=Object);var encapsulations=Array.prototype.slice.call(arguments,2,-1);if(arguments.length<2||"function"!=typeof Constructor||"[object Function]"!==Object.prototype.toString.call(Parent)||"[object Object]"!==Object.prototype.toString.call(props)||encapsulations.some(function(a){var b=Object.prototype.toString.call(a);return"[object Function]"!==b&&"[object Object]"!==b}))throw new Error("Incorrect input arguments. It should be: ClassBuilder(Function, [Function], [Function | Object]*, Object)");var Class;eval("Class = "+Constructor.toString()),Class.parent=Parent.prototype;var CoreClass=function(){};CoreClass.prototype=Parent.prototype,Class.prototype=new CoreClass,Class.prototype.constructor=Class,Class.prototype._defaults={},props.Encapsulate&&("[object Array]"==Object.prototype.toString.call(props.Encapsulate)?encapsulations=encapsulations.concat(props.Encapsulate):encapsulations.push(props.Encapsulate),delete props.Encapsulate),Parent.prototype._defaults&&encapsulations.unshift(Parent.prototype._defaults),encapsulations.push(props);for(var n=0,N=encapsulations.length;n<N;n++)utils.encapsulate(encapsulations[n],Class);return Class}function CoreConstructor(){utils.deepExtend(this,this.constructor.prototype._defaults),function a(b,c,d){var e=c.constructor.parent;e&&a(b,e,d),c.hasOwnProperty("initialize")&&c.initialize.apply(b,d)}(this,this.constructor.parent,arguments),this.constructor.prototype.hasOwnProperty("initialize")&&this.constructor.prototype.initialize.apply(this,arguments)}var utils={deepCopy:function(a,b){var c,d;for(c in b)switch(d=b[c],Object.prototype.toString.call(d)){case"[object Object]":a[c]||(a[c]={}),utils.deepCopy(a[c],d);break;default:a[c]=d}return a},deepExtend:function(a,b){var c,d;for(c in b)if(d=b[c],a.hasOwnProperty(c))"object"==typeof a[c]&&utils.deepExtend(a[c],d);else switch(Object.prototype.toString.call(d)){case"[object Object]":a[c]={},utils.deepExtend(a[c],d);break;case"[object Array]":a[c]=d.map(function(a){return a});break;default:a[c]=d}return a},encapsulate:function(a,b){"[object Function]"==Object.prototype.toString.call(a)&&(a=a.prototype);for(var c in a)if(a.hasOwnProperty(c)&&"constructor"!=c){var d=a[c];switch(Object.prototype.toString.call(d)){case"[object Function]":b.prototype[c]=d;break;case"[object Object]":"_defaults"===c?utils.deepCopy(b.prototype._defaults,d):(b.prototype._defaults[c]||(b.prototype._defaults[c]={}),utils.deepCopy(b.prototype._defaults[c],d));break;default:b.prototype._defaults[c]=d}}}},Class=ClassBuilder.bind(null,CoreConstructor),SingletonClass=ClassBuilder.bind(null,function(){return this.constructor.instance?this.constructor.instance:(this.constructor.instance=this,void CoreConstructor.apply(this,arguments))});return{utils:utils,ClassBuilder:ClassBuilder,Class:Class,SingletonClass:SingletonClass}});

@@ -19,3 +19,3 @@ module.exports = function(grunt) {

dest: {
src: ['lib/utils.js', 'lib/FClass.js', 'lib/Class.js', 'lib/SingletonClass.js'],
src: ['lib/utils.js', 'lib/ClassBuilder.js', 'lib/Class.js', 'lib/SingletonClass.js'],
dest: 'dest/<%= pkg.name %>.js'

@@ -28,3 +28,3 @@ }

src: ['dest/<%= pkg.name %>.js'],
dest: 'dest/<%= pkg.name %>_amd.js',
dest: 'dest/<%= pkg.name %>.js',
options: {

@@ -44,3 +44,3 @@ wrapper: [

' utils: utils,\n' +
' FClass: FClass,\n' +
' ClassBuilder: ClassBuilder,\n' +
' Class: Class,\n' +

@@ -61,4 +61,3 @@ ' SingletonClass: SingletonClass\n' +

files: {
'dest/<%= pkg.name %>.min.js': 'dest/<%= pkg.name %>.js',
'dest/<%= pkg.name %>_amd.min.js': 'dest/<%= pkg.name %>_amd.js',
'dest/<%= pkg.name %>.min.js': 'dest/<%= pkg.name %>.js'
}

@@ -65,0 +64,0 @@ }

@@ -12,3 +12,3 @@ /*

*
* @see {@link FClass}
* @see {@link ClassBuilder}
* @see {@link SingletonClass}

@@ -54,5 +54,5 @@ *

* Class
* This binds {@link Coreconstructor} function into FClass function as the first argument, so it will accept the other arguments.
* This binds {@link Coreconstructor} function into ClassBuilder function as the first argument, so it will accept the other arguments.
*
* @see {@link FClass}
* @see {@link ClassBuilder}
*

@@ -65,3 +65,3 @@ * @param {Function} [Parent = Object] - Parent class. Built-in 'Object' will be used if this argument will be omitted

*/
var Class = FClass.bind(null, CoreConstructor);
var Class = ClassBuilder.bind(null, CoreConstructor);

@@ -68,0 +68,0 @@ /*

@@ -12,3 +12,3 @@ /*

*
* @see {@link FClass}
* @see {@link ClassBuilder}
* @see {@link Class}

@@ -26,5 +26,5 @@ *

* This additionally wraps the {@link CoreConstructor} to store and return already created instance.
* This binds addtional wrapper into FClass function as the first argument, so it will accept the other arguments.
* This binds addtional wrapper into ClassBuilder function as the first argument, so it will accept the other arguments.
*
* @see {@link FClass}
* @see {@link ClassBuilder}
*

@@ -37,3 +37,3 @@ * @param {Function} [Parent = Object] - Parent class. Built-in 'Object' will be used if this argument will be omitted

*/
var SingletonClass = FClass.bind(null, function() {
var SingletonClass = ClassBuilder.bind(null, function() {
// Return instance if it is already exist

@@ -40,0 +40,0 @@ if (this.constructor.instance) {

@@ -115,3 +115,3 @@ /*

if (key === '_defaults') {
// NOTE. This is only for cases when some instance of FClass will be encapsulated.
// NOTE. This is only for cases when some instance of ClassBuilder will be encapsulated.
utils.deepCopy(to.prototype._defaults, value);

@@ -118,0 +118,0 @@ } else {

{
"name": "class-wrapper",
"version": "0.9.1",
"version": "0.9.2",
"description": "Set of wrappers for easier creation of different kinds of classes",

@@ -5,0 +5,0 @@ "main": "lib/FClass.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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