Comparing version 1.0.0 to 1.1.0
@@ -1,17 +0,18 @@ | ||
var _ = require('./utils'); | ||
var ClassFactory = require('./classFactory'); | ||
var Extender = require('./extender'); | ||
function Cla6(name, props) { | ||
if (name == null) | ||
throw Error('Cla6 error - a name must be provided'); | ||
throwErr('a name must be provided'); | ||
if (typeof name != 'string') | ||
throw Error('Cla6 error - name must be a string'); | ||
throwErr('name must be a string'); | ||
if (props != null) { | ||
if (typeof props != 'object') | ||
throw Error('Cla6 error - properties must be defined using an object'); | ||
throwErr('properties must be defined using an object'); | ||
if (props.hasOwnProperty('constructor') && | ||
typeof props.constructor != 'function') | ||
throw Error('Cla6 error - constructor must be a function'); | ||
throwErr('constructor must be a function'); | ||
} | ||
@@ -22,31 +23,19 @@ | ||
else | ||
return _.createClass(name, props); | ||
return ClassFactory.create(name, props); | ||
} | ||
var Extender = _.createClass('Extender', { | ||
constructor: function(name) { | ||
this.name = name; | ||
}, | ||
Cla6.use = function(plugin) { | ||
if (plugin == null) | ||
throwErr('a plugin must be provided'); | ||
extend: function(Parent, props) { | ||
if (Parent == null) | ||
throw Error('Cla6 extension error - a parent must be provided'); | ||
if (typeof plugin != 'function') | ||
throwErr('plugin must be a function'); | ||
if (typeof Parent != 'function') | ||
throw Error('Cla6 extension error - parent must be a function'); | ||
ClassFactory.use(plugin); | ||
}; | ||
if (props == null) | ||
throw Error('Cla6 extension error - properties must be provided'); | ||
var throwErr = function(msg) { | ||
throw Error('Cla6 error - ' + msg); | ||
}; | ||
if (typeof props != 'object') | ||
throw Error('Cla6 extension error - properties must be defined using an object'); | ||
if (props.hasOwnProperty('constructor') && | ||
typeof props.constructor != 'function') | ||
throw Error('Cla6 extension error - constructor must be a function'); | ||
return _.createClass(this.name, props, Parent); | ||
} | ||
}); | ||
module.exports = Cla6; |
@@ -1,45 +0,15 @@ | ||
var createClass = function(name, props, Parent) { | ||
if (typeof Parent != 'function') | ||
Parent = Object; | ||
var constructor = props.constructor; | ||
if (!props.hasOwnProperty('constructor')) | ||
constructor = function() { | ||
Parent.apply(this, arguments); | ||
}; | ||
var Child = nameFn(constructor, name); | ||
var fixedProps = Object.keys(props).reduce(function(result, k) { | ||
if (k == 'constructor') | ||
return result; | ||
var descriptor = Object.getOwnPropertyDescriptor(props, k); | ||
delete descriptor.enumerable; | ||
if (descriptor.value == null) | ||
delete descriptor.writable; | ||
result[k] = descriptor; | ||
return result; | ||
}, { | ||
'constructor': { | ||
configurable: true, | ||
writable: true, | ||
value: Child | ||
} | ||
}); | ||
Child.prototype = Object.create(Parent.prototype, fixedProps); | ||
return Child; | ||
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 nameFn = function(func, name) { | ||
return eval('(function ' + name + '() {return func.apply(this, arguments);})'); | ||
var nameFn = function(fn, name) { | ||
return eval('(function ' + name + '() {return fn.apply(this, arguments);})'); | ||
}; | ||
module.exports = { | ||
createClass: createClass, | ||
clone: clone, | ||
nameFn: nameFn | ||
}; |
{ | ||
"name": "cla6", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "lib/cla6.js", | ||
"repository": { | ||
@@ -9,9 +10,11 @@ "type": "git", | ||
"devDependencies": { | ||
"browserify": "~9.0.0", | ||
"chai": "~2.1.0", | ||
"chai-spies": "~0.5.1", | ||
"mocha": "~2.1.0" | ||
"chai-spies": "~0.5.0", | ||
"mocha": "~2.1.0", | ||
"uglify-js": "~2.4.0" | ||
}, | ||
"engines": { | ||
"node": "~0.10.33" | ||
"node": "~0.10.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# Cla6 | ||
# Cla6.js | ||
ES6 style class system | ||
@@ -83,2 +83,9 @@ | ||
console.log(k); | ||
``` | ||
``` | ||
## Download | ||
The source is available for download from | ||
[GitHub](http://github.com/DAB0mB/cla6). | ||
Alternatively, you can install using Node Package Manager (`npm`): | ||
npm install cla6 |
var Chai = require('chai'); | ||
var Cla6 = require('../index'); | ||
var Cla6 = require('..'); | ||
@@ -7,3 +7,3 @@ var expect = Chai.expect; | ||
describe('cla6', function() { | ||
describe('Cla6', function() { | ||
describe('validations', function() { | ||
@@ -10,0 +10,0 @@ it('should throw an error if a name is not provided', function() { |
var Chai = require('chai'); | ||
var Cla6 = require('../index'); | ||
var Cla6 = require('..'); | ||
@@ -7,3 +7,3 @@ var expect = Chai.expect; | ||
describe('cla6', function() { | ||
describe('Cla6', function() { | ||
describe('extender', function() { | ||
@@ -10,0 +10,0 @@ it('should return an extender if only a name is provided', function() { |
@@ -9,2 +9,3 @@ var Chai = require('chai'); | ||
require('./cla6'); | ||
require('./extender'); | ||
require('./extender'); | ||
require('./plugins'); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
20649
14
399
90
5
2
4
3