Merge pull request #14532 from resilient-tech/setDefault

This commit is contained in:
Suraj Shetty 2021-10-21 17:45:47 +05:30 committed by GitHub
commit cfa257929e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,6 +23,14 @@ if (!Array.prototype.uniqBy) {
});
}
// Python's dict.setdefault ported for JS objects
Object.defineProperty(Object.prototype, "setDefault", {
value: function(key, default_value) {
if (!(key in this)) this[key] = default_value;
return this[key];
}
});
// Pluralize
String.prototype.plural = function(revert) {
const plural = {