Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The npm package 'prr' provides a simple and effective way to set properties on objects with specific property attributes in JavaScript. It is particularly useful for managing property descriptors with ease, allowing developers to control enumerable, writable, and configurable attributes.
Setting properties with custom attributes
This feature allows the setting of properties on an object while defining their attributes such as enumerable, writable, and configurable. The example shows how to set a non-enumerable property, which will not show up in Object.keys() but is still accessible on the object.
const prr = require('prr');
let obj = {};
// Setting a non-enumerable property
prr(obj, 'secret', 'hidden value', 'e');
console.log(Object.keys(obj)); // Will not show 'secret'
console.log(obj.secret); // Outputs 'hidden value'
This package offers functionality similar to 'prr' by allowing developers to define a new property directly on an object, or modify an existing property on an object, and returns the object. It is similar to prr but does not provide shorthand flags for property attributes.
While not directly similar in functionality, 'deep-freeze' is related in the sense that it allows for control over object properties by recursively freezing objects. This is different from prr which does not freeze objects but allows for specific attribute settings on properties.
An sensible alternative to Object.defineProperty()
. Available in npm and Ender as prr.
Set the property 'foo'
(obj.foo
) to have the value 'bar'
with default options (enumerable, configurable and writable are all false):
prr(obj, 'foo', 'bar')
Adjust the default options:
prr(obj, 'foo', 'bar', { enumerable: true, writable: true })
Do the same operation for multiple properties:
prr(obj, { one: 'one', two: 'two' })
// or with options:
prr(obj, { one: 'one', two: 'two' }, { enumerable: true, writable: true })
But obviously, having to write out the full options object makes it nearly as bad as the original Object.defineProperty()
so we can simplify.
As an alternative method we can use an options string where each character represents a option: 'e'=='enumerable'
, 'c'=='configurable'
and 'w'=='writable'
:
prr(obj, 'foo', 'bar', 'ew') // enumerable and writable but not configurable
// muliple properties:
prr(obj, { one: 'one', two: 'two' }, 'ewc') // configurable too
Anywhere! For pre-ES5 environments prr will simply fall-back to an object[property] = value
so you can get close to what you want.
prr is Ender-compatible so you can include it in your Ender build and $.prr(...)
or var prr = require('prr'); prr(...)
.
prr is Copyright (c) 2013 Rod Vagg @rvagg and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
FAQs
A better Object.defineProperty()
The npm package prr receives a total of 1,931,882 weekly downloads. As such, prr popularity was classified as popular.
We found that prr 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
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.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.