
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
define-props
Advanced tools
Object.defineProperties 的简化操作函数
npm install define-props
yarn add define-props
defineProps(obj, props, defaults)
obj 目前仅限制为不得为 undefined 或 null
defaults 则必须为 {} 结构,defaults 的有效字段为:
defaults.enumerable 是否可枚举,默认 truedefaults.writable 是否可写入,默认 falsedefaults.configurable 是否可配置(delete key),默认 falseprops 可以是 [] 或 {} 或 function:
prop 表示每一个属性的声明
prop.value 属性值prop.get getter方法prop.set setter方法prop.enumerable 参见 defaultsprop.writable 参见 defaultsprop.configurable 参见 defaults实际使用发现 reference 有问题,暂时放弃这个声明,下一个版本提供一个 clone 的声明,复制对象值。
const a = defineProps({}, {
// a.key1 = ‘value1’
// enumerable = true, configurable = false, writable = false
key1: 'value1',
// a.key2 = 'value2'
// 有 value 字段,则取 value 字段的值
key2: {
value: 'value2',
enumerable: true,
writable: true
},
// a.key3 = {a: 11, b: 22}
// 无 value 字段,则以整个 {} 作为值
key3: {
a: 11,
b: 22,
},
// a.key4 = 'value4'
// 以一个函数为值,则直接作为 getter
key4: () => {
return 'value4'
},
// a.key5 = 'value5'
// 如果 {} 未指定 value 字段,但指定了 get 方法(set不算)
key5: {
get: () => {
return 'value5'
}
},
// a.key6 = undefined
// 当值为 null or undefined 的时候,判断是否指定了 get 或 writable = true,否则将不会将该键值对写入到对象属性
key6: null,
// 同上
key7: {
value: null
},
// a.key8 = null
// 由于该键允许写入,所以将 key8 写入到对象属性中
key8: {
value: null,
writable: true
},
// a.key9 = 'value9'
// 因为存在 get ,所以也会将 key9 写入对象属性中
key9: {
value: null,
get : () => {
return 'value9';
}
}
})
FAQs
a simplified function for Object.defineProperties.
The npm package define-props receives a total of 1 weekly downloads. As such, define-props popularity was classified as not popular.
We found that define-props 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.