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 1.0.3 to 1.1.0

lib/index.js

108

dest/class-wrapper.js
(function (root, factory) {
if(typeof define === "function" && define.amd) {
define("class-wrapper", [], factory);
} else if(typeof module === "object" && module.exports) {
module.exports = factory();
} else {
root["class-wrapper"] = factory();
}
})(this, function() {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define([], function () {
return (root['ClassWrapper'] = factory());
});
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
root['class-wrapper'] = factory();
}
}(this, function () {
// Set of wrappers for easier definition of different kinds of classes

@@ -16,3 +23,3 @@ // v1.0.3

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Copyright (c) 2016-2018 Valerii Zinchenko

@@ -106,3 +113,3 @@ Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Copyright (c) 2016-2018 Valerii Zinchenko

@@ -132,3 +139,3 @@ Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)

* - save the inheritance chain
* - define the classes/functions/objects that are going to be encapsulated into the resulting class. The last encapsulated object will have a precndence over the previose objects, even parent class. Only the own properties of the new class will have the highest precedence
* - define the classes/functions/objects that are going to be encapsulated into the resulting class. The last encapsulated object will have a precedence over the previous objects, even parent class. Only the own properties of the new class will have the highest precedence
* - the reference to the parent class is stored in 'parent' property

@@ -138,5 +145,11 @@ * - inherited methods are stored in class prototype object

*
* @see {@link Class}
* @see {@link SingletonClass}
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @param {Function} InstanceBuilder - Function that defines how instances will be created, how constructor(s) will be executed
* @param {Function} [Parent = Object] - Parent class
* @param {Function | null} Constructor - Cconstructor function
* @param {Function | null} Constructor - Constructor function
* @param {Object} props - Object of properties and methods for a new class. Property names that are used internally and will be ignored by encapsulation:

@@ -147,10 +160,6 @@ * - __constructor

* If some of the object has "__defaults" object, then all of it's properties will be treated as an object of default properties that a new class should have.
* @param {String} [props.__name] - Specify the class name. If ommited, "Class" will be displayed.
* @param {Object | Function | Class | Array} [props.Implement] - Define which interface or an array of interfaces should be implemented in the new class
* @param {Object | Function | Class | Array} [props.Encapsulate] - Define which object/function/class or an array of objects/functions/classes should be encapsulated into the new class
* @returns {Function} Class
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @see {@link Class}
* @see {@link SingletonClass}
*/

@@ -182,6 +191,16 @@ function ClassBuilder(InstanceBuilder, Parent, Constructor, props) {

// Extract class name if defined
// --------------------------------------------------
var className = '';
if (typeof props.__name === 'string' && props.__name) {
className = props.__name;
}
delete props.__name;
// --------------------------------------------------
// Prepare an array of what is going to be encapsulated into a new class
// --------------------------------------------------
var encapsulations = [];
// Collect objects properties and methods of which will be encapsulated into a new class
// Collect objects properties and methods
if (props.Encapsulate) {

@@ -219,3 +238,6 @@ if (Object.prototype.toString.call(props.Encapsulate) === '[object Array]') {

var Class;
eval('Class = ' + InstanceBuilder.toString());
var declaration = className
? 'var ' + className + '; Class = ' + className + ' = '
: 'Class = ';
eval(declaration + InstanceBuilder.toString());
// --------------------------------------------------

@@ -278,3 +300,3 @@

// Clone objects and store the copies into "__defaults"
// Clone objects and store the copies into "__defaults"
case '[object Object]':

@@ -292,3 +314,3 @@ if (key === '__defaults') {

// Store evererything else into "__defaults" container
// Store everything else into "__defaults" container
default:

@@ -302,3 +324,3 @@ to.prototype.__defaults[key] = value;

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Copyright (c) 2016-2018 Valerii Zinchenko

@@ -356,2 +378,8 @@ Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)

*
* @see {@link ClassBuilder}
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @param {Function} [Parent] - Parent class
* @param {Function | null} Constructor - Class constructor. The second last argument

@@ -361,7 +389,2 @@ * @param {Object} props - Defines the properties and methods for a new class. The last input argument

* @returns {Function} Class
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @see {@link ClassBuilder}
*/

@@ -374,3 +397,3 @@ var Class = ClassBuilder.bind(null, function() {

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Copyright (c) 2016-2018 Valerii Zinchenko

@@ -398,2 +421,7 @@ Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)

*
* @see {@link ClassBuilder}
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @param {Function | null} Constructor - Class constructor. The second last argument

@@ -403,7 +431,2 @@ * @param {Object} props - Defines the properties and methods for a new class. The last input argument

* @returns {Function} Class
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @see {@link ClassBuilder}
*/

@@ -422,8 +445,11 @@ var SingletonClass = ClassBuilder.bind(null, function() {

return {
utils: utils,
ClassBuilder: ClassBuilder,
Class: Class,
SingletonClass: SingletonClass
};
});
var ClassWrapper = {
utils: utils,
ClassBuilder: ClassBuilder,
Class: Class,
SingletonClass: SingletonClass
};
return ClassWrapper;
}));

@@ -7,2 +7,2 @@ // Set of wrappers for easier definition of different kinds of classes

!function(a,b){"function"==typeof define&&define.amd?define("class-wrapper",[],b):"object"==typeof module&&module.exports?module.exports=b():a["class-wrapper"]=b()}(this,function(){"use strict";function ClassBuilder(InstanceBuilder,Parent,Constructor,props){if(props=arguments[arguments.length-1],Constructor=arguments[arguments.length-2],3===arguments.length&&(Parent=Object),arguments.length<3||"function"!=typeof InstanceBuilder||"[object Function]"!==Object.prototype.toString.call(Parent)||null!==Constructor&&"function"!=typeof Constructor||"[object Object]"!==Object.prototype.toString.call(props))throw new Error("Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)");var encapsulations=[];if(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),encapsulations.some(function(a){var b=Object.prototype.toString.call(a);return"[object Function]"!==b&&"[object Object]"!==b}))throw new Error("Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class");var Class;eval("Class = "+InstanceBuilder.toString()),Class.prototype=Object.create(Parent.prototype),Class.prototype.constructor=Class,Constructor&&(Class.prototype.__constructor=Constructor),Class.prototype.__defaults={},Class.__parent=Parent.prototype;for(var n=0,N=encapsulations.length;n<N;n++)ClassBuilder.encapsulate(encapsulations[n],Class);return Class}function ParentConstructorFirst(){utils.deepExtend(this,this.constructor.prototype.__defaults),function a(b,c,d){var e=c.constructor.__parent;e&&a(b,e,d),c.hasOwnProperty("__constructor")&&c.__constructor.apply(b,d)}(this,this.constructor.__parent,arguments),this.constructor.prototype.hasOwnProperty("__constructor")&&this.constructor.prototype.__constructor.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}};ClassBuilder.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&&"__constructor"!==c&&"__parent"!==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}}};var Class=ClassBuilder.bind(null,function(){ParentConstructorFirst.apply(this,arguments)}),SingletonClass=ClassBuilder.bind(null,function(){if(this.constructor.instance)return this.constructor.instance;this.constructor.instance=this,ParentConstructorFirst.apply(this,arguments)});return{utils:utils,ClassBuilder:ClassBuilder,Class:Class,SingletonClass:SingletonClass}});
!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.ClassWrapper=b()}):"object"==typeof module&&module.exports?module.exports=b():a["class-wrapper"]=b()}(this,function(){"use strict";function ClassBuilder(InstanceBuilder,Parent,Constructor,props){if(props=arguments[arguments.length-1],Constructor=arguments[arguments.length-2],3===arguments.length&&(Parent=Object),arguments.length<3||"function"!=typeof InstanceBuilder||"[object Function]"!==Object.prototype.toString.call(Parent)||null!==Constructor&&"function"!=typeof Constructor||"[object Object]"!==Object.prototype.toString.call(props))throw new Error("Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)");var className="";"string"==typeof props.__name&&props.__name&&(className=props.__name),delete props.__name;var encapsulations=[];if(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),encapsulations.some(function(a){var b=Object.prototype.toString.call(a);return"[object Function]"!==b&&"[object Object]"!==b}))throw new Error("Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class");var Class,declaration=className?"var "+className+"; Class = "+className+" = ":"Class = ";eval(declaration+InstanceBuilder.toString()),Class.prototype=Object.create(Parent.prototype),Class.prototype.constructor=Class,Constructor&&(Class.prototype.__constructor=Constructor),Class.prototype.__defaults={},Class.__parent=Parent.prototype;for(var n=0,N=encapsulations.length;n<N;n++)ClassBuilder.encapsulate(encapsulations[n],Class);return Class}function ParentConstructorFirst(){utils.deepExtend(this,this.constructor.prototype.__defaults),function a(b,c,d){var e=c.constructor.__parent;e&&a(b,e,d),c.hasOwnProperty("__constructor")&&c.__constructor.apply(b,d)}(this,this.constructor.__parent,arguments),this.constructor.prototype.hasOwnProperty("__constructor")&&this.constructor.prototype.__constructor.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}};ClassBuilder.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&&"__constructor"!==c&&"__parent"!==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}}};var Class=ClassBuilder.bind(null,function(){ParentConstructorFirst.apply(this,arguments)}),SingletonClass=ClassBuilder.bind(null,function(){if(this.constructor.instance)return this.constructor.instance;this.constructor.instance=this,ParentConstructorFirst.apply(this,arguments)}),ClassWrapper={utils:utils,ClassBuilder:ClassBuilder,Class:Class,SingletonClass:SingletonClass};return ClassWrapper});

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

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

@@ -25,26 +25,10 @@ }

wrap: {
umd: {
pkg: {
src: ['dest/<%= pkg.name %>.js'],
dest: 'dest/<%= pkg.name %>.js',
options: {
wrapper: [
'(function (root, factory) {\n' +
' if(typeof define === "function" && define.amd) {\n' +
' define("<%= pkg.name %>", [], factory);\n' +
' } else if(typeof module === "object" && module.exports) {\n' +
' module.exports = factory();\n' +
' } else {\n' +
' root["<%= pkg.name %>"] = factory();\n' +
' }\n' +
'})(this, function() {',
// code will be placed right here
' return {\n' +
' utils: utils,\n' +
' ClassBuilder: ClassBuilder,\n' +
' Class: Class,\n' +
' SingletonClass: SingletonClass\n' +
' };\n' +
'});'
]
src: ['dest/<%= pkg.name %>.js'],
dest: 'dest/<%= pkg.name %>.js',
template: 'umd.hbs',
objectToExport: 'ClassWrapper',
globalAlias: 'class-wrapper'
}

@@ -177,3 +161,3 @@ }

[
['build', ['clean:build', 'concat', 'wrap', 'uglify', 'template:test']],
['build', ['clean:build', 'concat', 'umd', 'uglify', 'template:test']],
['test', ['template:test', 'mocha:test']],

@@ -180,0 +164,0 @@ ['coverage', ['prepareForCoverage', 'template:coverage', 'mocha:coverage', 'clean:coverage', 'template:test']],

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Copyright (c) 2016-2018 Valerii Zinchenko

@@ -55,2 +55,8 @@ Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)

*
* @see {@link ClassBuilder}
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @param {Function} [Parent] - Parent class
* @param {Function | null} Constructor - Class constructor. The second last argument

@@ -60,7 +66,2 @@ * @param {Object} props - Defines the properties and methods for a new class. The last input argument

* @returns {Function} Class
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @see {@link ClassBuilder}
*/

@@ -67,0 +68,0 @@ var Class = ClassBuilder.bind(null, function() {

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Copyright (c) 2016-2018 Valerii Zinchenko

@@ -27,3 +27,3 @@ Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)

* - save the inheritance chain
* - define the classes/functions/objects that are going to be encapsulated into the resulting class. The last encapsulated object will have a precndence over the previose objects, even parent class. Only the own properties of the new class will have the highest precedence
* - define the classes/functions/objects that are going to be encapsulated into the resulting class. The last encapsulated object will have a precedence over the previous objects, even parent class. Only the own properties of the new class will have the highest precedence
* - the reference to the parent class is stored in 'parent' property

@@ -33,5 +33,11 @@ * - inherited methods are stored in class prototype object

*
* @see {@link Class}
* @see {@link SingletonClass}
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @param {Function} InstanceBuilder - Function that defines how instances will be created, how constructor(s) will be executed
* @param {Function} [Parent = Object] - Parent class
* @param {Function | null} Constructor - Cconstructor function
* @param {Function | null} Constructor - Constructor function
* @param {Object} props - Object of properties and methods for a new class. Property names that are used internally and will be ignored by encapsulation:

@@ -43,9 +49,4 @@ * - __constructor

* @param {Object | Function | Class | Array} [props.Encapsulate] - Define which object/function/class or an array of objects/functions/classes should be encapsulated into the new class
* @param {String} [props.__name = "Class"] - Specify the class name what will be visible near the variables during the debugging.
* @returns {Function} Class
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @see {@link Class}
* @see {@link SingletonClass}
*/

@@ -77,6 +78,16 @@ function ClassBuilder(InstanceBuilder, Parent, Constructor, props) {

// Extract class name if defined
// --------------------------------------------------
var className = '';
if (typeof props.__name === 'string' && props.__name) {
className = props.__name;
}
delete props.__name;
// --------------------------------------------------
// Prepare an array of what is going to be encapsulated into a new class
// --------------------------------------------------
var encapsulations = [];
// Collect objects properties and methods of which will be encapsulated into a new class
// Collect objects properties and methods
if (props.Encapsulate) {

@@ -114,3 +125,6 @@ if (Object.prototype.toString.call(props.Encapsulate) === '[object Array]') {

var Class;
eval('Class = ' + InstanceBuilder.toString());
var declaration = className
? 'var ' + className + '; Class = ' + className + ' = '
: 'Class = ';
eval(declaration + InstanceBuilder.toString());
// --------------------------------------------------

@@ -173,3 +187,3 @@

// Clone objects and store the copies into "__defaults"
// Clone objects and store the copies into "__defaults"
case '[object Object]':

@@ -187,3 +201,3 @@ if (key === '__defaults') {

// Store evererything else into "__defaults" container
// Store everything else into "__defaults" container
default:

@@ -190,0 +204,0 @@ to.prototype.__defaults[key] = value;

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Copyright (c) 2016-2018 Valerii Zinchenko

@@ -25,2 +25,7 @@ Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)

*
* @see {@link ClassBuilder}
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @param {Function | null} Constructor - Class constructor. The second last argument

@@ -30,7 +35,2 @@ * @param {Object} props - Defines the properties and methods for a new class. The last input argument

* @returns {Function} Class
*
* @throws {Error} Incorrect input arguments. It should be: ClassBuilder(Function, [Function], Function | null, Object)
* @throws {Error} Some of the items for encapsulation is incorrect. An item can be: Object, Function, Class
*
* @see {@link ClassBuilder}
*/

@@ -37,0 +37,0 @@ var SingletonClass = ClassBuilder.bind(null, function() {

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Copyright (c) 2016-2018 Valerii Zinchenko

@@ -4,0 +4,0 @@ Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)

The MIT License (MIT)
Copyright (c) 2016-2017 Valerii Zinchenko
Copyright (c) 2016-2018 Valerii Zinchenko

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

{
"name": "class-wrapper",
"version": "1.0.3",
"version": "1.1.0",
"description": "Set of wrappers for easier definition of different kinds of classes",

@@ -13,4 +13,8 @@ "main": "dest/class-wrapper.js",

"scripts": {
"preversion": "grunt test",
"prepublish": "grunt build"
"test": "grunt test",
"build": "grunt build",
"doc": "grunt doc",
"coverage": "grunt coverage",
"preversion": "npm test",
"prepublishOnly": "npm build"
},

@@ -31,3 +35,3 @@ "directories": {

"grunt-template": "^1.0.0",
"grunt-wrap": "^0.3.0",
"grunt-umd": "^2.4.0",
"istanbul": "^0.4.5",

@@ -34,0 +38,0 @@ "load-grunt-tasks": "^3.5.2",

@@ -82,3 +82,3 @@ # {class}

console.log(someRect.calcArea()); // the square is: 8
console.log(someRect.calcArea()); // the area is: 8

@@ -93,3 +93,3 @@

console.log(someSqrt.calcArea()); // the square is: 25
console.log(someSqrt.calcArea()); // the area is: 25
```

@@ -96,0 +96,0 @@

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

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)
All source files are available at: http://github.com/valerii-zinchenko/class-wrapper
*/
suite('Instance from a Class', function() {

@@ -11,0 +2,0 @@ test('creating an instance without any specified constructor', function(){

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

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)
All source files are available at: http://github.com/valerii-zinchenko/class-wrapper
*/
'use strict';
suite('ClassBuilder', function() {

@@ -195,15 +185,29 @@ suite('Input arguments are', function() {

assert.isArray(ref.__defaults.array, 'Array type was not copied');
assert.isTrue(ref.__defaults.array[0] === properties.array[0] && ref.__defaults.array[1] === properties.array[1], 'Array items was incorrectly copied');
assert.isTrue(ref.__defaults.array[0] === properties.array[0] && ref.__defaults.array[1] === properties.array[1], 'Array items were incorrectly copied');
assert.isObject(ref.__defaults.nestedObj, 'Object type was not saved');
assert.notEqual(ref.__defaults.nestedObj, properties.nestedObj, 'Object from a properties should be shared');
assert.notEqual(ref.__defaults.nestedObj, properties.nestedObj, 'Object from a properties should not be shared');
assert.isObject(ref.__defaults.nestedObj.innerObj, 'Inner object was not saved');
assert.notEqual(ref.__defaults.nestedObj.innerObj, properties.nestedObj.innerObj, 'Inner nested object from a properties should be shared');
assert.notEqual(ref.__defaults.nestedObj.innerObj, properties.nestedObj.innerObj, 'Inner nested object from a properties should not be shared');
assert.equal(ref.__defaults.nestedObj.innerObj.v, properties.nestedObj.innerObj.v, 'Value of most inner object was not copied');
assert.equal(ref.__defaults.nestedObj.prop, properties.nestedObj.prop, 'Object properties was incorrectly copied');
assert.isFunction(ref.fn, 'All functions should be saved in prototype for desired reuse');
assert.isFunction(ref.fn, 'All functions should be saved in prototype for reuse');
assert.equal(ref.fn, properties.fn, 'Functions should be shared');
});
// this test is skipped because it is failing in PhantomJS, but works good in a browser and node
test.skip('define a name of the class', function() {
var name = "NamedClass";
var result;
assert.doesNotThrow(function(){
result = ClassBuilder(function(){}, function(){}, {
__name: name
});
});
assert.equal(result.name, name);
});
suite('Encapsulate', function(){

@@ -210,0 +214,0 @@ var fns = {

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

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)
All source files are available at: http://github.com/valerii-zinchenko/class-wrapper
*/
suite('Instance from a SingletonClass', function() {

@@ -11,0 +2,0 @@ test('creating an instance without any specified constructor', function(){

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

/*
Copyright (c) 2016-2017 Valerii Zinchenko
Licensed under MIT (https://github.com/valerii-zinchenko/class-wrapper/blob/master/LICENSE.txt)
All source files are available at: http://github.com/valerii-zinchenko/class-wrapper
*/
suite('utils', function() {

@@ -11,0 +2,0 @@ suite('Object manipulations.', function() {

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