# define-data-property

> Define a data property on an object. Will fall back to assignment in an engine without descriptors.

Latest version **1.1.4** (published 2024-02-13) · MIT license · 0 weekly downloads

> **Native alternative:** Object.defineProperty — Use native JavaScript (Node 0.10.0+) (https://developer.mozilla.orgGlobal_Objects/Object/defineProperty)

## Install

```sh
npm install define-data-property
pnpm add define-data-property
yarn add define-data-property
bun add define-data-property
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2024-02-13 |
| First published | 2023-09-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 0.4 |
| Dependencies | 3 |
| Unpacked size | 30.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jordan Harband |
| Maintainers | ljharb |
| Keywords | define, data, property, object, accessor, javascript, ecmascript, enumerable, configurable, writable |

## Links

- npm: https://www.npmjs.com/package/define-data-property
- Repository: https://github.com/ljharb/define-data-property
- Homepage: https://github.com/ljharb/define-data-property#readme
- Issues: https://github.com/ljharb/define-data-property/issues
- Funding: https://github.com/sponsors/ljharb
- npm.io page: https://npm.io/package/define-data-property

## Dependencies (3)

- [gopd](https://npm.io/package/gopd.md) ^1.0.1
- [es-errors](https://npm.io/package/es-errors.md) ^1.3.0
- [es-define-property](https://npm.io/package/es-define-property.md) ^1.0.0

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 1.1.4 (latest) — 2024-02-13
- 1.1.3 — 2024-02-12
- 1.1.2 — 2024-02-06
- 1.1.1 — 2023-10-13
- 1.1.0 — 2023-09-13
- 1.0.1 — 2023-09-12
- 1.0.0 — 2023-09-12

## README

# define-data-property <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

Define a data property on an object. Will fall back to assignment in an engine without descriptors.

The three `non*` argument can also be passed `null`, which will use the existing state if available.

The `loose` argument will mean that if you attempt to set a non-normal data property, in an environment without descriptor support, it will fall back to normal assignment.

## Usage

```javascript
var defineDataProperty = require('define-data-property');
var assert = require('assert');

var obj = {};
defineDataProperty(obj, 'key', 'value');
defineDataProperty(
	obj,
	'key2',
	'value',
	true, // nonEnumerable, optional
	false, // nonWritable, optional
	true, // nonConfigurable, optional
	false // loose, optional
);

assert.deepEqual(
	Object.getOwnPropertyDescriptors(obj),
	{
		key: {
			configurable: true,
			enumerable: true,
			value: 'value',
			writable: true,
		},
		key2: {
			configurable: false,
			enumerable: false,
			value: 'value',
			writable: true,
		},
	}
);
```

[package-url]: https://npmjs.org/package/define-data-property
[npm-version-svg]: https://versionbadg.es/ljharb/define-data-property.svg
[deps-svg]: https://david-dm.org/ljharb/define-data-property.svg
[deps-url]: https://david-dm.org/ljharb/define-data-property
[dev-deps-svg]: https://david-dm.org/ljharb/define-data-property/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/define-data-property#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/define-data-property.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/define-data-property.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/define-data-property.svg
[downloads-url]: https://npm-stat.com/charts.html?package=define-data-property
[codecov-image]: https://codecov.io/gh/ljharb/define-data-property/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/ljharb/define-data-property/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/define-data-property
[actions-url]: https://github.com/ljharb/define-data-property/actions

---
_Source: https://npm.io/package/define-data-property · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
