Socket
Socket
Sign inDemoInstall

d

Package Overview
Dependencies
8
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 1.0.0

LICENSE

25

auto-bind.js
'use strict';
var copy = require('es5-ext/object/copy')
, map = require('es5-ext/object/map')
, callable = require('es5-ext/object/valid-callable')
, validValue = require('es5-ext/object/valid-value')
var copy = require('es5-ext/object/copy')
, normalizeOptions = require('es5-ext/object/normalize-options')
, ensureCallable = require('es5-ext/object/valid-callable')
, map = require('es5-ext/object/map')
, callable = require('es5-ext/object/valid-callable')
, validValue = require('es5-ext/object/valid-value')

@@ -12,3 +14,3 @@ , bind = Function.prototype.bind, defineProperty = Object.defineProperty

define = function (name, desc, bindTo) {
define = function (name, desc, options) {
var value = validValue(desc) && callable(desc.value), dgs;

@@ -19,4 +21,4 @@ dgs = copy(desc);

dgs.get = function () {
if (hasOwnProperty.call(this, name)) return value;
desc.value = bind.call(value, (bindTo == null) ? this : this[bindTo]);
if (!options.overwriteDefinition && hasOwnProperty.call(this, name)) return value;
desc.value = bind.call(value, options.resolveContext ? options.resolveContext(this) : this);
defineProperty(this, name, desc);

@@ -28,7 +30,6 @@ return this[name];

module.exports = function (props/*, bindTo*/) {
var bindTo = arguments[1];
return map(props, function (desc, name) {
return define(name, desc, bindTo);
});
module.exports = function (props/*, options*/) {
var options = normalizeOptions(arguments[1]);
if (options.resolveContext != null) ensureCallable(options.resolveContext);
return map(props, function (desc, name) { return define(name, desc, options); });
};

@@ -47,7 +47,10 @@ 'use strict';

// was defined with a value, following workarounds that
if (ownDesc.hasOwnProperty('value')) return ownDesc.value;
if ((typeof ownDesc.get === 'function') && (ownDesc.get !== self)) {
return ownDesc.get.call(this);
// While in IE11 it may happen that here ownDesc is undefined (go figure)
if (ownDesc) {
if (ownDesc.hasOwnProperty('value')) return ownDesc.value;
if ((typeof ownDesc.get === 'function') && (ownDesc.get !== self)) {
return ownDesc.get.call(this);
}
return value;
}
return value;
}

@@ -79,2 +82,5 @@ desc.value = resolvable ? call.call(value, this, options) : value;

dgs.set = function (value) {
if (hasOwnProperty.call(this, name)) {
throw new TypeError("Cannot assign to lazy defined '" + name + "' property of " + this);
}
dgs.get.call(this);

@@ -81,0 +87,0 @@ this[cacheName] = value;

{
"name": "d",
"version": "0.1.1",
"version": "1.0.0",
"description": "Property descriptor factory",
"author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)",
"scripts": {
"test": "node node_modules/tad/bin/tad"
},
"repository": {
"type": "git",
"url": "git://github.com/medikoo/d.git"
},
"keywords": [

@@ -23,9 +16,20 @@ "descriptor",

],
"repository": {
"type": "git",
"url": "git://github.com/medikoo/d.git"
},
"dependencies": {
"es5-ext": "~0.10.2"
"es5-ext": "^0.10.9"
},
"devDependencies": {
"tad": "~0.1.21"
"tad": "^0.2.4",
"xlint": "^0.2.2",
"xlint-jslint-medikoo": "^0.1.4"
},
"scripts": {
"lint": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --no-cache --no-stream",
"lint-console": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --watch",
"test": "node node_modules/tad/bin/tad"
},
"license": "MIT"
}

@@ -1,2 +0,3 @@

# D - Property descriptor factory
# D
## Property descriptor factory

@@ -13,3 +14,3 @@ _Originally derived from [es5-ext](https://github.com/medikoo/es5-ext) package._

}, configurable: true, enumerable: false, writable: true },
whithdraw: { value: function () {
withdraw: { value: function () {
/* ... */

@@ -33,3 +34,3 @@ }, configurable: true, enumerable: false, writable: true },

}),
whithdraw: d(function () {
withdraw: d(function () {
/* ... */

@@ -59,2 +60,8 @@ }),

### Installation
$ npm install d
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/)
### Other utilities

@@ -71,5 +78,5 @@

var Foo = function () { this._count = 0; };
autoBind(Foo.prototype, {
Object.defineProperties(Foo.prototype, autoBind({
increment: d(function () { ++this._count; });
});
}));

@@ -91,23 +98,12 @@ var foo = new Foo();

var Foo = function () {};
lazy(Foo.prototype, {
Object.defineProperties(Foo.prototype, lazy({
items: d(function () { return []; })
});
}));
var foo = new Foo();
foo.items.push(1, 2); // foo.items array created
foo.items.push(1, 2); // foo.items array created and defined directly on foo
```
## Installation
### NPM
In your project path:
$ npm install d
### Browser
You can easily bundle _D_ for browser with [modules-webmake](https://github.com/medikoo/modules-webmake)
## Tests [![Build Status](https://travis-ci.org/medikoo/d.png)](https://travis-ci.org/medikoo/d)
$ npm test

@@ -77,2 +77,7 @@ 'use strict';

a(Foo.prototype.flat2, 'bar');
a.h2("Reset direct");
Object.defineProperties(Foo.prototype, t({ testResetDirect: d(false) }));
a.throws(function () { Foo.prototype.testResetDirect = false; }, TypeError);
};

Sorry, the diff of this file is not supported yet

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc