Socket
Socket
Sign inDemoInstall

extend-me

Package Overview
Dependencies
0
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.2 to 2.2.3

41

index.js

@@ -42,11 +42,16 @@ 'use strict';

case 1:
prototypeAdditions = extendedClassName;
if (typeof prototypeAdditions !== 'object') {
throw 'Single parameter overload must be object.';
switch (typeof extendedClassName) {
case 'object':
prototypeAdditions = extendedClassName;
extendedClassName = undefined;
break;
case 'string':
prototypeAdditions = {};
default:
throw 'Single-parameter overload must be either string or object.';
}
extendedClassName = undefined;
break;
case 2:
if (typeof extendedClassName !== 'string' || typeof prototypeAdditions !== 'object') {
throw 'Two parameter overload must be string, object.';
throw 'Two-parameter overload must be string, object.';
}

@@ -96,2 +101,4 @@ break;

makeAlias(value, key.substr(1));
} else if (isDescriptor(value)) {
Object.defineProperty(prototype, key, value);
} else {

@@ -111,2 +118,17 @@ prototype[key] = value;

function isDescriptor(value) {
var result;
if(typeof value === 'object' && value) {
var len = Object.keys(value).length,
hasSetter = typeof value.set === 'function' && value.set.length === 1,
hasGetter = typeof value.get === 'function' && value.get.length === 0;
result = typeof value.configurable === 'boolean' ||
typeof value.enumerable === 'boolean' ||
len === 1 && (hasSetter || hasGetter) ||
len === 2 && hasSetter && hasGetter;
}
return result;
}
function Base() {}

@@ -131,4 +153,9 @@ Base.prototype = {

* @property {object} [aliases] - Hash of aliases for prototype members in form `{ key: 'member', ... }` where `key` is the name of an alieas and `'member'` is the name of an existing member in the prototype. Each such key is added to the prototype as a reference to the named member. (The `aliases` object itself is *not* added to prototype.) Alternatively:
* @property {string} [keys] - Arbitrary property names defined here with string values starting with a `#` character will alias the actual properties named in the strings (following the `#`). This is an alternative to providing an `aliases` hash, perhaps simpler (though subtler). (Use arbitrary identifiers here; don't use the name `keys`!)
* @property {*} [arbitraryProperties] - Any additional arbitrary properties defined here will be added to the new constructor's prototype. (Use arbitrary identifiers here; don't use the name `aribitraryProperties`!)
* @property {string} [keys] - Arbitrary property names defined here with string values starting with a `#` character will alias the actual properties named in the strings (following the `#`). This is an alternative to providing an `aliases` hash, perhaps simpler (though subtler). (Use your own identifiers here; don't use the name `keys`!)
* @property {descriptorObject} [descriptors] - Will be run through `Object.defineProperty()`. Use your own identifiers here; don't use the name `descriptors`!)
* Detected by duck-typing:
* * It has a `configurable` property.
* * It has an `enumerable` property.
* * It has only: a `set` function that takes exactly one parameter and/or only a `get` function that takes no parameters.
* @property {*} [arbitraryProperties] - Any additional arbitrary properties defined here will be added to the new constructor's prototype. (Use your own identifiers here; don't use the name `aribitraryProperties`!)
*/

@@ -135,0 +162,0 @@

2

package.json
{
"name": "extend-me",
"version": "2.2.2",
"version": "2.2.3",
"main": "index.js",

@@ -5,0 +5,0 @@ "description": "Yet another Backbone-like class extender",

@@ -10,2 +10,3 @@ # extend-me

var Base = require('extend-me').Base;
var newClass = Base.extend(extendedClassName, prototype);
```

@@ -22,2 +23,12 @@

Syntax:
```javascript
var newClass = Base.extend(extendedClassName, prototypeAdditions);
```
* `Base` could also be any descendant class (previously extended in this way).
* `extendedClassName` _Optional._ This value if provided is copied to the prototype as `$$CLASS_NAME` and is useful in debugging to identify the derived class, the name of which is otherwise (unfortunately) not displayed by the debugger. Could also be useful in your code (something not easily available in standard JavaScript).
* `prototypeAdditions` _Required._ The members (properties and methods) of this object are added to the new constructor's prototype. Getter/setter literal syntax is not supported but you can use `defineProperty`'s {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty|descriptor objects}. These are recognized with duck-typing. See API doc for details.
Usage:

@@ -24,0 +35,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc