pax_global_header 0000666 0000000 0000000 00000000064 14500250401 0014501 g ustar 00root root 0000000 0000000 52 comment=d7a4db30214eb06d3997dc3e662c11dfe95b25bd
define-properties-1.2.1/ 0000775 0000000 0000000 00000000000 14500250401 0015126 5 ustar 00root root 0000000 0000000 define-properties-1.2.1/.editorconfig 0000664 0000000 0000000 00000000424 14500250401 0017603 0 ustar 00root root 0000000 0000000 root = true
[*]
indent_style = tab;
insert_final_newline = true;
quote_type = auto;
space_after_anonymous_functions = true;
space_after_control_statements = true;
spaces_around_operators = true;
trim_trailing_whitespace = true;
spaces_in_brackets = false;
end_of_line = lf;
define-properties-1.2.1/.eslintrc 0000664 0000000 0000000 00000000353 14500250401 0016753 0 ustar 00root root 0000000 0000000 {
"root": true,
"extends": "@ljharb",
"rules": {
"id-length": [2, { "min": 1, "max": 35 }],
"max-params": [2, 4],
},
"overrides": [
{
"files": "test/**",
"rules": {
"max-lines-per-function": 0,
},
},
],
}
define-properties-1.2.1/.github/ 0000775 0000000 0000000 00000000000 14500250401 0016466 5 ustar 00root root 0000000 0000000 define-properties-1.2.1/.github/FUNDING.yml 0000664 0000000 0000000 00000001114 14500250401 0020300 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-properties
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-properties-1.2.1/.github/workflows/ 0000775 0000000 0000000 00000000000 14500250401 0020523 5 ustar 00root root 0000000 0000000 define-properties-1.2.1/.github/workflows/node-aught.yml 0000664 0000000 0000000 00000000516 14500250401 0023303 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-properties-1.2.1/.github/workflows/node-pretest.yml 0000664 0000000 0000000 00000000245 14500250401 0023660 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-properties-1.2.1/.github/workflows/node-tens.yml 0000664 0000000 0000000 00000000521 14500250401 0023140 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-properties-1.2.1/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000257 14500250401 0022513 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-properties-1.2.1/.github/workflows/require-allow-edits.yml 0000664 0000000 0000000 00000000303 14500250401 0025140 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-properties-1.2.1/.gitignore 0000664 0000000 0000000 00000000220 14500250401 0017110 0 ustar 00root root 0000000 0000000 # gitignore
node_modules
# Only apps should have lockfile
npm-shrinkwrap.json
package-lock.json
yarn.lock
coverage/
.nyc_output/
.npmignore
define-properties-1.2.1/.npmrc 0000664 0000000 0000000 00000000067 14500250401 0016251 0 ustar 00root root 0000000 0000000 package-lock=false
allow-same-version=true
message=v%s
define-properties-1.2.1/.nycrc 0000664 0000000 0000000 00000000213 14500250401 0016241 0 ustar 00root root 0000000 0000000 {
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"exclude": [
"coverage",
"test"
]
}
define-properties-1.2.1/CHANGELOG.md 0000664 0000000 0000000 00000010147 14500250401 0016742 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.2.1](https://github.com/ljharb/define-properties/compare/v1.2.0...v1.2.1) - 2023-09-12
### Commits
- [Refactor] use `define-data-property` [`e7782a7`](https://github.com/ljharb/define-properties/commit/e7782a7480a62f8b6e141b49371e6de4df176c97)
- [actions] use reusable rebase action [`cd249c3`](https://github.com/ljharb/define-properties/commit/cd249c3920607bc8eeb7c0cd5b672b810983cac5)
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`8205f97`](https://github.com/ljharb/define-properties/commit/8205f9734a4da8ee5b3b29798788567a09b330e8)
## [v1.2.0](https://github.com/ljharb/define-properties/compare/v1.1.4...v1.2.0) - 2023-02-10
### Commits
- [New] if the predicate is boolean `true`, it compares the existing value with `===` as the predicate [`d8dd6fc`](https://github.com/ljharb/define-properties/commit/d8dd6fca40d7c5878a4b643b91e66ae5a513a194)
- [meta] add `auto-changelog` [`7ebe2b0`](https://github.com/ljharb/define-properties/commit/7ebe2b0a0f90e62b842942cd45e86864fe75d9f6)
- [meta] use `npmignore` to autogenerate an npmignore file [`647478a`](https://github.com/ljharb/define-properties/commit/647478a8401fbf053fb633c0a3a7c982da6bad74)
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`e620d70`](https://github.com/ljharb/define-properties/commit/e620d707d2e1118a38796f22a862200eb0a53fff)
- [Dev Deps] update `aud`, `tape` [`f1e5072`](https://github.com/ljharb/define-properties/commit/f1e507225c2551a99ed4fe40d3fe71b0f44acf88)
- [actions] update checkout action [`628b3af`](https://github.com/ljharb/define-properties/commit/628b3af5c74b8f0963296d811a8f6fa657baf964)
1.1.4 / 2022-04-14
=================
* [Refactor] use `has-property-descriptors`
* [readme] add github actions/codecov badges
* [Docs] fix header parsing; remove testling
* [Deps] update `object-keys`
* [meta] use `prepublishOnly` script for npm 7+
* [meta] add `funding` field; create FUNDING.yml
* [actions] add "Allow Edits" workflow; automatic rebasing / merge commit blocking
* [actions] reuse common workflows
* [actions] update codecov uploader
* [actions] use `node/install` instead of `node/run`; use `codecov` action
* [Tests] migrate tests to Github Actions
* [Tests] run `nyc` on all tests; use `tape` runner
* [Tests] use shared travis-ci config
* [Tests] use `npx aud` instead of `nsp` or `npm audit` with hoops
* [Tests] remove `jscs`
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `safe-publish-latest`, `tape`; add `aud`, `safe-publish-latest`
1.1.3 / 2018-08-14
=================
* [Refactor] use a for loop instead of `foreach` to make for smaller bundle sizes
* [Robustness] cache `Array.prototype.concat` and `Object.defineProperty`
* [Deps] update `object-keys`
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `nsp`, `tape`, `jscs`; remove unused eccheck script + dep
* [Tests] use pretest/posttest for linting/security
* [Tests] fix npm upgrades on older nodes
1.1.2 / 2015-10-14
=================
* [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG
* [Deps] Update `object-keys`
* [Dev Deps] update `jscs`, `tape`, `eslint`, `@ljharb/eslint-config`, `nsp`
* [Tests] up to `io.js` `v3.3`, `node` `v4.2`
1.1.1 / 2015-07-21
=================
* [Deps] Update `object-keys`
* [Dev Deps] Update `tape`, `eslint`
* [Tests] Test on `io.js` `v2.4`
1.1.0 / 2015-07-01
=================
* [New] Add support for symbol-valued properties.
* [Dev Deps] Update `nsp`, `eslint`
* [Tests] Test up to `io.js` `v2.3`
1.0.3 / 2015-05-30
=================
* Using a more reliable check for supported property descriptors.
1.0.2 / 2015-05-23
=================
* Test up to `io.js` `v2.0`
* Update `tape`, `jscs`, `nsp`, `eslint`, `object-keys`, `editorconfig-tools`, `covert`
1.0.1 / 2015-01-06
=================
* Update `object-keys` to fix ES3 support
1.0.0 / 2015-01-04
=================
* v1.0.0
define-properties-1.2.1/LICENSE 0000664 0000000 0000000 00000002070 14500250401 0016132 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (C) 2015 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-properties-1.2.1/README.md 0000664 0000000 0000000 00000005410 14500250401 0016405 0 ustar 00root root 0000000 0000000 # define-properties [![Version Badge][npm-version-svg]][package-url]
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines.
Existing properties are not overridden. Accepts a map of property names to a predicate that, when true, force-overrides.
## Example
```js
var define = require('define-properties');
var assert = require('assert');
var obj = define({ a: 1, b: 2 }, {
a: 10,
b: 20,
c: 30
});
assert(obj.a === 1);
assert(obj.b === 2);
assert(obj.c === 30);
if (define.supportsDescriptors) {
assert.deepEqual(Object.keys(obj), ['a', 'b']);
assert.deepEqual(Object.getOwnPropertyDescriptor(obj, 'c'), {
configurable: true,
enumerable: false,
value: 30,
writable: false
});
}
```
Then, with predicates:
```js
var define = require('define-properties');
var assert = require('assert');
var obj = define({ a: 1, b: 2, c: 3 }, {
a: 10,
b: 20,
c: 30
}, {
a: function () { return false; },
b: function () { return true; }
});
assert(obj.a === 1);
assert(obj.b === 20);
assert(obj.c === 3);
if (define.supportsDescriptors) {
assert.deepEqual(Object.keys(obj), ['a', 'c']);
assert.deepEqual(Object.getOwnPropertyDescriptor(obj, 'b'), {
configurable: true,
enumerable: false,
value: 20,
writable: false
});
}
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/define-properties
[npm-version-svg]: https://versionbadg.es/ljharb/define-properties.svg
[deps-svg]: https://david-dm.org/ljharb/define-properties.svg
[deps-url]: https://david-dm.org/ljharb/define-properties
[dev-deps-svg]: https://david-dm.org/ljharb/define-properties/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/define-properties#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/define-properties.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/define-properties.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/define-properties.svg
[downloads-url]: https://npm-stat.com/charts.html?package=define-properties
[codecov-image]: https://codecov.io/gh/ljharb/define-properties/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/ljharb/define-properties/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/define-properties
[actions-url]: https://github.com/ljharb/define-properties/actions
define-properties-1.2.1/index.js 0000664 0000000 0000000 00000002364 14500250401 0016600 0 ustar 00root root 0000000 0000000 'use strict';
var keys = require('object-keys');
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
var toStr = Object.prototype.toString;
var concat = Array.prototype.concat;
var defineDataProperty = require('define-data-property');
var isFunction = function (fn) {
return typeof fn === 'function' && toStr.call(fn) === '[object Function]';
};
var supportsDescriptors = require('has-property-descriptors')();
var defineProperty = function (object, name, value, predicate) {
if (name in object) {
if (predicate === true) {
if (object[name] === value) {
return;
}
} else if (!isFunction(predicate) || !predicate()) {
return;
}
}
if (supportsDescriptors) {
defineDataProperty(object, name, value, true);
} else {
defineDataProperty(object, name, value);
}
};
var defineProperties = function (object, map) {
var predicates = arguments.length > 2 ? arguments[2] : {};
var props = keys(map);
if (hasSymbols) {
props = concat.call(props, Object.getOwnPropertySymbols(map));
}
for (var i = 0; i < props.length; i += 1) {
defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
}
};
defineProperties.supportsDescriptors = !!supportsDescriptors;
module.exports = defineProperties;
define-properties-1.2.1/package.json 0000664 0000000 0000000 00000004351 14500250401 0017417 0 ustar 00root root 0000000 0000000 {
"name": "define-properties",
"version": "1.2.1",
"author": "Jordan Harband ",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"description": "Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines.",
"license": "MIT",
"main": "index.js",
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"pretest": "npm run lint",
"test": "npm run tests-only",
"posttest": "aud --production",
"tests-only": "nyc tape 'test/**/*.js'",
"lint": "eslint --ext=js,mjs .",
"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://github.com/ljharb/define-properties.git"
},
"keywords": [
"Object.defineProperty",
"Object.defineProperties",
"object",
"property descriptor",
"descriptor",
"define",
"ES5"
],
"dependencies": {
"define-data-property": "^1.0.1",
"has-property-descriptors": "^1.0.0",
"object-keys": "^1.1.1"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.1.0",
"aud": "^2.0.3",
"auto-changelog": "^2.4.0",
"eslint": "=8.8.0",
"in-publish": "^2.0.1",
"npmignore": "^0.3.0",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.6.6"
},
"testling": {
"files": "test/index.js",
"browsers": [
"iexplore/6.0..latest",
"firefox/3.0..6.0",
"firefox/15.0..latest",
"firefox/nightly",
"chrome/4.0..10.0",
"chrome/20.0..latest",
"chrome/canary",
"opera/10.0..latest",
"opera/next",
"safari/4.0..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"android-browser/4.2"
]
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true,
"startingVersion": "1.1.5"
},
"publishConfig": {
"ignore": [
".github/workflows",
"test/"
]
}
}
define-properties-1.2.1/test/ 0000775 0000000 0000000 00000000000 14500250401 0016105 5 ustar 00root root 0000000 0000000 define-properties-1.2.1/test/index.js 0000664 0000000 0000000 00000007424 14500250401 0017561 0 ustar 00root root 0000000 0000000 'use strict';
var define = require('../');
var test = require('tape');
var keys = require('object-keys');
var arePropertyDescriptorsSupported = function () {
var obj = { a: 1 };
try {
Object.defineProperty(obj, 'x', { value: obj });
return obj.x === obj;
} catch (e) { /* this is IE 8. */
return false;
}
};
var descriptorsSupported = !!Object.defineProperty && arePropertyDescriptorsSupported();
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
test('defineProperties', function (dt) {
dt.test('with descriptor support', { skip: !descriptorsSupported }, function (t) {
var getDescriptor = function (value) {
return {
configurable: true,
enumerable: false,
value: value,
writable: true
};
};
var obj = {
a: 1,
b: 2,
c: 3
};
t.deepEqual(keys(obj), ['a', 'b', 'c'], 'all literal-set keys start enumerable');
define(obj, {
b: 3,
c: 4,
d: 5
});
t.deepEqual(
obj,
{
a: 1,
b: 2,
c: 3
},
'existing properties were not overridden'
);
t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'd'), getDescriptor(5), 'new property "d" was added and is not enumerable');
t.deepEqual(['a', 'b', 'c'], keys(obj), 'new keys are not enumerable');
define(
obj,
{
a: 2,
b: 3,
c: 4
},
{
a: function () { return true; },
b: function () { return false; }
}
);
t.deepEqual(
obj,
{
b: 2,
c: 3
},
'properties only overriden when predicate exists and returns true'
);
t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'd'), getDescriptor(5), 'existing property "d" remained and is not enumerable');
t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'a'), getDescriptor(2), 'existing property "a" was overridden and is not enumerable');
t.deepEqual(['b', 'c'], keys(obj), 'overridden keys are not enumerable');
define(
obj,
{
a: 4,
b: 3,
c: 3
},
{
a: true,
b: true,
c: true
}
);
t.deepEqual(
obj,
{ c: 3 },
'properties overriden when predicate is `true` and ==='
);
t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'a'), getDescriptor(4), 'existing property "a" was overridden and is not enumerable');
t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'b'), getDescriptor(3), 'existing property "b" was overridden and is not enumerable');
t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'd'), getDescriptor(5), 'existing property "d" remained and is not enumerable');
t.deepEqual(['c'], keys(obj), 'overridden keys are not enumerable');
t.end();
});
dt.test('without descriptor support', { skip: descriptorsSupported }, function (t) {
var obj = {
a: 1,
b: 2,
c: 3
};
define(obj, {
b: 3,
c: 4,
d: 5
});
t.deepEqual(
obj,
{
a: 1,
b: 2,
c: 3,
d: 5
},
'existing properties were not overridden, new properties were added'
);
define(
obj,
{
a: 2,
b: 3,
c: 4
},
{
a: function () { return true; },
b: function () { return false; }
}
);
t.deepEqual(
obj,
{
a: 2,
b: 2,
c: 3,
d: 5
},
'properties only overriden when predicate exists and returns true'
);
t.end();
});
dt.end();
});
test('symbols', { skip: !hasSymbols }, function (t) {
var sym = Symbol('foo');
var obj = {};
var aValue = {};
var bValue = {};
var properties = { a: aValue };
properties[sym] = bValue;
define(obj, properties);
t.deepEqual(Object.keys(obj), [], 'object has no enumerable keys');
t.deepEqual(Object.getOwnPropertyNames(obj), ['a'], 'object has non-enumerable "a" key');
t.deepEqual(Object.getOwnPropertySymbols(obj), [sym], 'object has non-enumerable symbol key');
t.equal(obj.a, aValue, 'string keyed value is defined');
t.equal(obj[sym], bValue, 'symbol keyed value is defined');
t.end();
});