cla6-hidden
Advanced tools
Comparing version 1.0.1 to 1.0.3
{ | ||
"name": "cla6-hidden", | ||
"version": "1.0.1", | ||
"description": "Hidden plugin for Cla6.js", | ||
"version": "1.0.3", | ||
"main": "client/cla6-hidden.js", | ||
@@ -9,5 +10,2 @@ "repository": { | ||
}, | ||
"dependencies": { | ||
"cla6": "~1.1.0" | ||
}, | ||
"devDependencies": { | ||
@@ -17,2 +15,3 @@ "browserify": "~9.0.0", | ||
"chai-spies": "~0.5.0", | ||
"cla6": "~1.1.0", | ||
"mocha": "~2.1.0", | ||
@@ -19,0 +18,0 @@ "uglify-js": "~2.4.0" |
(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 Cla6 = require('cla6'); |
var Cla6Hidden = require('..'); |
Cla6.use(Cla6Hidden); |
},{"..":2,"cla6":4}],2:[function(require,module,exports){ |
},{"..":2}],2:[function(require,module,exports){ |
var _ = require('./utils'); |
@@ -13,13 +12,13 @@ |
function Hidden(props) { |
var _props = {}; |
function Hidden(descriptors) { |
var _descriptors = {}; |
props[hiddenField] = { |
value: _props |
descriptors[hiddenField] = { |
value: _descriptors |
}; |
Object.keys(props).filter(function(k) { |
Object.keys(descriptors).filter(function(k) { |
if (k[0] == '_' && k != hiddenField) { |
_.move(props, _props, k); |
_props[k].enumerable = true; |
_.move(descriptors, _descriptors, k); |
_descriptors[k].enumerable = true; |
} else { |
@@ -31,5 +30,5 @@ return true; |
if (k == 'constructor') |
props.constructor.value = wrapCtor(props.constructor.value); |
descriptors.constructor.value = wrapCtor(descriptors.constructor.value); |
else |
wrapDescriptor(props[k]); |
wrapDescriptor(descriptors[k]); |
}); |
@@ -52,3 +51,3 @@ } |
var _props = ancestors.map(function(ancestor) { |
var _descriptors = ancestors.map(function(ancestor) { |
return ancestor.prototype[hiddenField]; |
@@ -61,3 +60,3 @@ }) |
var hidden = Object.defineProperties({}, _props); |
var hidden = Object.defineProperties({}, _descriptors); |
Object.defineProperty(this, hiddenField, {value: hidden}); |
@@ -147,146 +146,2 @@ } |
}; |
},{}],4:[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":5,"./extender":6}],5:[function(require,module,exports){ |
var _ = require('./utils'); |
var plugins = []; |
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 fixedProps = getFixedProps(props); |
applyPlugins(fixedProps); |
var Child = _.nameFn(fixedProps.constructor.value, name); |
fixedProps.constructor.value = Child; |
Child.prototype = Object.create(Parent.prototype, fixedProps); |
return Child; |
}; |
var getFixedProps = 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; |
}, {}); |
}; |
var addPlugin = function(plugin) { |
plugins.push(plugin); |
}; |
var applyPlugins = function(props) { |
plugins.forEach(function(plugin) { |
plugin(props); |
}); |
}; |
module.exports = { |
create: createClass, |
use: addPlugin |
}; |
},{"./utils":7}],6:[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":5}],7:[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 nameFn = function(fn, name) { |
return eval('(function ' + name + '() {return fn.apply(this, arguments);})'); |
}; |
module.exports = { |
clone: clone, |
nameFn: nameFn |
}; |
},{}]},{},[1]); |
@@ -1,1 +0,1 @@ |
(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 Cla6=require("cla6");var Cla6Hidden=require("..");Cla6.use(Cla6Hidden)},{"..":2,cla6:4}],2:[function(require,module,exports){var _=require("./utils");var hiddenField=_.createArr(10).reduce(function(result){return result+_.randomDigit()},"__cla6Hidden__");function Hidden(props){var _props={};props[hiddenField]={value:_props};Object.keys(props).filter(function(k){if(k[0]=="_"&&k!=hiddenField){_.move(props,_props,k);_props[k].enumerable=true}else{return true}}).forEach(function(k){if(k=="constructor")props.constructor.value=wrapCtor(props.constructor.value);else wrapDescriptor(props[k])})}wrapDescriptor=function(descriptor){["value","get","set"].filter(function(k){return typeof descriptor[k]=="function"}).forEach(function(k){descriptor[k]=wrapMethod(descriptor[k])})};wrapCtor=function(ctor){return function(){if(!this.hasOwnProperty(hiddenField)){var ancestors=_.getAncestors(this);var _props=ancestors.map(function(ancestor){return ancestor.prototype[hiddenField]}).reduce(function(result,hidden){_.copy(hidden,result);return result},{});var hidden=Object.defineProperties({},_props);Object.defineProperty(this,hiddenField,{value:hidden})}return wrapMethod(ctor).apply(this,arguments)}};wrapMethod=function(method){return function(){swapHidden(this);var result=method.apply(this,arguments);swapHidden(this);return result}};swapHidden=function(obj){var hidden=obj[hiddenField];_.swap(hidden,obj);Object.keys(hidden).filter(function(k){return k[0]!="_"}).forEach(function(k){_.move(hidden,obj,k)})};module.exports=Hidden},{"./utils":3}],3:[function(require,module,exports){var createArr=function(length){return Array.apply(null,{length:length})};var randomDigit=function(){return parseInt(Math.random()*10)};getAncestors=function(obj){var ancestor=Object.getPrototypeOf(obj).constructor;if(ancestor===Object)return[];else return getAncestors(ancestor.prototype).concat(ancestor)};var swap=function(src,dst){var temp={};move(src,temp);move(dst,src);copy(temp,dst)};var move=function(src,dst,k){if(k==null){Object.keys(src).forEach(function(k){move(src,dst,k)})}else{copy(src,dst,k);delete src[k]}};var copy=function(src,dst,k){if(k==null){Object.keys(src).forEach(function(k){copy(src,dst,k)})}else{var descriptor=Object.getOwnPropertyDescriptor(src,k);Object.defineProperty(dst,k,descriptor)}};module.exports={createArr:createArr,randomDigit:randomDigit,getAncestors:getAncestors,swap:swap,move:move,copy:copy}},{}],4:[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":5,"./extender":6}],5:[function(require,module,exports){var _=require("./utils");var plugins=[];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 fixedProps=getFixedProps(props);applyPlugins(fixedProps);var Child=_.nameFn(fixedProps.constructor.value,name);fixedProps.constructor.value=Child;Child.prototype=Object.create(Parent.prototype,fixedProps);return Child};var getFixedProps=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},{})};var addPlugin=function(plugin){plugins.push(plugin)};var applyPlugins=function(props){plugins.forEach(function(plugin){plugin(props)})};module.exports={create:createClass,use:addPlugin}},{"./utils":7}],6:[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":5}],7:[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 nameFn=function(fn,name){return eval("(function "+name+"() {return fn.apply(this, arguments);})")};module.exports={clone:clone,nameFn:nameFn}},{}]},{},[1]); |
(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 Cla6Hidden=require("..");Cla6.use(Cla6Hidden)},{"..":2}],2:[function(require,module,exports){var _=require("./utils");var hiddenField=_.createArr(10).reduce(function(result){return result+_.randomDigit()},"__cla6Hidden__");function Hidden(descriptors){var _descriptors={};descriptors[hiddenField]={value:_descriptors};Object.keys(descriptors).filter(function(k){if(k[0]=="_"&&k!=hiddenField){_.move(descriptors,_descriptors,k);_descriptors[k].enumerable=true}else{return true}}).forEach(function(k){if(k=="constructor")descriptors.constructor.value=wrapCtor(descriptors.constructor.value);else wrapDescriptor(descriptors[k])})}wrapDescriptor=function(descriptor){["value","get","set"].filter(function(k){return typeof descriptor[k]=="function"}).forEach(function(k){descriptor[k]=wrapMethod(descriptor[k])})};wrapCtor=function(ctor){return function(){if(!this.hasOwnProperty(hiddenField)){var ancestors=_.getAncestors(this);var _descriptors=ancestors.map(function(ancestor){return ancestor.prototype[hiddenField]}).reduce(function(result,hidden){_.copy(hidden,result);return result},{});var hidden=Object.defineProperties({},_descriptors);Object.defineProperty(this,hiddenField,{value:hidden})}return wrapMethod(ctor).apply(this,arguments)}};wrapMethod=function(method){return function(){swapHidden(this);var result=method.apply(this,arguments);swapHidden(this);return result}};swapHidden=function(obj){var hidden=obj[hiddenField];_.swap(hidden,obj);Object.keys(hidden).filter(function(k){return k[0]!="_"}).forEach(function(k){_.move(hidden,obj,k)})};module.exports=Hidden},{"./utils":3}],3:[function(require,module,exports){var createArr=function(length){return Array.apply(null,{length:length})};var randomDigit=function(){return parseInt(Math.random()*10)};getAncestors=function(obj){var ancestor=Object.getPrototypeOf(obj).constructor;if(ancestor===Object)return[];else return getAncestors(ancestor.prototype).concat(ancestor)};var swap=function(src,dst){var temp={};move(src,temp);move(dst,src);copy(temp,dst)};var move=function(src,dst,k){if(k==null){Object.keys(src).forEach(function(k){move(src,dst,k)})}else{copy(src,dst,k);delete src[k]}};var copy=function(src,dst,k){if(k==null){Object.keys(src).forEach(function(k){copy(src,dst,k)})}else{var descriptor=Object.getOwnPropertyDescriptor(src,k);Object.defineProperty(dst,k,descriptor)}};module.exports={createArr:createArr,randomDigit:randomDigit,getAncestors:getAncestors,swap:swap,move:move,copy:copy}},{}]},{},[1]); |
@@ -1,4 +0,3 @@ | ||
var Cla6 = require('cla6'); | ||
var Cla6Hidden = require('..'); | ||
Cla6.use(Cla6Hidden); |
@@ -7,13 +7,13 @@ var _ = require('./utils'); |
function Hidden(props) { |
var _props = {}; |
function Hidden(descriptors) { |
var _descriptors = {}; |
props[hiddenField] = { |
value: _props |
descriptors[hiddenField] = { |
value: _descriptors |
}; |
Object.keys(props).filter(function(k) { |
Object.keys(descriptors).filter(function(k) { |
if (k[0] == '_' && k != hiddenField) { |
_.move(props, _props, k); |
_props[k].enumerable = true; |
_.move(descriptors, _descriptors, k); |
_descriptors[k].enumerable = true; |
} else { |
@@ -25,5 +25,5 @@ return true; |
if (k == 'constructor') |
props.constructor.value = wrapCtor(props.constructor.value); |
descriptors.constructor.value = wrapCtor(descriptors.constructor.value); |
else |
wrapDescriptor(props[k]); |
wrapDescriptor(descriptors[k]); |
}); |
@@ -46,3 +46,3 @@ } |
var _props = ancestors.map(function(ancestor) { |
var _descriptors = ancestors.map(function(ancestor) { |
return ancestor.prototype[hiddenField]; |
@@ -55,3 +55,3 @@ }) |
var hidden = Object.defineProperties({}, _props); |
var hidden = Object.defineProperties({}, _descriptors); |
Object.defineProperty(this, hiddenField, {value: hidden}); |
@@ -58,0 +58,0 @@ } |
{ | ||
"name": "cla6-hidden", | ||
"version": "1.0.1", | ||
"description": "Hidden plugin for Cla6.js", | ||
"version": "1.0.3", | ||
"main": "lib/hidden.js", | ||
@@ -9,5 +10,2 @@ "repository": { | ||
}, | ||
"dependencies": { | ||
"cla6": "~1.1.0" | ||
}, | ||
"devDependencies": { | ||
@@ -17,2 +15,3 @@ "browserify": "~9.0.0", | ||
"chai-spies": "~0.5.0", | ||
"cla6": "~1.1.0", | ||
"mocha": "~2.1.0", | ||
@@ -19,0 +18,0 @@ "uglify-js": "~2.4.0" |
@@ -1,8 +0,5 @@ | ||
# Cla6 Hidden | ||
Hidden plugin for Cla6.js. | ||
# Cla6 Hidden | ||
This is an addon plugin for [Cla6.js](https://github.com/DAB0mB/cla6) class system library. It provides the ability to hide some of the instance's properties and therefore make some of your api's logic private without exposing it. | ||
This is an addon plugin for [Cla6.js](https://github.com/DAB0mB/cla6) class system library. It provides the ability to hide some of the instance's properties and therefore make some of your api's logic private without exposing it. Although originally designed for use with [Node.js](http://nodejs.org) and installable via `npm install cla6-hidden`, it can also be used directly in the browser. | ||
Although originally designed for use with [Node.js](http://nodejs.org) and installable via `npm install cla6-hidden`, it can also be used directly in the browser. | ||
Cla6 Hidden is also installable via: | ||
@@ -12,3 +9,3 @@ | ||
## Examples | ||
## Basic Examples | ||
@@ -31,3 +28,3 @@ ```js | ||
You may also define hidden properties on the prototype, and don't worry, Cla6-Hidden also knows how to handle the inheritance process: | ||
You may also define hidden properties on the prototype. Don't worry, Cla6-Hidden also knows how to handle the inheritance process: | ||
@@ -53,6 +50,7 @@ ```js | ||
## How To Plug | ||
## How To Use | ||
```js | ||
var Cla6 = require('cla6') | ||
var Cla6Hidden = require('cla6-hidden') | ||
var Cla6 = require('cla6'); | ||
var Cla6Hidden = require('cla6-hidden'); | ||
@@ -63,2 +61,3 @@ Cla6.use(Cla6Hidden); | ||
## Download | ||
The source is available for download from | ||
@@ -65,0 +64,0 @@ [GitHub](http://github.com/DAB0mB/cla6-hidden). |
@@ -23,4 +23,4 @@ var Chai = require('chai'); |
set hidden(v) { |
this._hidden = v; |
set hidden(value) { |
this._hidden = value; |
} |
@@ -27,0 +27,0 @@ }); |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent 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
0
0
15044
6
352
1
64
- Removedcla6@~1.1.0
- Removedcla6@1.1.5(transitive)