pax_global_header 0000666 0000000 0000000 00000000064 14562717423 0014525 g ustar 00root root 0000000 0000000 52 comment=e313da59d1f65e1549ac59539a7a8ac17632df60
ljharb-define-data-property-7397c50/ 0000775 0000000 0000000 00000000000 14562717423 0017273 5 ustar 00root root 0000000 0000000 ljharb-define-data-property-7397c50/.eslintrc 0000664 0000000 0000000 00000000443 14562717423 0021120 0 ustar 00root root 0000000 0000000 {
"root": true,
"extends": "@ljharb",
"rules": {
"complexity": 0,
"id-length": 0,
"new-cap": ["error", {
"capIsNewExceptions": [
"GetIntrinsic",
],
}],
},
"overrides": [
{
"files": "test/**",
"rules": {
"max-lines-per-function": "off",
},
},
],
}
ljharb-define-data-property-7397c50/.github/ 0000775 0000000 0000000 00000000000 14562717423 0020633 5 ustar 00root root 0000000 0000000 ljharb-define-data-property-7397c50/.github/FUNDING.yml 0000664 0000000 0000000 00000001117 14562717423 0022450 0 ustar 00root root 0000000 0000000 # These are supported funding model platforms
github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/define-data-property
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
ljharb-define-data-property-7397c50/.github/workflows/ 0000775 0000000 0000000 00000000000 14562717423 0022670 5 ustar 00root root 0000000 0000000 ljharb-define-data-property-7397c50/.github/workflows/node-aught.yml 0000664 0000000 0000000 00000000615 14562717423 0025450 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js < 10'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '< 10'
type: minors
command: npm run tests-only
skip-ls-check: true # io.js's npm can't handle `@types/*` deps in `npm ls`
node:
name: 'node < 10'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: true
ljharb-define-data-property-7397c50/.github/workflows/node-pretest.yml 0000664 0000000 0000000 00000000245 14562717423 0026025 0 ustar 00root root 0000000 0000000 name: 'Tests: pretest/posttest'
on: [pull_request, push]
permissions:
contents: read
jobs:
tests:
uses: ljharb/actions/.github/workflows/pretest.yml@main
ljharb-define-data-property-7397c50/.github/workflows/node-tens.yml 0000664 0000000 0000000 00000000477 14562717423 0025317 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js >= 10'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 10'
type: minors
command: npm run tests-only
node:
name: 'node >= 10'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: true
ljharb-define-data-property-7397c50/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000257 14562717423 0024660 0 ustar 00root root 0000000 0000000 name: Automatic Rebase
on: [pull_request_target]
jobs:
_:
uses: ljharb/actions/.github/workflows/rebase.yml@main
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
ljharb-define-data-property-7397c50/.github/workflows/require-allow-edits.yml 0000664 0000000 0000000 00000000303 14562717423 0027305 0 ustar 00root root 0000000 0000000 name: Require “Allow Edits”
on: [pull_request_target]
jobs:
_:
name: "Require “Allow Edits”"
runs-on: ubuntu-latest
steps:
- uses: ljharb/require-allow-edits@main
ljharb-define-data-property-7397c50/.gitignore 0000664 0000000 0000000 00000004136 14562717423 0021267 0 ustar 00root root 0000000 0000000 # Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
.npmignore
ljharb-define-data-property-7397c50/.npmrc 0000664 0000000 0000000 00000000067 14562717423 0020416 0 ustar 00root root 0000000 0000000 package-lock=false
allow-same-version=true
message=v%s
ljharb-define-data-property-7397c50/.nycrc 0000664 0000000 0000000 00000000330 14562717423 0020406 0 ustar 00root root 0000000 0000000 {
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"lines": 86,
"statements": 85.93,
"functions": 82.43,
"branches": 76.06,
"exclude": [
"coverage",
"test"
]
}
ljharb-define-data-property-7397c50/CHANGELOG.md 0000664 0000000 0000000 00000012416 14562717423 0021110 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.1.4](https://github.com/ljharb/define-data-property/compare/v1.1.3...v1.1.4) - 2024-02-13
### Commits
- [Refactor] use `es-define-property` [`90f2f4c`](https://github.com/ljharb/define-data-property/commit/90f2f4cc20298401e71c28e1e08888db12021453)
- [Dev Deps] update `@types/object.getownpropertydescriptors` [`cd929d9`](https://github.com/ljharb/define-data-property/commit/cd929d9a04f5f2fdcfa9d5be140940b91a083153)
## [v1.1.3](https://github.com/ljharb/define-data-property/compare/v1.1.2...v1.1.3) - 2024-02-12
### Commits
- [types] hand-write d.ts instead of emitting it [`0cbc988`](https://github.com/ljharb/define-data-property/commit/0cbc988203c105f2d97948327c7167ebd33bd318)
- [meta] simplify `exports` [`690781e`](https://github.com/ljharb/define-data-property/commit/690781eed28bbf2d6766237efda0ba6dd591609e)
- [Dev Deps] update `hasown`; clean up DT packages [`6cdfd1c`](https://github.com/ljharb/define-data-property/commit/6cdfd1cb2d91d791bfd18cda5d5cab232fd5d8fc)
- [actions] cleanup [`3142bc6`](https://github.com/ljharb/define-data-property/commit/3142bc6a4bc406a51f5b04f31e98562a27f35ffd)
- [meta] add `funding` [`8474423`](https://github.com/ljharb/define-data-property/commit/847442391a79779af3e0f1bf0b5bb923552b7804)
- [Deps] update `get-intrinsic` [`3e9be00`](https://github.com/ljharb/define-data-property/commit/3e9be00e07784ba34e7c77d8bc0fdbc832ad61de)
## [v1.1.2](https://github.com/ljharb/define-data-property/compare/v1.1.1...v1.1.2) - 2024-02-05
### Commits
- [Dev Deps] update @types packages, `object-inspect`, `tape`, `typescript` [`df41bf8`](https://github.com/ljharb/define-data-property/commit/df41bf84ca3456be6226055caab44e38e3a7fd2f)
- [Dev Deps] update DT packages, `aud`, `npmignore`, `tape`, typescript` [`fab0e4e`](https://github.com/ljharb/define-data-property/commit/fab0e4ec709ee02b79f42d6db3ee5f26e0a34b8a)
- [Dev Deps] use `hasown` instead of `has` [`aa51ef9`](https://github.com/ljharb/define-data-property/commit/aa51ef93f6403d49d9bb72a807bcdb6e418978c0)
- [Refactor] use `es-errors`, so things that only need those do not need `get-intrinsic` [`d89be50`](https://github.com/ljharb/define-data-property/commit/d89be50571175888d391238605122679f7e65ffc)
- [Deps] update `has-property-descriptors` [`7af887c`](https://github.com/ljharb/define-data-property/commit/7af887c9083b59b195b0079e04815cfed9fcee2b)
- [Deps] update `get-intrinsic` [`bb8728e`](https://github.com/ljharb/define-data-property/commit/bb8728ec42cd998505a7157ae24853a560c20646)
## [v1.1.1](https://github.com/ljharb/define-data-property/compare/v1.1.0...v1.1.1) - 2023-10-12
### Commits
- [Tests] fix tests in ES3 engines [`5c6920e`](https://github.com/ljharb/define-data-property/commit/5c6920edd1f52f675b02f417e539c28135b43f94)
- [Dev Deps] update `@types/es-value-fixtures`, `@types/for-each`, `@types/gopd`, `@types/has-property-descriptors`, `tape`, `typescript` [`7d82dfc`](https://github.com/ljharb/define-data-property/commit/7d82dfc20f778b4465bba06335dd53f6f431aea3)
- [Fix] IE 8 has a broken `Object.defineProperty` [`0672e1a`](https://github.com/ljharb/define-data-property/commit/0672e1af2a9fcc787e7c23b96dea60d290df5548)
- [meta] emit types on prepack [`73acb1f`](https://github.com/ljharb/define-data-property/commit/73acb1f903c21b314ec7156bf10f73c7910530c0)
- [Dev Deps] update `tape`, `typescript` [`9489a77`](https://github.com/ljharb/define-data-property/commit/9489a7738bf2ecf0ac71d5b78ec4ca6ad7ba0142)
## [v1.1.0](https://github.com/ljharb/define-data-property/compare/v1.0.1...v1.1.0) - 2023-09-13
### Commits
- [New] add `loose` arg [`155235a`](https://github.com/ljharb/define-data-property/commit/155235a4c4d7741f6de01cd87c99599a56654b72)
- [New] allow `null` to be passed for the non* args [`7d2fa5f`](https://github.com/ljharb/define-data-property/commit/7d2fa5f06be0392736c13b126f7cd38979f34792)
## [v1.0.1](https://github.com/ljharb/define-data-property/compare/v1.0.0...v1.0.1) - 2023-09-12
### Commits
- [meta] add TS types [`43d763c`](https://github.com/ljharb/define-data-property/commit/43d763c6c883f652de1c9c02ef6216ee507ffa69)
- [Dev Deps] update `@types/tape`, `typescript` [`f444985`](https://github.com/ljharb/define-data-property/commit/f444985811c36f3e6448a03ad2f9b7898917f4c7)
- [meta] add `safe-publish-latest`, [`172bb10`](https://github.com/ljharb/define-data-property/commit/172bb10890896ebb160e64398f6ee55760107bee)
## v1.0.0 - 2023-09-12
### Commits
- Initial implementation, tests, readme [`5b43d6b`](https://github.com/ljharb/define-data-property/commit/5b43d6b44e675a904810467a7d4e0adb7efc3196)
- Initial commit [`35e577a`](https://github.com/ljharb/define-data-property/commit/35e577a6ba59a98befa97776d70d90f3bea9009d)
- npm init [`82a0a04`](https://github.com/ljharb/define-data-property/commit/82a0a04a321ca7de220af02d41e2745e8a9962ed)
- Only apps should have lockfiles [`96df244`](https://github.com/ljharb/define-data-property/commit/96df244a3c6f426f9a2437be825d1c6f5dd7158e)
- [meta] use `npmignore` to autogenerate an npmignore file [`a87ff18`](https://github.com/ljharb/define-data-property/commit/a87ff18cb79e14c2eb5720486c4759fd9a189375)
ljharb-define-data-property-7397c50/LICENSE 0000664 0000000 0000000 00000002057 14562717423 0020304 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2023 Jordan Harband
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
ljharb-define-data-property-7397c50/README.md 0000664 0000000 0000000 00000004577 14562717423 0020567 0 ustar 00root root 0000000 0000000 # define-data-property [![Version Badge][npm-version-svg]][package-url]
[![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
ljharb-define-data-property-7397c50/index.d.ts 0000664 0000000 0000000 00000000473 14562717423 0021200 0 ustar 00root root 0000000 0000000
declare function defineDataProperty(
obj: Record,
property: keyof typeof obj,
value: typeof obj[typeof property],
nonEnumerable?: boolean | null,
nonWritable?: boolean | null,
nonConfigurable?: boolean | null,
loose?: boolean
): void;
export = defineDataProperty; ljharb-define-data-property-7397c50/index.js 0000664 0000000 0000000 00000004440 14562717423 0020742 0 ustar 00root root 0000000 0000000 'use strict';
var $defineProperty = require('es-define-property');
var $SyntaxError = require('es-errors/syntax');
var $TypeError = require('es-errors/type');
var gopd = require('gopd');
/** @type {import('.')} */
module.exports = function defineDataProperty(
obj,
property,
value
) {
if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) {
throw new $TypeError('`obj` must be an object or a function`');
}
if (typeof property !== 'string' && typeof property !== 'symbol') {
throw new $TypeError('`property` must be a string or a symbol`');
}
if (arguments.length > 3 && typeof arguments[3] !== 'boolean' && arguments[3] !== null) {
throw new $TypeError('`nonEnumerable`, if provided, must be a boolean or null');
}
if (arguments.length > 4 && typeof arguments[4] !== 'boolean' && arguments[4] !== null) {
throw new $TypeError('`nonWritable`, if provided, must be a boolean or null');
}
if (arguments.length > 5 && typeof arguments[5] !== 'boolean' && arguments[5] !== null) {
throw new $TypeError('`nonConfigurable`, if provided, must be a boolean or null');
}
if (arguments.length > 6 && typeof arguments[6] !== 'boolean') {
throw new $TypeError('`loose`, if provided, must be a boolean');
}
var nonEnumerable = arguments.length > 3 ? arguments[3] : null;
var nonWritable = arguments.length > 4 ? arguments[4] : null;
var nonConfigurable = arguments.length > 5 ? arguments[5] : null;
var loose = arguments.length > 6 ? arguments[6] : false;
/* @type {false | TypedPropertyDescriptor} */
var desc = !!gopd && gopd(obj, property);
if ($defineProperty) {
$defineProperty(obj, property, {
configurable: nonConfigurable === null && desc ? desc.configurable : !nonConfigurable,
enumerable: nonEnumerable === null && desc ? desc.enumerable : !nonEnumerable,
value: value,
writable: nonWritable === null && desc ? desc.writable : !nonWritable
});
} else if (loose || (!nonEnumerable && !nonWritable && !nonConfigurable)) {
// must fall back to [[Set]], and was not explicitly asked to make non-enumerable, non-writable, or non-configurable
obj[property] = value; // eslint-disable-line no-param-reassign
} else {
throw new $SyntaxError('This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.');
}
};
ljharb-define-data-property-7397c50/package.json 0000664 0000000 0000000 00000005450 14562717423 0021565 0 ustar 00root root 0000000 0000000 {
"name": "define-data-property",
"version": "1.1.4",
"description": "Define a data property on an object. Will fall back to assignment in an engine without descriptors.",
"main": "index.js",
"types": "./index.d.ts",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
},
"sideEffects": false,
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"tsc": "tsc -p .",
"prelint": "evalmd README.md",
"lint": "eslint --ext=js,mjs .",
"postlint": "npm run tsc",
"pretest": "npm run lint",
"tests-only": "nyc tape 'test/**/*.js'",
"test": "npm run tests-only",
"posttest": "aud --production",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/ljharb/define-data-property.git"
},
"keywords": [
"define",
"data",
"property",
"object",
"accessor",
"javascript",
"ecmascript",
"enumerable",
"configurable",
"writable"
],
"author": "Jordan Harband ",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/ljharb/define-data-property/issues"
},
"homepage": "https://github.com/ljharb/define-data-property#readme",
"dependencies": {
"es-define-property": "^1.0.0",
"es-errors": "^1.3.0",
"gopd": "^1.0.1"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.1.0",
"@types/call-bind": "^1.0.5",
"@types/define-properties": "^1.1.5",
"@types/es-value-fixtures": "^1.4.4",
"@types/for-each": "^0.3.3",
"@types/get-intrinsic": "^1.2.2",
"@types/gopd": "^1.0.3",
"@types/has-property-descriptors": "^1.0.3",
"@types/object-inspect": "^1.8.4",
"@types/object.getownpropertydescriptors": "^2.1.4",
"@types/tape": "^5.6.4",
"aud": "^2.0.4",
"auto-changelog": "^2.4.0",
"es-value-fixtures": "^1.4.2",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"for-each": "^0.3.3",
"hasown": "^2.0.1",
"in-publish": "^2.0.1",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"object-inspect": "^1.13.1",
"object.getownpropertydescriptors": "^2.1.7",
"reflect.ownkeys": "^1.1.4",
"safe-publish-latest": "^2.0.0",
"tape": "^5.7.4",
"typescript": "next"
},
"engines": {
"node": ">= 0.4"
},
"testling": {
"files": "test/index.js"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows",
"types/reflect.ownkeys"
]
}
}
ljharb-define-data-property-7397c50/test/ 0000775 0000000 0000000 00000000000 14562717423 0020252 5 ustar 00root root 0000000 0000000 ljharb-define-data-property-7397c50/test/index.js 0000664 0000000 0000000 00000024347 14562717423 0021731 0 ustar 00root root 0000000 0000000 'use strict';
var test = require('tape');
var v = require('es-value-fixtures');
var forEach = require('for-each');
var inspect = require('object-inspect');
var hasOwn = require('hasown');
var hasPropertyDescriptors = require('has-property-descriptors')();
var getOwnPropertyDescriptors = require('object.getownpropertydescriptors');
var ownKeys = require('reflect.ownkeys');
var defineDataProperty = require('../');
test('defineDataProperty', function (t) {
t.test('argument validation', function (st) {
forEach(v.primitives, function (nonObject) {
st['throws'](
// @ts-expect-error
function () { defineDataProperty(nonObject, 'key', 'value'); },
TypeError,
'throws on non-object input: ' + inspect(nonObject)
);
});
forEach(v.nonPropertyKeys, function (nonPropertyKey) {
st['throws'](
// @ts-expect-error
function () { defineDataProperty({}, nonPropertyKey, 'value'); },
TypeError,
'throws on non-PropertyKey input: ' + inspect(nonPropertyKey)
);
});
forEach(v.nonBooleans, function (nonBoolean) {
if (nonBoolean !== null) {
st['throws'](
// @ts-expect-error
function () { defineDataProperty({}, 'key', 'value', nonBoolean); },
TypeError,
'throws on non-boolean nonEnumerable: ' + inspect(nonBoolean)
);
st['throws'](
// @ts-expect-error
function () { defineDataProperty({}, 'key', 'value', false, nonBoolean); },
TypeError,
'throws on non-boolean nonWritable: ' + inspect(nonBoolean)
);
st['throws'](
// @ts-expect-error
function () { defineDataProperty({}, 'key', 'value', false, false, nonBoolean); },
TypeError,
'throws on non-boolean nonConfigurable: ' + inspect(nonBoolean)
);
}
});
st.end();
});
t.test('normal data property', function (st) {
/** @type {Record} */
var obj = { existing: 'existing property' };
st.ok(hasOwn(obj, 'existing'), 'has initial own property');
st.equal(obj.existing, 'existing property', 'has expected initial value');
var res = defineDataProperty(obj, 'added', 'added property');
st.equal(res, void undefined, 'returns `undefined`');
st.ok(hasOwn(obj, 'added'), 'has expected own property');
st.equal(obj.added, 'added property', 'has expected value');
defineDataProperty(obj, 'existing', 'new value');
st.ok(hasOwn(obj, 'existing'), 'still has expected own property');
st.equal(obj.existing, 'new value', 'has new expected value');
defineDataProperty(obj, 'explicit1', 'new value', false);
st.ok(hasOwn(obj, 'explicit1'), 'has expected own property (explicit enumerable)');
st.equal(obj.explicit1, 'new value', 'has new expected value (explicit enumerable)');
defineDataProperty(obj, 'explicit2', 'new value', false, false);
st.ok(hasOwn(obj, 'explicit2'), 'has expected own property (explicit writable)');
st.equal(obj.explicit2, 'new value', 'has new expected value (explicit writable)');
defineDataProperty(obj, 'explicit3', 'new value', false, false, false);
st.ok(hasOwn(obj, 'explicit3'), 'has expected own property (explicit configurable)');
st.equal(obj.explicit3, 'new value', 'has new expected value (explicit configurable)');
st.end();
});
t.test('loose mode', { skip: !hasPropertyDescriptors }, function (st) {
var obj = { existing: 'existing property' };
defineDataProperty(obj, 'added', 'added value 1', true, null, null, true);
st.deepEqual(
getOwnPropertyDescriptors(obj),
{
existing: {
configurable: true,
enumerable: true,
value: 'existing property',
writable: true
},
added: {
configurable: true,
enumerable: !hasPropertyDescriptors,
value: 'added value 1',
writable: true
}
},
'in loose mode, obj still adds property 1'
);
defineDataProperty(obj, 'added', 'added value 2', false, true, null, true);
st.deepEqual(
getOwnPropertyDescriptors(obj),
{
existing: {
configurable: true,
enumerable: true,
value: 'existing property',
writable: true
},
added: {
configurable: true,
enumerable: true,
value: 'added value 2',
writable: !hasPropertyDescriptors
}
},
'in loose mode, obj still adds property 2'
);
defineDataProperty(obj, 'added', 'added value 3', false, false, true, true);
st.deepEqual(
getOwnPropertyDescriptors(obj),
{
existing: {
configurable: true,
enumerable: true,
value: 'existing property',
writable: true
},
added: {
configurable: !hasPropertyDescriptors,
enumerable: true,
value: 'added value 3',
writable: true
}
},
'in loose mode, obj still adds property 3'
);
st.end();
});
t.test('non-normal data property, ES3', { skip: hasPropertyDescriptors }, function (st) {
/** @type {Record} */
var obj = { existing: 'existing property' };
st['throws'](
function () { defineDataProperty(obj, 'added', 'added value', true); },
SyntaxError,
'nonEnumerable throws a Syntax Error'
);
st['throws'](
function () { defineDataProperty(obj, 'added', 'added value', false, true); },
SyntaxError,
'nonWritable throws a Syntax Error'
);
st['throws'](
function () { defineDataProperty(obj, 'added', 'added value', false, false, true); },
SyntaxError,
'nonWritable throws a Syntax Error'
);
st.deepEqual(
ownKeys(obj),
['existing'],
'obj still has expected keys'
);
st.equal(obj.existing, 'existing property', 'obj still has expected values');
st.end();
});
t.test('new non-normal data property, ES5+', { skip: !hasPropertyDescriptors }, function (st) {
/** @type {Record} */
var obj = { existing: 'existing property' };
defineDataProperty(obj, 'nonEnum', null, true);
defineDataProperty(obj, 'nonWrit', null, false, true);
defineDataProperty(obj, 'nonConf', null, false, false, true);
st.deepEqual(
getOwnPropertyDescriptors(obj),
{
existing: {
configurable: true,
enumerable: true,
value: 'existing property',
writable: true
},
nonEnum: {
configurable: true,
enumerable: false,
value: null,
writable: true
},
nonWrit: {
configurable: true,
enumerable: true,
value: null,
writable: false
},
nonConf: {
configurable: false,
enumerable: true,
value: null,
writable: true
}
},
'obj has expected property descriptors'
);
st.end();
});
t.test('existing non-normal data property, ES5+', { skip: !hasPropertyDescriptors }, function (st) {
// test case changing an existing non-normal property
/** @type {Record} */
var obj = {};
Object.defineProperty(obj, 'nonEnum', { configurable: true, enumerable: false, value: null, writable: true });
Object.defineProperty(obj, 'nonWrit', { configurable: true, enumerable: true, value: null, writable: false });
Object.defineProperty(obj, 'nonConf', { configurable: false, enumerable: true, value: null, writable: true });
st.deepEqual(
getOwnPropertyDescriptors(obj),
{
nonEnum: {
configurable: true,
enumerable: false,
value: null,
writable: true
},
nonWrit: {
configurable: true,
enumerable: true,
value: null,
writable: false
},
nonConf: {
configurable: false,
enumerable: true,
value: null,
writable: true
}
},
'obj initially has expected property descriptors'
);
defineDataProperty(obj, 'nonEnum', 'new value', false);
defineDataProperty(obj, 'nonWrit', 'new value', false, false);
st['throws'](
function () { defineDataProperty(obj, 'nonConf', 'new value', false, false, false); },
TypeError,
'can not alter a nonconfigurable property'
);
st.deepEqual(
getOwnPropertyDescriptors(obj),
{
nonEnum: {
configurable: true,
enumerable: true,
value: 'new value',
writable: true
},
nonWrit: {
configurable: true,
enumerable: true,
value: 'new value',
writable: true
},
nonConf: {
configurable: false,
enumerable: true,
value: null,
writable: true
}
},
'obj ends up with expected property descriptors'
);
st.end();
});
t.test('frozen object, ES5+', { skip: !hasPropertyDescriptors }, function (st) {
var frozen = Object.freeze({ existing: true });
st['throws'](
function () { defineDataProperty(frozen, 'existing', 'new value'); },
TypeError,
'frozen object can not modify an existing property'
);
st['throws'](
function () { defineDataProperty(frozen, 'new', 'new property'); },
TypeError,
'frozen object can not add a new property'
);
st.end();
});
t.test('sealed object, ES5+', { skip: !hasPropertyDescriptors }, function (st) {
var sealed = Object.seal({ existing: true });
st.deepEqual(
Object.getOwnPropertyDescriptor(sealed, 'existing'),
{
configurable: false,
enumerable: true,
value: true,
writable: true
},
'existing value on sealed object has expected descriptor'
);
defineDataProperty(sealed, 'existing', 'new value');
st.deepEqual(
Object.getOwnPropertyDescriptor(sealed, 'existing'),
{
configurable: false,
enumerable: true,
value: 'new value',
writable: true
},
'existing value on sealed object has changed descriptor'
);
st['throws'](
function () { defineDataProperty(sealed, 'new', 'new property'); },
TypeError,
'sealed object can not add a new property'
);
st.end();
});
t.test('nonextensible object, ES5+', { skip: !hasPropertyDescriptors }, function (st) {
var nonExt = Object.preventExtensions({ existing: true });
st.deepEqual(
Object.getOwnPropertyDescriptor(nonExt, 'existing'),
{
configurable: true,
enumerable: true,
value: true,
writable: true
},
'existing value on non-extensible object has expected descriptor'
);
defineDataProperty(nonExt, 'existing', 'new value', true);
st.deepEqual(
Object.getOwnPropertyDescriptor(nonExt, 'existing'),
{
configurable: true,
enumerable: false,
value: 'new value',
writable: true
},
'existing value on non-extensible object has changed descriptor'
);
st['throws'](
function () { defineDataProperty(nonExt, 'new', 'new property'); },
TypeError,
'non-extensible object can not add a new property'
);
st.end();
});
t.end();
});
ljharb-define-data-property-7397c50/tsconfig.json 0000664 0000000 0000000 00000011423 14562717423 0022003 0 ustar 00root root 0000000 0000000 {
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
/* Language and Environment */
"target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
"useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
"typeRoots": ["types"], /* Specify multiple folders that act like './node_modules/@types'. */
"resolveJsonModule": true, /* Enable importing .json files. */
/* JavaScript Support */
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
"checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
"maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
/* Emit */
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
"declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
"noEmit": true, /* Disable emitting files from a compilation. */
/* Interop Constraints */
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
"noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
"useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
"noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
"noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
"noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
"noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
"noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
"noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
/* Completeness */
// "skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"exclude": [
"coverage"
]
}
ljharb-define-data-property-7397c50/types/ 0000775 0000000 0000000 00000000000 14562717423 0020437 5 ustar 00root root 0000000 0000000 ljharb-define-data-property-7397c50/types/reflect.ownkeys/ 0000775 0000000 0000000 00000000000 14562717423 0023561 5 ustar 00root root 0000000 0000000 ljharb-define-data-property-7397c50/types/reflect.ownkeys/implementation.d.ts 0000664 0000000 0000000 00000000205 14562717423 0027375 0 ustar 00root root 0000000 0000000 declare module 'reflect.ownkeys/implementation' {
function ownKeys(target: object): (string | symbol)[];
export = ownKeys;
} ljharb-define-data-property-7397c50/types/reflect.ownkeys/index.d.ts 0000664 0000000 0000000 00000000173 14562717423 0025463 0 ustar 00root root 0000000 0000000 declare module 'reflect.ownkeys' {
import ownKeys = require('reflect.ownkeys/implementation');
export = ownKeys;
} ljharb-define-data-property-7397c50/types/reflect.ownkeys/polyfill.d.ts 0000664 0000000 0000000 00000000205 14562717423 0026202 0 ustar 00root root 0000000 0000000 declare module 'reflect.ownkeys/polyfill' {
import ownKeys = require('reflect.ownkeys/implementation');
export = ownKeys;
}
ljharb-define-data-property-7397c50/types/reflect.ownkeys/shim.d.ts 0000664 0000000 0000000 00000000201 14562717423 0025304 0 ustar 00root root 0000000 0000000 declare module 'reflect.ownkeys/shim' {
import ownKeys = require('reflect.ownkeys/implementation');
export = ownKeys;
}