js.private
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -11,2 +11,4 @@ "use strict"; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -48,8 +50,16 @@ | ||
value: function set(context) { | ||
var props = Object.create(this._props_); | ||
var props = Object.create(this._props_, this.descriptor(this._key_, context)); | ||
for (var attr in this._props_) { | ||
if (this._props_.hasOwnProperty(attr) && typeof this._props_[attr] === "object") props[attr] = (0, _jsClone2["default"])(this._props_[attr]); | ||
}props[this._key_] = context; | ||
return context[this._key_] = props; | ||
}return Object.defineProperties(context, this.descriptor(this._key_, props))[this._key_]; | ||
} | ||
}, { | ||
key: "descriptor", | ||
value: function descriptor(name, value) { | ||
var configurable = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; | ||
var writable = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3]; | ||
var enumerable = arguments.length <= 4 || arguments[4] === undefined ? false : arguments[4]; | ||
return _defineProperty({}, name, { value: value, configurable: configurable, writable: writable, enumerable: enumerable }); | ||
} | ||
}]); | ||
@@ -56,0 +66,0 @@ |
@@ -1,9 +0,17 @@ | ||
var gulp = require( "gulp" ), | ||
babel = require( "gulp-babel" ); | ||
var gulp = require( "gulp" ), | ||
babel = require( "gulp-babel" ), | ||
src = "./src/**/*.js", | ||
dst = "./dst"; | ||
gulp.task( "build", function(){ | ||
return gulp.src( "./src/**/*.js" ) | ||
return gulp.src( src ) | ||
.pipe( babel() ) | ||
.pipe( gulp.dest( "./dst" ) ); | ||
.pipe( gulp.dest( dst ) ); | ||
}); | ||
gulp.task( "watch", function(){ | ||
return gulp.watch( src, [ "build" ] ) | ||
}); | ||
gulp.task( "default", [ "build", "watch" ] ); |
{ | ||
"name": "js.private", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Private properties for objects", | ||
"main": "./dst/Private.js", | ||
"scripts": { | ||
"start": "gulp", | ||
"build": "gulp build" | ||
}, | ||
"author": "Denis Churbanov", | ||
"author": { | ||
"name": "Denis Churbanov" | ||
}, | ||
"license": "MIT", | ||
@@ -17,3 +20,9 @@ "devDependencies": { | ||
"js.clone": ">0.0.1" | ||
} | ||
}, | ||
"readme": "### Install\r\n\r\n```\r\nnpm install js.private --save\r\n```\r\n\r\n### Usage\r\n\r\n```javascript\r\n\r\nimport Private from \"js.private\";\r\n\r\nclass People {\r\n\r\n\tconstructor( firstname, lastname, gender ){\r\n\t\t$( this ).firstname = firstname; // private property\r\n\t\t$( this ).lastname = lastname; // private property\r\n\t\tthis.gender = gender; // public property\r\n\t}\r\n\r\n\tget info(){\r\n\t\treturn $( this ).generateInfo(); // call private method\r\n\t}\r\n\r\n}\r\n\r\nlet $ = Private({\r\n\tfirstname: \"DefaultFirstName\",\r\n\tlastname: \"DefaultLastName\",\r\n\tgenerateInfo: function(){\r\n\t\treturn $( this ).firstname + \" \" + $( this ).lastname + \" (\" + this.gender + \")\";\r\n\t}\r\n});\r\n\r\n\r\nlet man = new People( \"Denis\", \"Churbanov\", \"man\" );\r\n\r\nman.info // > \"Denis Churbanov (man)\"\r\nman.gender // > \"man\"\r\nman.firstname // > undefined\r\nman.lastname // > undefined\r\nman.generateInfo // > undefined\r\n```\r\n\r\n", | ||
"readmeFilename": "README.md", | ||
"gitHead": "51b92f56d4a5c68ba3f77ef732381c20c3c927b7", | ||
"_id": "js.private@0.2.0", | ||
"_shasum": "eeb514909a532b1a1f77c2d86bd6717ca9f0d5d0", | ||
"_from": "js.private@>0.0.3" | ||
} |
@@ -27,7 +27,8 @@ ### Install | ||
let $ = Private({ | ||
const $ = Private({ | ||
firstname: "DefaultFirstName", | ||
lastname: "DefaultLastName", | ||
age: 28, | ||
generateInfo: function(){ | ||
return $( this ).firstname + " " + $( this ).lastname + " (" + this.gender + ")"; | ||
return `${ $( this ).firstname } ${ $( this ).lastname } (${ this.gender }, ${ $( this ).age })`; | ||
} | ||
@@ -39,3 +40,3 @@ }); | ||
man.info // > "Denis Churbanov (man)" | ||
man.info // > "Denis Churbanov (man, 28)" | ||
man.gender // > "man" | ||
@@ -42,0 +43,0 @@ man.firstname // > undefined |
@@ -10,3 +10,3 @@ import Clone from "js.clone"; | ||
} | ||
prepare( props ){ | ||
@@ -18,3 +18,3 @@ for( let attr in props ) | ||
} | ||
bind( key, method ){ | ||
@@ -31,9 +31,12 @@ return function(){ | ||
set( context ){ | ||
let props = Object.create( this._props_ ) | ||
let props = Object.create( this._props_, this.descriptor( this._key_, context ) ); | ||
for( let attr in this._props_ ) | ||
if( this._props_.hasOwnProperty( attr ) && typeof this._props_[ attr ] === `object` ) | ||
props[ attr ] = Clone( this._props_[ attr ] ); | ||
props[ this._key_ ] = context; | ||
return context[ this._key_ ] = props; | ||
return Object.defineProperties( context, this.descriptor( this._key_, props ) )[ this._key_ ]; | ||
} | ||
descriptor( name, value, configurable = false, writable = false, enumerable = false ){ | ||
return { [ name ]: { value, configurable, writable, enumerable } }; | ||
} | ||
@@ -48,2 +51,2 @@ } | ||
}; | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7408
110
46