Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
extendable-base
Advanced tools
Simple library for setting up Javascript classes based on Backbone.extend
Leverages Backbone.extend
semantics for defining subclasses in a generic way,
making it straightforward to set up javascript class hierarchies.
As a convenience, adds logic so that the default constructor for the Base
class calls initialize
function on all classes in the inheritance chain
passing the same arguments to each class.
var Base = require('base-extend');
var MyClass = Base.extend({
initialize: function(name) {
this.name = name;
},
whoami: function() {
console.log("I am", this.name);
}
});
console.log(new MyClass('joe').whoami());
// 'I am joe'
Simple inheritance chains work as well, calling initialize
for all classes
in the chain:
var Animal = Base.extend({
initialize: function(type) {
this.classname = "Animal";
this.type = type;
},
ident : function() {
return 'I am an ' + this.classname + ': ' + this.type;
},
legs : function() {
return 'I have ' + this._legs + ' legs';
}
});
var FourLegged = Animal.extend({
// Initialize is called for all classes
initialize : function(type) {
this._legs = 4;
}
});
var dog = new FourLegged('dog');
console.log(dog.ident());
// 'I am an Animal: dog'
console.log(dog.legs());
// 'I have 4 legs'
You can use Base.extends
to subclass an existing Javascript type, for example
to define custom Error
subclasses:
var BaseError = Base.inherits(Error, {
default_status: 500,
initialize: function(message, status) {
Error.call(this, message);
this.message = message || this.default_message || "";
this.status = status || this.default_status;
},
toJSON: function() {
return {status: this.status, message: this.message};
}
});
var NotFoundError = BaseError.extend({
default_status: 404,
default_message: "Bad Request"
});
var BadRequestError = BaseError.extend({
default_status: 400,
default_message: "Not Found"
});
console.log(new BadRequestError().toJSON());
// { status: 400, message: 'Not Found' }
console.log(new BadRequestError("Invalid request").toJSON());
// { status: 400, message: 'Invalid request' }
console.log(new BadRequestError("Unauthorized", 401).toJSON());
// { status: 401, message: 'Unauthorized' }
console.log(new NotFoundError().toJSON());
// { status: 404, message: 'Bad Request' }
FAQs
Simple library for setting up Javascript classes based on Backbone.extend
The npm package extendable-base receives a total of 65 weekly downloads. As such, extendable-base popularity was classified as not popular.
We found that extendable-base demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.