npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

define-props

v0.0.7

Published

a simplified function for Object.defineProperties.

Downloads

14

Readme

define-props.js

Object.defineProperties 的简化操作函数

安装说明

npm install define-props
yarn add define-props

函数说明

defineProps(obj, props, defaults)

obj 目前仅限制为不得为 undefinednull

defaults 则必须为 {} 结构,defaults 的有效字段为:

  • defaults.enumerable 是否可枚举,默认 true
  • defaults.writable 是否可写入,默认 false
  • defaults.configurable 是否可配置(delete key),默认 false

props 可以是 []{}function

prop 表示每一个属性的声明

  • prop.value 属性值
  • prop.get getter方法
  • prop.set setter方法
  • prop.enumerable 参见 defaults
  • prop.writable 参见 defaults
  • prop.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';
		}
	}
})