Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

es-class

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-class - npm Package Compare versions

Comparing version
1.2.0
to
1.2.1
+2
build/es-class.amd.js
/*! (C) Andrea Giammarchi - MIT Style License */
define(function(){var e=e||function(e){"use strict";function N(e,t,n){for(var r,s=[],o=0;o<e.length;o++)r=D(e[o]),p.call(r,i)&&s.push(r[i]),C(r,t,n,!1,!1);return s}function C(e,t,n,r,i){for(var s,o=typeof e!="function",u=y(e),a=0;a<u.length;a++)s=u[a],(o||S.call(E,s)<0)&&M(s,i)&&(p.call(t,s)&&B("duplicated: "+s),P(n,t,s,g(e,s),r))}function k(e,t){var n=function(){};return e&&""+t!=""+n?function(){return t.apply(this,arguments)}:n}function L(e,t,n,r){var i=O(t,r);m(e,t,{enumerable:!1,configurable:i,writable:i,value:n})}function A(e){return e?(e<65||90<e)&&(e<97||122<e)&&e!==95:!0}function O(e,t){return t?!_(e):!0}function M(e,f){return e!==t&&e!==n&&e!==r&&e!==s&&e!==o&&e!==u&&e!==a&&(f||e!==i)}function _(e){for(var t,n=0;n<e.length;n++){t=e.charCodeAt(n);if((t<65||90<t)&&t!==95)return!1}return!0}function D(t){if(typeof t=="object")return t;t.length&&B((t.name||"Class")+" should not expect arguments");for(var n,r,i,s={init:t},o=t.prototype;o&&o!==e.prototype;o=w(o))for(n=0,i=y(o);n<i.length;n++)r=i[n],M(r,!1)&&!p.call(s,r)&&m(s,r,g(o,r));return s}function P(e,t,n,r,i){var s=p.call(r,"value"),o,u;if(i){if(p.call(t,n))return}else s?(u=r.value,typeof u=="function"&&x(u)&&(r.value=j(e,n,u,i))):(F(e,n,r,"get"),F(e,n,r,"set"));o=O(n,i),r.enumerable=!1,r.configurable=o,s&&(r.writable=o),m(t,n,r)}function H(e,t){for(var n,r,i=0;i<e.length;i++){n=e[i];for(r in n)p.call(n,r)&&!p.call(t,r)&&B(r+" is not implemented")}}function B(e){try{console.warn(e)}catch(t){}}function j(e,t,n,r){return function(){p.call(this,u)||L(this,u,null,r);var i=this[u],s=this[u]=e[t],o=n.apply(this,arguments);return this[u]=i,o}}function F(e,t,n,r,i){p.call(n,r)&&x(n[r])&&(n[r]=j(g(e,t),r,n[r],i))}var t="constructor",n="extends",r="implements",i="init",s="prototype",o="static",u="super",a="with",f="__proto__",l=["hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],c={}[l[2]]||function(e){for(var t in this)if(e===t)return this.hasOwnProperty(e);return!1},h=!c.call({valueOf:0},l[5]),p=e[l[0]],d=e.create||function(e){var t=this instanceof d;return d[s]=t?v:e,t?this:new d},v=d[s],m=e.defineProperty,g=e.getOwnPropertyDescriptor,y=e.getOwnPropertyNames||function(e){var t=[],n,r;for(r in e)p.call(e,r)&&t.push(r);if(h)for(n=0;n<l.length;n++)r=l[n],p.call(e,r)&&t.push(r);return t},b=e.getPrototypeOf,w=b||function(e){return e[f]||null},E=y(function(){}),S=E.indexOf||function(e){for(var t=this.length;t--&&this[t]!==e;);return t},x=(""+function(){this["super"]()}).indexOf(u)<0?function(){return!0}:function(e){var t=""+e,n=t.indexOf(u);return n<0?!1:A(t.charCodeAt(n-1))&&A(t.charCodeAt(n+5))};try{m({},"{}",{})}catch(T){"__defineGetter__"in{}?(m=function(e,t,n){return p.call(n,"value")?e[t]=n.value:(p.call(n,"get")&&e.__defineGetter__(t,n.get),p.call(n,"set")&&e.__defineSetter__(t,n.set)),e},g=function(e,t){var n=e.__lookupGetter__(t),r=e.__lookupSetter__(t),i={};return n||r?(n&&(i.get=n),r&&(i.set=r)):i.value=e[t],i}):(m=function(e,t,n){return e[t]=n.value,e},g=function(e,t){return{value:e[t]}})}return function(e){var i=p.call(e,t),u=p.call(e,n),l=u&&e[n],c=u&&typeof l=="function",h=c?l[s]:l,v=i?e[t]:k(c,l),m=u&&i&&x(v),g=u?d(h):v[s],y,w;return m&&(v=j(h,t,v,!1)),p.call(e,a)&&(y=N([].concat(e[a]),g,h),w=y.length,w&&(v=function(e){return function(){var t=0;while(t<w)y[t++].call(this);return e.apply(this,arguments)}}(v),v[s]=g)),p.call(e,o)&&C(e[o],v,h,!0,!0),u&&(l!==h&&C(l,v,h,!0,!0),v[s]=g),g[t]!==v&&L(g,t,v,!1),C(e,g,h,!1,!0),p.call(e,r)&&H([].concat(e[r]),g),u&&!b&&L(g,f,h,!1),v}}(Object);return e});
/*!
Copyright (C) 2015 by Andrea Giammarchi - @WebReflection
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
define(function () {
var Class = Class || (function (Object) {
'use strict';
/*! (C) Andrea Giammarchi - MIT Style License */
var
// shortcuts for minifiers and ES3 private keywords too
CONSTRUCTOR = 'constructor',
EXTENDS = 'extends',
IMPLEMENTS = 'implements',
INIT = 'init',
PROTOTYPE = 'prototype',
STATIC = 'static',
SUPER = 'super',
WITH = 'with',
// infamous property used as fallback
// for IE8 and lower only
PROTO = '__proto__',
// used to copy non enumerable properties on IE
nonEnumerables = [
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'toLocaleString',
'toString',
'valueOf'
],
// Espruino 1.7x does not have (yet) Object.prototype.propertyIsEnumerable
propertyIsEnumerable = {}[nonEnumerables[2]] || function (p) {
for (var k in this) if (p === k) return this.hasOwnProperty(p);
return false;
},
// IE < 9 bug only
hasIEEnumerableBug = !propertyIsEnumerable.call({valueOf:0}, nonEnumerables[5]),
// shortcut for own properties
hOP = Object[nonEnumerables[0]],
// basic ad-hoc private fallback for old browsers
// use es5-shim if you want a properly patched polyfill
create = Object.create || function (proto) {
/*jshint newcap: false */
var isInstance = this instanceof create;
create[PROTOTYPE] = isInstance ? createPrototype : proto;
return isInstance ? this : new create();
},
// very old browsers actually work better
// without assigning null as prototype
createPrototype = create[PROTOTYPE],
// redefined if not present
defineProperty = Object.defineProperty,
// redefined if not present
gOPD = Object.getOwnPropertyDescriptor,
// basic ad-hoc private fallback for old browsers
// use es5-shim if you want a properly patched polyfill
gOPN = Object.getOwnPropertyNames || function (object) {
var names = [], i, key;
for (key in object) {
if (hOP.call(object, key)) {
names.push(key);
}
}
if (hasIEEnumerableBug) {
for (i = 0; i < nonEnumerables.length; i++) {
key = nonEnumerables[i];
if (hOP.call(object, key)) {
names.push(key);
}
}
}
return names;
},
// needed to verify the existence
getPrototypeOf = Object.getPrototypeOf,
// needed to allow Classes as traits
gPO = getPrototypeOf || function (o) {
return o[PROTO] || null;
},
// used to avoid setting `arguments` and other function properties
// when public static are copied over
nativeFunctionOPN = gOPN(function () {}),
indexOf = nativeFunctionOPN.indexOf || function (v) {
for (var i = this.length; i-- && this[i] !== v;) {}
return i;
},
trustSuper = ('' + function () {
// this test should never be minifier sensitive
// or the indexOf check after will fail
this['super']();
}).indexOf(SUPER) < 0 ?
// In 2010 Opera 10.5 for Linux Debian 6
// goes nut with methods to string representation,
// truncating pieces of text in an unpredictable way.
// If you are targeting such browser
// be aware that super invocation might fail.
// This is the only exception I could find
// from year 2000 to modern days browsers
// plus everything else would work just fine.
function () { return true; } :
// all other JS engines should be just fine
function (method) {
var
str = '' + method,
i = str.indexOf(SUPER)
;
return i < 0 ?
false :
isBoundary(str.charCodeAt(i - 1)) &&
isBoundary(str.charCodeAt(i + 5));
}
;
// verified broken IE8 or older browsers
try {
defineProperty({}, '{}', {});
} catch(o_O) {
if ('__defineGetter__' in {}) {
defineProperty = function (object, name, descriptor) {
if (hOP.call(descriptor, 'value')) {
object[name] = descriptor.value;
} else {
if (hOP.call(descriptor, 'get')) {
object.__defineGetter__(name, descriptor.get);
}
if (hOP.call(descriptor, 'set')) {
object.__defineSetter__(name, descriptor.set);
}
}
return object;
};
gOPD = function (object, key) {
var
get = object.__lookupGetter__(key),
set = object.__lookupSetter__(key),
descriptor = {}
;
if (get || set) {
if (get) {
descriptor.get = get;
}
if (set) {
descriptor.set = set;
}
} else {
descriptor.value = object[key];
}
return descriptor;
};
} else {
defineProperty = function (object, name, descriptor) {
object[name] = descriptor.value;
return object;
};
gOPD = function (object, key) {
return {value: object[key]};
};
}
}
// copy all imported enumerable methods and properties
function addMixins(mixins, target, inherits) {
for (var
source,
init = [],
i = 0; i < mixins.length; i++
) {
source = transformMixin(mixins[i]);
if (hOP.call(source, INIT)) {
init.push(source[INIT]);
}
copyOwn(source, target, inherits, false, false);
}
return init;
}
// configure source own properties in the target
function copyOwn(source, target, inherits, publicStatic, allowInit) {
for (var
key,
noFunctionCheck = typeof source !== 'function',
names = gOPN(source),
i = 0; i < names.length; i++
) {
key = names[i];
if (
(noFunctionCheck || indexOf.call(nativeFunctionOPN, key) < 0) &&
isNotASpecialKey(key, allowInit)
) {
if (hOP.call(target, key)) {
warn('duplicated: ' + key);
}
setProperty(inherits, target, key, gOPD(source, key), publicStatic);
}
}
}
// return the right constructor analyzing the parent.
// if the parent is empty there is no need to call it.
function createConstructor(hasParentPrototype, parent) {
var Class = function Class() {};
return hasParentPrototype && ('' + parent) !== ('' + Class) ?
function Class() {
return parent.apply(this, arguments);
} :
Class
;
}
// common defineProperty wrapper
function define(target, key, value, publicStatic) {
var configurable = isConfigurable(key, publicStatic);
defineProperty(target, key, {
enumerable: false, // was: publicStatic,
configurable: configurable,
writable: configurable,
value: value
});
}
// verifies a specific char code is not in [A-Za-z_]
// used to avoid RegExp for non RegExp aware environment
function isBoundary(code) {
return code ?
(code < 65 || 90 < code) &&
(code < 97 || 122 < code) &&
code !== 95 :
true;
}
// if key is UPPER_CASE and the property is public static
// it will define the property as non configurable and non writable
function isConfigurable(key, publicStatic) {
return publicStatic ? !isPublicStatic(key) : true;
}
// verifies a key is not special for the class
function isNotASpecialKey(key, allowInit) {
return key !== CONSTRUCTOR &&
key !== EXTENDS &&
key !== IMPLEMENTS &&
// Blackberry 7 and old WebKit bug only:
// user defined functions have
// enumerable prototype and constructor
key !== PROTOTYPE &&
key !== STATIC &&
key !== SUPER &&
key !== WITH &&
(allowInit || key !== INIT);
}
// verifies the entire string is upper case
// and contains eventually an underscore
// used to avoid RegExp for non RegExp aware environment
function isPublicStatic(key) {
for(var c, i = 0; i < key.length; i++) {
c = key.charCodeAt(i);
if ((c < 65 || 90 < c) && c !== 95) {
return false;
}
}
return true;
}
// will eventually convert classes or constructors
// into trait objects, before assigning them as such
function transformMixin(trait) {
if (typeof trait === 'object') return trait;
if (trait.length) {
warn((trait.name || 'Class') + ' should not expect arguments');
}
for (var
i, key, keys,
object = {init: trait},
proto = trait.prototype;
proto && proto !== Object.prototype;
proto = gPO(proto)
) {
for (i = 0, keys = gOPN(proto); i < keys.length; i++) {
key = keys[i];
if (isNotASpecialKey(key, false) && !hOP.call(object, key)) {
defineProperty(object, key, gOPD(proto, key));
}
}
}
return object;
}
// set a property via defineProperty using a common descriptor
// only if properties where not defined yet.
// If publicStatic is true, properties are both non configurable and non writable
function setProperty(inherits, target, key, descriptor, publicStatic) {
var
hasValue = hOP.call(descriptor, 'value'),
configurable,
value
;
if (publicStatic) {
if (hOP.call(target, key)) {
return;
}
} else if (hasValue) {
value = descriptor.value;
if (typeof value === 'function' && trustSuper(value)) {
descriptor.value = wrap(inherits, key, value, publicStatic);
}
} else {
wrapGetOrSet(inherits, key, descriptor, 'get');
wrapGetOrSet(inherits, key, descriptor, 'set');
}
configurable = isConfigurable(key, publicStatic);
descriptor.enumerable = false; // was: publicStatic;
descriptor.configurable = configurable;
if (hasValue) {
descriptor.writable = configurable;
}
defineProperty(target, key, descriptor);
}
// basic check against expected properties or methods
// used when `implements` is used
function verifyImplementations(interfaces, target) {
for (var
current,
key,
i = 0; i < interfaces.length; i++
) {
current = interfaces[i];
for (key in current) {
if (hOP.call(current, key) && !hOP.call(target, key)) {
warn(key + ' is not implemented');
}
}
}
}
// warn if something doesn't look right
// such overwritten public statics
// or traits / mixins assigning twice same thing
function warn(message) {
try {
console.warn(message);
} catch(meh) {
/*\_(ツ)_*/
}
}
// lightweight wrapper for methods that requires
// .super(...) invokaction - inspired by old klass.js
function wrap(inherits, key, method, publicStatic) {
return function () {
if (!hOP.call(this, SUPER)) {
// define it once in order to use
// fast assignment every other time
define(this, SUPER, null, publicStatic);
}
var
previous = this[SUPER],
current = (this[SUPER] = inherits[key]),
result = method.apply(this, arguments)
;
this[SUPER] = previous;
return result;
};
}
// get/set shortcut for the eventual wrapper
function wrapGetOrSet(inherits, key, descriptor, gs, publicStatic) {
if (hOP.call(descriptor, gs) && trustSuper(descriptor[gs])) {
descriptor[gs] = wrap(
gOPD(inherits, key),
gs,
descriptor[gs],
publicStatic
);
}
}
// the actual Class({ ... }) definition
return function (description) {
var
hasConstructor = hOP.call(description, CONSTRUCTOR),
hasParent = hOP.call(description, EXTENDS),
parent = hasParent && description[EXTENDS],
hasParentPrototype = hasParent && typeof parent === 'function',
inherits = hasParentPrototype ? parent[PROTOTYPE] : parent,
constructor = hasConstructor ?
description[CONSTRUCTOR] :
createConstructor(hasParentPrototype, parent),
hasSuper = hasParent && hasConstructor && trustSuper(constructor),
prototype = hasParent ? create(inherits) : constructor[PROTOTYPE],
mixins,
length
;
if (hasSuper) {
constructor = wrap(inherits, CONSTRUCTOR, constructor, false);
}
// add modules/mixins (that might swap the constructor)
if (hOP.call(description, WITH)) {
mixins = addMixins([].concat(description[WITH]), prototype, inherits);
length = mixins.length;
if (length) {
constructor = (function (parent) {
return function () {
var i = 0;
while (i < length) mixins[i++].call(this);
return parent.apply(this, arguments);
};
}(constructor));
constructor[PROTOTYPE] = prototype;
}
}
if (hOP.call(description, STATIC)) {
// add new public static properties first
copyOwn(description[STATIC], constructor, inherits, true, true);
}
if (hasParent) {
// in case it's a function
if (parent !== inherits) {
// copy possibly inherited statics too
copyOwn(parent, constructor, inherits, true, true);
}
constructor[PROTOTYPE] = prototype;
}
if (prototype[CONSTRUCTOR] !== constructor) {
define(prototype, CONSTRUCTOR, constructor, false);
}
// enrich the prototype
copyOwn(description, prototype, inherits, false, true);
if (hOP.call(description, IMPLEMENTS)) {
verifyImplementations([].concat(description[IMPLEMENTS]), prototype);
}
if (hasParent && !getPrototypeOf) {
define(prototype, PROTO, inherits, false);
}
return constructor;
};
}(Object));
return Class;
});
/*!
Copyright (C) 2015 by Andrea Giammarchi - @WebReflection
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var Class = Class || (function (Object) {
'use strict';
/*! (C) Andrea Giammarchi - MIT Style License */
var
// shortcuts for minifiers and ES3 private keywords too
CONSTRUCTOR = 'constructor',
EXTENDS = 'extends',
IMPLEMENTS = 'implements',
INIT = 'init',
PROTOTYPE = 'prototype',
STATIC = 'static',
SUPER = 'super',
WITH = 'with',
// infamous property used as fallback
// for IE8 and lower only
PROTO = '__proto__',
// used to copy non enumerable properties on IE
nonEnumerables = [
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'toLocaleString',
'toString',
'valueOf'
],
// Espruino 1.7x does not have (yet) Object.prototype.propertyIsEnumerable
propertyIsEnumerable = {}[nonEnumerables[2]] || function (p) {
for (var k in this) if (p === k) return this.hasOwnProperty(p);
return false;
},
// IE < 9 bug only
hasIEEnumerableBug = !propertyIsEnumerable.call({valueOf:0}, nonEnumerables[5]),
// shortcut for own properties
hOP = Object[nonEnumerables[0]],
// basic ad-hoc private fallback for old browsers
// use es5-shim if you want a properly patched polyfill
create = Object.create || function (proto) {
/*jshint newcap: false */
var isInstance = this instanceof create;
create[PROTOTYPE] = isInstance ? createPrototype : proto;
return isInstance ? this : new create();
},
// very old browsers actually work better
// without assigning null as prototype
createPrototype = create[PROTOTYPE],
// redefined if not present
defineProperty = Object.defineProperty,
// redefined if not present
gOPD = Object.getOwnPropertyDescriptor,
// basic ad-hoc private fallback for old browsers
// use es5-shim if you want a properly patched polyfill
gOPN = Object.getOwnPropertyNames || function (object) {
var names = [], i, key;
for (key in object) {
if (hOP.call(object, key)) {
names.push(key);
}
}
if (hasIEEnumerableBug) {
for (i = 0; i < nonEnumerables.length; i++) {
key = nonEnumerables[i];
if (hOP.call(object, key)) {
names.push(key);
}
}
}
return names;
},
// needed to verify the existence
getPrototypeOf = Object.getPrototypeOf,
// needed to allow Classes as traits
gPO = getPrototypeOf || function (o) {
return o[PROTO] || null;
},
// used to avoid setting `arguments` and other function properties
// when public static are copied over
nativeFunctionOPN = gOPN(function () {}),
indexOf = nativeFunctionOPN.indexOf || function (v) {
for (var i = this.length; i-- && this[i] !== v;) {}
return i;
},
trustSuper = ('' + function () {
// this test should never be minifier sensitive
// or the indexOf check after will fail
this['super']();
}).indexOf(SUPER) < 0 ?
// In 2010 Opera 10.5 for Linux Debian 6
// goes nut with methods to string representation,
// truncating pieces of text in an unpredictable way.
// If you are targeting such browser
// be aware that super invocation might fail.
// This is the only exception I could find
// from year 2000 to modern days browsers
// plus everything else would work just fine.
function () { return true; } :
// all other JS engines should be just fine
function (method) {
var
str = '' + method,
i = str.indexOf(SUPER)
;
return i < 0 ?
false :
isBoundary(str.charCodeAt(i - 1)) &&
isBoundary(str.charCodeAt(i + 5));
}
;
// verified broken IE8 or older browsers
try {
defineProperty({}, '{}', {});
} catch(o_O) {
if ('__defineGetter__' in {}) {
defineProperty = function (object, name, descriptor) {
if (hOP.call(descriptor, 'value')) {
object[name] = descriptor.value;
} else {
if (hOP.call(descriptor, 'get')) {
object.__defineGetter__(name, descriptor.get);
}
if (hOP.call(descriptor, 'set')) {
object.__defineSetter__(name, descriptor.set);
}
}
return object;
};
gOPD = function (object, key) {
var
get = object.__lookupGetter__(key),
set = object.__lookupSetter__(key),
descriptor = {}
;
if (get || set) {
if (get) {
descriptor.get = get;
}
if (set) {
descriptor.set = set;
}
} else {
descriptor.value = object[key];
}
return descriptor;
};
} else {
defineProperty = function (object, name, descriptor) {
object[name] = descriptor.value;
return object;
};
gOPD = function (object, key) {
return {value: object[key]};
};
}
}
// copy all imported enumerable methods and properties
function addMixins(mixins, target, inherits) {
for (var
source,
init = [],
i = 0; i < mixins.length; i++
) {
source = transformMixin(mixins[i]);
if (hOP.call(source, INIT)) {
init.push(source[INIT]);
}
copyOwn(source, target, inherits, false, false);
}
return init;
}
// configure source own properties in the target
function copyOwn(source, target, inherits, publicStatic, allowInit) {
for (var
key,
noFunctionCheck = typeof source !== 'function',
names = gOPN(source),
i = 0; i < names.length; i++
) {
key = names[i];
if (
(noFunctionCheck || indexOf.call(nativeFunctionOPN, key) < 0) &&
isNotASpecialKey(key, allowInit)
) {
if (hOP.call(target, key)) {
warn('duplicated: ' + key);
}
setProperty(inherits, target, key, gOPD(source, key), publicStatic);
}
}
}
// return the right constructor analyzing the parent.
// if the parent is empty there is no need to call it.
function createConstructor(hasParentPrototype, parent) {
var Class = function Class() {};
return hasParentPrototype && ('' + parent) !== ('' + Class) ?
function Class() {
return parent.apply(this, arguments);
} :
Class
;
}
// common defineProperty wrapper
function define(target, key, value, publicStatic) {
var configurable = isConfigurable(key, publicStatic);
defineProperty(target, key, {
enumerable: false, // was: publicStatic,
configurable: configurable,
writable: configurable,
value: value
});
}
// verifies a specific char code is not in [A-Za-z_]
// used to avoid RegExp for non RegExp aware environment
function isBoundary(code) {
return code ?
(code < 65 || 90 < code) &&
(code < 97 || 122 < code) &&
code !== 95 :
true;
}
// if key is UPPER_CASE and the property is public static
// it will define the property as non configurable and non writable
function isConfigurable(key, publicStatic) {
return publicStatic ? !isPublicStatic(key) : true;
}
// verifies a key is not special for the class
function isNotASpecialKey(key, allowInit) {
return key !== CONSTRUCTOR &&
key !== EXTENDS &&
key !== IMPLEMENTS &&
// Blackberry 7 and old WebKit bug only:
// user defined functions have
// enumerable prototype and constructor
key !== PROTOTYPE &&
key !== STATIC &&
key !== SUPER &&
key !== WITH &&
(allowInit || key !== INIT);
}
// verifies the entire string is upper case
// and contains eventually an underscore
// used to avoid RegExp for non RegExp aware environment
function isPublicStatic(key) {
for(var c, i = 0; i < key.length; i++) {
c = key.charCodeAt(i);
if ((c < 65 || 90 < c) && c !== 95) {
return false;
}
}
return true;
}
// will eventually convert classes or constructors
// into trait objects, before assigning them as such
function transformMixin(trait) {
if (typeof trait === 'object') return trait;
if (trait.length) {
warn((trait.name || 'Class') + ' should not expect arguments');
}
for (var
i, key, keys,
object = {init: trait},
proto = trait.prototype;
proto && proto !== Object.prototype;
proto = gPO(proto)
) {
for (i = 0, keys = gOPN(proto); i < keys.length; i++) {
key = keys[i];
if (isNotASpecialKey(key, false) && !hOP.call(object, key)) {
defineProperty(object, key, gOPD(proto, key));
}
}
}
return object;
}
// set a property via defineProperty using a common descriptor
// only if properties where not defined yet.
// If publicStatic is true, properties are both non configurable and non writable
function setProperty(inherits, target, key, descriptor, publicStatic) {
var
hasValue = hOP.call(descriptor, 'value'),
configurable,
value
;
if (publicStatic) {
if (hOP.call(target, key)) {
return;
}
} else if (hasValue) {
value = descriptor.value;
if (typeof value === 'function' && trustSuper(value)) {
descriptor.value = wrap(inherits, key, value, publicStatic);
}
} else {
wrapGetOrSet(inherits, key, descriptor, 'get');
wrapGetOrSet(inherits, key, descriptor, 'set');
}
configurable = isConfigurable(key, publicStatic);
descriptor.enumerable = false; // was: publicStatic;
descriptor.configurable = configurable;
if (hasValue) {
descriptor.writable = configurable;
}
defineProperty(target, key, descriptor);
}
// basic check against expected properties or methods
// used when `implements` is used
function verifyImplementations(interfaces, target) {
for (var
current,
key,
i = 0; i < interfaces.length; i++
) {
current = interfaces[i];
for (key in current) {
if (hOP.call(current, key) && !hOP.call(target, key)) {
warn(key + ' is not implemented');
}
}
}
}
// warn if something doesn't look right
// such overwritten public statics
// or traits / mixins assigning twice same thing
function warn(message) {
try {
console.warn(message);
} catch(meh) {
/*\_(ツ)_*/
}
}
// lightweight wrapper for methods that requires
// .super(...) invokaction - inspired by old klass.js
function wrap(inherits, key, method, publicStatic) {
return function () {
if (!hOP.call(this, SUPER)) {
// define it once in order to use
// fast assignment every other time
define(this, SUPER, null, publicStatic);
}
var
previous = this[SUPER],
current = (this[SUPER] = inherits[key]),
result = method.apply(this, arguments)
;
this[SUPER] = previous;
return result;
};
}
// get/set shortcut for the eventual wrapper
function wrapGetOrSet(inherits, key, descriptor, gs, publicStatic) {
if (hOP.call(descriptor, gs) && trustSuper(descriptor[gs])) {
descriptor[gs] = wrap(
gOPD(inherits, key),
gs,
descriptor[gs],
publicStatic
);
}
}
// the actual Class({ ... }) definition
return function (description) {
var
hasConstructor = hOP.call(description, CONSTRUCTOR),
hasParent = hOP.call(description, EXTENDS),
parent = hasParent && description[EXTENDS],
hasParentPrototype = hasParent && typeof parent === 'function',
inherits = hasParentPrototype ? parent[PROTOTYPE] : parent,
constructor = hasConstructor ?
description[CONSTRUCTOR] :
createConstructor(hasParentPrototype, parent),
hasSuper = hasParent && hasConstructor && trustSuper(constructor),
prototype = hasParent ? create(inherits) : constructor[PROTOTYPE],
mixins,
length
;
if (hasSuper) {
constructor = wrap(inherits, CONSTRUCTOR, constructor, false);
}
// add modules/mixins (that might swap the constructor)
if (hOP.call(description, WITH)) {
mixins = addMixins([].concat(description[WITH]), prototype, inherits);
length = mixins.length;
if (length) {
constructor = (function (parent) {
return function () {
var i = 0;
while (i < length) mixins[i++].call(this);
return parent.apply(this, arguments);
};
}(constructor));
constructor[PROTOTYPE] = prototype;
}
}
if (hOP.call(description, STATIC)) {
// add new public static properties first
copyOwn(description[STATIC], constructor, inherits, true, true);
}
if (hasParent) {
// in case it's a function
if (parent !== inherits) {
// copy possibly inherited statics too
copyOwn(parent, constructor, inherits, true, true);
}
constructor[PROTOTYPE] = prototype;
}
if (prototype[CONSTRUCTOR] !== constructor) {
define(prototype, CONSTRUCTOR, constructor, false);
}
// enrich the prototype
copyOwn(description, prototype, inherits, false, true);
if (hOP.call(description, IMPLEMENTS)) {
verifyImplementations([].concat(description[IMPLEMENTS]), prototype);
}
if (hasParent && !getPrototypeOf) {
define(prototype, PROTO, inherits, false);
}
return constructor;
};
}(Object));
+3
-0
language: node_js
node_js:
- 0.6
- 0.8
- 0.9
- 0.10
- 0.12
git:

@@ -6,0 +9,0 @@ depth: 1

{
"version": "1.2.0",
"version": "1.2.1",
"license": "MIT",

@@ -37,3 +37,13 @@ "name": "es-class",

"wru": ">= 0.0.0"
}
},
"filename": "es-class.js",
"npmName": "es-class",
"npmFileMap": [
{
"basePath": "/build/",
"files": [
"*.js"
]
}
]
}

@@ -19,3 +19,3 @@ es-class

Following a list of tested browsers split in Desktop and Mobile.
Following a list of tested browsers split in Desktop and Mobile, plus a list of server/micro-controller side supported engines.

@@ -44,3 +44,13 @@ #### Desktop

#### Others (tested)
* [Espruino Pico](http://www.espruino.com)
* MIPS version of node for [Arduino Yun](http://www.arduino.cc/en/Main/ArduinoBoardYun?from=Products.ArduinoYUN)
* node.js 0.6+ and io.js every (so Raspberry PI and every other with node.js)
* Duktape and Nashorn
If you actually know a hybrid (like Espruino) or ES3+ engine that does not work, please file a bug, thank you!
### Features

@@ -47,0 +57,0 @@ All features explained in the [dedicated page](https://github.com/WebReflection/es-class/blob/master/FEATURES.md).

Sorry, the diff of this file is not supported yet