Socket
Socket
Sign inDemoInstall

mock-property

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-property - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

tmp.html

33

CHANGELOG.md

@@ -1,13 +0,36 @@

### Changelog
# Changelog
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
All notable changes to this project will be documented in this file.
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
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.0.0
## [v1.0.1](https://github.com/ljharb/mock-property/compare/v1.0.0...v1.0.1) - 2023-10-11
> 16 April 2022
### Commits
- [meta] use `npmignore` to autogenerate an npmignore file [`46993e4`](https://github.com/ljharb/mock-property/commit/46993e4f1c0943e66f64fe1a94b05f433f4f434f)
- [Refactor] use `define-data-property` for data properties [`04e7859`](https://github.com/ljharb/mock-property/commit/04e7859e26f39806b90d1ff070d0935e210cb9aa)
- [patch] replace spaces with tabs [`be261ab`](https://github.com/ljharb/mock-property/commit/be261abea438ee1f3dca9c8721add88c11658cd9)
- [meta] fix auto-changelog config [`39eca6c`](https://github.com/ljharb/mock-property/commit/39eca6c3e483074c60b13e4dd657a62cdb836a70)
- [Fix] on restore, properly delete previously nonexistent properties in ES3 engines [`0378863`](https://github.com/ljharb/mock-property/commit/0378863cf9541f965a7822b1ed92660afdd7720d)
- [Fix] use `gopd` to handle IE < 9 [`f4a7461`](https://github.com/ljharb/mock-property/commit/f4a746146154196261caac342f4afb59bde1508d)
- [actions] update rebase action [`fea7b9c`](https://github.com/ljharb/mock-property/commit/fea7b9c53cff3bcf6011ed565a76139a1f088052)
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `object-inspect`, `tape` [`3a5c6f5`](https://github.com/ljharb/mock-property/commit/3a5c6f564125e4af28c35d6213bb588c0c695194)
- [Fix] throw validation errors before SyntaxErrors [`34c9995`](https://github.com/ljharb/mock-property/commit/34c99958fb36c5970ac14344acb34c4294b1a5ea)
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`cb46e3d`](https://github.com/ljharb/mock-property/commit/cb46e3de91cb4b40e6428e9028a832d2b67e64e3)
- [Dev Deps] update `es-value-fixtures`, `object-inspect`, `tape` [`bc66f0d`](https://github.com/ljharb/mock-property/commit/bc66f0d2d7d6b12c3b4112b99c38c1ae58572304)
- [Fix] in ES3 engines, do not attempt to change enumerability of array lengths [`cea6cd6`](https://github.com/ljharb/mock-property/commit/cea6cd6ed18b0f6b569735e398f2d767d3b0f4a0)
- [Dev Deps] update `tape` [`e44b744`](https://github.com/ljharb/mock-property/commit/e44b744399b785254f86d4c9f2b97d43ae38fb03)
- [Tests] skip tests that require ES5 in ES3 [`baa63d8`](https://github.com/ljharb/mock-property/commit/baa63d89ab326d257c6ee59491afb8fdd9e3c84e)
- [Deps] update `functions-have-names` [`dd791a7`](https://github.com/ljharb/mock-property/commit/dd791a7f934cf63a52d634da184a57e25341e2a0)
- [meta] correct FUNDING.yml [`5e2ca17`](https://github.com/ljharb/mock-property/commit/5e2ca17d71d1959c6e2c67a453b5d4528199ea36)
## v1.0.0 - 2022-04-16
### Commits
- Initial implementation, tests, readme [`dc1a5ff`](https://github.com/ljharb/mock-property/commit/dc1a5ff66da575e7714529854f4608cb91c01729)
- Initial commit [`8a8282a`](https://github.com/ljharb/mock-property/commit/8a8282ab7fe07083d497e991dac582ebc362ea30)
- npm init [`28c438a`](https://github.com/ljharb/mock-property/commit/28c438a5352c9b3a9a983cb9dfd9b1f37e04cc52)
- Only apps should have lockfiles [`6316905`](https://github.com/ljharb/mock-property/commit/6316905ca992763cabf7fa9269aa25db36cd928e)

77

index.js

@@ -7,9 +7,10 @@ 'use strict';

var functionsHaveConfigurableNames = require('functions-have-names').functionsHaveConfigurableNames();
var gOPD = require('gopd');
var defineDataProperty = require('define-data-property');
var $defineProperty = hasPropertyDescriptors() && Object.defineProperty;
var hasDescriptors = hasPropertyDescriptors();
var $defineProperty = hasDescriptors && Object.defineProperty;
var hasArrayLengthDefineBug = hasPropertyDescriptors.hasArrayLengthDefineBug();
var gOPD = Object.getOwnPropertyDescriptor;
var $TypeError = TypeError;

@@ -32,2 +33,6 @@ var $SyntaxError = SyntaxError;

if (options['delete'] && (wantsData || wantsAccessor || has(options, 'nonEnumerable'))) {
throw new $TypeError('`delete` option must not be set to true when any of `value`, `get`, `set`, `nonWritable`, or `nonEnumerable` are provided');
}
if (wantsAccessor) {

@@ -39,3 +44,3 @@ if (wantsData) {

(has(options, 'get') && typeof options.get !== 'function' && typeof options.get !== 'undefined')
|| (has(options, 'set') && typeof options.set !== 'function' && typeof options.set !== 'undefined')
|| (has(options, 'set') && typeof options.set !== 'function' && typeof options.set !== 'undefined')
) {

@@ -48,5 +53,2 @@ throw new $TypeError('`get` and `set` options, when present, must be functions or `undefined`');

}
if (options['delete'] && (wantsData || wantsAccessor || has(options, 'nonEnumerable'))) {
throw new $TypeError('`delete` option must not be set to true when any of `value`, `get`, `set`, `nonWritable`, or `nonEnumerable` are provided');
}

@@ -56,8 +58,10 @@ var objIsArray = isArray(obj);

? gOPD(obj, prop)
: {
configurable: typeof obj === 'function' && prop === 'name' ? functionsHaveConfigurableNames : true,
enumerable: !(objIsArray && prop === 'length'),
value: obj[prop],
writable: true
};
: has(obj, prop)
? {
configurable: typeof obj === 'function' && prop === 'name' ? functionsHaveConfigurableNames : true,
enumerable: !(hasDescriptors && objIsArray && prop === 'length'),
value: obj[prop],
writable: true
}
: void undefined;

@@ -114,7 +118,7 @@ var origConfigurable = origDescriptor ? origDescriptor.configurable : true;

wantsData
&& !isChangingEnumerability
&& (!origDescriptor || origDescriptor.enumerable)
&& (!has(options, 'nonWritable') || !options.nonWritable)
&& (!origDescriptor || origDescriptor.writable)
&& (!gOPD || !(prop in obj))
&& !isChangingEnumerability
&& (!origDescriptor || origDescriptor.enumerable)
&& (!has(options, 'nonWritable') || !options.nonWritable)
&& (!origDescriptor || origDescriptor.writable)
&& (!gOPD || !(prop in obj))
) {

@@ -130,8 +134,9 @@ obj[prop] = options.value; // eslint-disable-line no-param-reassign

if (wantsData) {
$defineProperty(obj, prop, {
configurable: origConfigurable,
enumerable: newEnumerable,
value: has(options, 'value') ? options.value : origDescriptor.value,
writable: has(options, 'nonWritable') ? !options.nonWritable : has(origDescriptor, 'writable') ? origDescriptor.writable : true
});
defineDataProperty(
obj,
prop,
has(options, 'value') ? options.value : origDescriptor.value,
!newEnumerable,
has(options, 'nonWritable') ? options.nonWritable : has(origDescriptor, 'writable') ? !origDescriptor.writable : false
);
} else if (wantsAccessor) {

@@ -148,6 +153,8 @@ var getter = has(options, 'get') ? options.get : origDescriptor && origDescriptor.get;

} else {
$defineProperty(obj, prop, {
configurable: origConfigurable,
enumerable: newEnumerable
});
defineDataProperty(
obj,
prop,
origDescriptor.value,
!newEnumerable
);
}

@@ -161,8 +168,10 @@ }

if (has(origDescriptor, 'writable')) {
$defineProperty(obj, prop, {
configurable: origDescriptor.configurable,
enumerable: origDescriptor.enumerable,
value: origDescriptor.value,
writable: origDescriptor.writable
});
defineDataProperty(
obj,
prop,
origDescriptor.value,
!origDescriptor.enumerable,
!origDescriptor.writable,
!origDescriptor.configurable
);
} else {

@@ -169,0 +178,0 @@ var oldGetter = origDescriptor && origDescriptor.get;

{
"name": "mock-property",
"version": "1.0.0",
"version": "1.0.1",
"description": "Given an object and a property, replaces a property descriptor (or deletes it), and returns a thunk to restore it.",

@@ -11,2 +11,3 @@ "main": "index.js",

"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublish": "not-in-publish || npm run prepublishOnly",

@@ -48,6 +49,6 @@ "prepublishOnly": "safe-publish-latest",

"devDependencies": {
"@ljharb/eslint-config": "^21.0.0",
"aud": "^2.0.0",
"@ljharb/eslint-config": "^21.1.0",
"aud": "^2.0.3",
"auto-changelog": "^2.4.0",
"es-value-fixtures": "^1.2.1",
"es-value-fixtures": "^1.4.2",
"eslint": "=8.8.0",

@@ -57,13 +58,35 @@ "evalmd": "^0.0.19",

"in-publish": "^2.0.1",
"npmignore": "^0.3.0",
"nyc": "^10.3.2",
"object-inspect": "^1.12.0",
"object-inspect": "^1.12.3",
"safe-publish-latest": "^2.0.0",
"tape": "^5.5.3"
"tape": "^5.7.1"
},
"dependencies": {
"functions-have-names": "^1.2.2",
"define-data-property": "^1.1.0",
"functions-have-names": "^1.2.3",
"gopd": "^1.0.1",
"has": "^1.0.3",
"has-property-descriptors": "^1.0.0",
"isarray": "^2.0.5"
},
"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"
]
}
}

@@ -22,7 +22,7 @@ # mock-property <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

var object = {
a: 1,
get b() {
i += 1;
return 'b ' + i;
}
a: 1,
get b() {
i += 1;
return 'b ' + i;
}
};

@@ -29,0 +29,0 @@

@@ -121,3 +121,3 @@ 'use strict';

t.test('data: enumerable -> nonEnumerable', function (st) {
t.test('data: enumerable -> nonEnumerable', { skip: !hasPropertyDescriptors() }, function (st) {
var obj = { a: sentinel };

@@ -124,0 +124,0 @@ st.ok(Object.prototype.propertyIsEnumerable.call(obj, 'a'), 'starts enumerable');

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc