pax_global_header 0000666 0000000 0000000 00000000064 14500342071 0014506 g ustar 00root root 0000000 0000000 52 comment=48c2253c040b9fddc0529794fdc75205cb153e75
define-data-property-1.1.0/ 0000775 0000000 0000000 00000000000 14500342071 0015530 5 ustar 00root root 0000000 0000000 define-data-property-1.1.0/.eslintrc 0000664 0000000 0000000 00000000443 14500342071 0017355 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",
},
},
],
}
define-data-property-1.1.0/.github/ 0000775 0000000 0000000 00000000000 14500342071 0017070 5 ustar 00root root 0000000 0000000 define-data-property-1.1.0/.github/FUNDING.yml 0000664 0000000 0000000 00000001117 14500342071 0020705 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']
define-data-property-1.1.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14500342071 0021125 5 ustar 00root root 0000000 0000000 define-data-property-1.1.0/.github/workflows/node-aught.yml 0000664 0000000 0000000 00000000637 14500342071 0023711 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: 'echo tests completed'
define-data-property-1.1.0/.github/workflows/node-pretest.yml 0000664 0000000 0000000 00000000245 14500342071 0024262 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
define-data-property-1.1.0/.github/workflows/node-tens.yml 0000664 0000000 0000000 00000000521 14500342071 0023542 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: 'echo tests completed'
define-data-property-1.1.0/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000267 14500342071 0023116 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 }}
define-data-property-1.1.0/.github/workflows/require-allow-edits.yml 0000664 0000000 0000000 00000000303 14500342071 0025542 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
define-data-property-1.1.0/.gitignore 0000664 0000000 0000000 00000004155 14500342071 0017525 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
*.ts
*.ts.map
define-data-property-1.1.0/.npmrc 0000664 0000000 0000000 00000000067 14500342071 0016653 0 ustar 00root root 0000000 0000000 package-lock=false
allow-same-version=true
message=v%s
define-data-property-1.1.0/.nycrc 0000664 0000000 0000000 00000000330 14500342071 0016643 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"
]
}
define-data-property-1.1.0/CHANGELOG.md 0000664 0000000 0000000 00000003620 14500342071 0017342 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.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)
define-data-property-1.1.0/LICENSE 0000664 0000000 0000000 00000002057 14500342071 0016541 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.
define-data-property-1.1.0/README.md 0000664 0000000 0000000 00000004577 14500342071 0017024 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
define-data-property-1.1.0/index.js 0000664 0000000 0000000 00000005171 14500342071 0017201 0 ustar 00root root 0000000 0000000 'use strict';
var hasPropertyDescriptors = require('has-property-descriptors')();
var GetIntrinsic = require('get-intrinsic');
var $defineProperty = hasPropertyDescriptors && GetIntrinsic('%Object.defineProperty%', true);
var $SyntaxError = GetIntrinsic('%SyntaxError%');
var $TypeError = GetIntrinsic('%TypeError%');
var gopd = require('gopd');
/** @type {(obj: Record, property: PropertyKey, value: unknown, nonEnumerable?: boolean | null, nonWritable?: boolean | null, nonConfigurable?: boolean | null, loose?: boolean) => void} */
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.');
}
};
define-data-property-1.1.0/package.json 0000664 0000000 0000000 00000005671 14500342071 0020027 0 ustar 00root root 0000000 0000000 {
"name": "define-data-property",
"version": "1.1.0",
"description": "Define a data property on an object. Will fall back to assignment in an engine without descriptors.",
"main": "index.js",
"exports": {
".": [
{
"types": "./index.d.ts",
"default": "./index.js"
},
"./index.js"
],
"./package.json": "./package.json"
},
"sideEffects": false,
"types": "./index.d.ts",
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"tsc": "tsc -p .",
"preemit-types": "rm -f *.ts *.ts.map test/*.ts test/*.ts.map",
"emit-types": "npm run tsc -- --noEmit false --emitDeclarationOnly",
"postemit-types": "rm test/*.ts test/*.ts.map",
"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 ",
"license": "MIT",
"bugs": {
"url": "https://github.com/ljharb/define-data-property/issues"
},
"homepage": "https://github.com/ljharb/define-data-property#readme",
"dependencies": {
"get-intrinsic": "^1.2.1",
"gopd": "^1.0.1",
"has-property-descriptors": "^1.0.0"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.1.0",
"@types/es-value-fixtures": "^1.4.0",
"@types/for-each": "^0.3.0",
"@types/get-intrinsic": "^1.2.0",
"@types/gopd": "^1.0.0",
"@types/has": "^1.0.0",
"@types/has-property-descriptors": "^1.0.0",
"@types/object-inspect": "^1.8.2",
"@types/object.getownpropertydescriptors": "^2.1.2",
"@types/tape": "^5.6.1",
"aud": "^2.0.3",
"auto-changelog": "^2.4.0",
"es-value-fixtures": "^1.4.2",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"for-each": "^0.3.3",
"has": "^1.0.3",
"in-publish": "^2.0.1",
"npmignore": "^0.3.0",
"nyc": "^10.3.2",
"object-inspect": "^1.12.3",
"object.getownpropertydescriptors": "^2.1.7",
"safe-publish-latest": "^2.0.0",
"tape": "^5.6.6",
"typescript": "^5.3.0-dev.20230912"
},
"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",
"!*.ts",
"!*.ts.map"
]
}
}
define-data-property-1.1.0/test/ 0000775 0000000 0000000 00000000000 14500342071 0016507 5 ustar 00root root 0000000 0000000 define-data-property-1.1.0/test/index.js 0000664 0000000 0000000 00000024275 14500342071 0020166 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 has = require('has');
var hasPropertyDescriptors = require('has-property-descriptors')();
var getOwnPropertyDescriptors = require('object.getownpropertydescriptors');
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(has(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(has(obj, 'added'), 'has expected own property');
st.equal(obj.added, 'added property', 'has expected value');
defineDataProperty(obj, 'existing', 'new value');
st.ok(has(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(has(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(has(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(has(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', 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(
getOwnPropertyDescriptors(obj),
{
existing: {
configurable: true,
enumerable: true,
value: 'existing property',
writable: true
}
},
'obj still has expected descriptors'
);
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();
});
define-data-property-1.1.0/tsconfig.json 0000664 0000000 0000000 00000011224 14500342071 0020237 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. */
"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"
]
}