Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Helping you do prototypical OO
var extend = require("pd").extend
var Animal = {
legs: 4,
walk: function () { ... }
}
var Cat = extend({}, Animal, {
nyan: function () { ... },
constructor: function () {
this.lives = 9
return this;
}
});
var cat = extend({}, Cat).constructor()
ES5 OO is verbose
pd solves this with utilities and sugar.
pd converts all the values of your objects properties into property descriptors of those values.
pd({
"foo": "bar"
})
is the same as
{
"foo": {
"value": "bar",
"enumerable": true,
"writable": true,
"configurable": true
}
}
pd.extend extends an object with other objects. key clashes are given right preference
pd.extend(
{
"one": "faz",
"three": "bar"
},
{
"two": "ni",
"three": "baz"
},
{
"three": "bas",
"four": "four"
}
);
is the same as
{
"one": "faz",
"two": "ni",
"three": "bas",
"four": "four"
}
pd.extend returns the first object you pass in.
pd.bindAll is similar to underscore's bindAll method. It takes an object and binds all it's methods to the object. It takes an optional list of objects to mix in
var o = {
constructor: function () {
pd.bindAll(this, {
draw: function () {
/* use `this` with its "correct" value, i.e. `o` */
}
});
},
start: function (eventEmitter) {
// note `this.draw` would not work correctly if it wasn't bound
eventEmitter.on("draw", this.draw);
}
};
pd.Name constructs a Name function. This name function when passed your object will return a privates object. This privates object cannot be accessed in any other way then calling Name.
var Klass = (function () {
var privates = pd.Name();
return {
constructor: function (secret) {
privates(this).secret = secret;
},
getSecret: function () {
return privates(this).secret;
}
};
}());
pd.memoize caches the results of an asynchronous function. Pass in an optional context so the fn is called with the context and pass in an optional hasher so you can choose how your the arguments of the returned memoized function should map to results
var f = pd.memoize(asyncFunction),
start = Date.now()
f(10)
f(10)
f(10)
var time_taken = Date.now() - start // roughly 500
// because asyncFunction is memoized, the second and third call return
// at the same time as the first, and any call after that returns
// immediately
function asyncFunction(key, callback) {
setTimeout(function () {
callback(key * 2)
}, 500)
}
npm install pd
make test
FAQs
an ES5 / OO utility
The npm package pd receives a total of 29 weekly downloads. As such, pd popularity was classified as not popular.
We found that pd 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.