Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation, tests, readme, types
- Loading branch information
Showing
17 changed files
with
360 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"root": true, | ||
|
||
"extends": "@ljharb", | ||
|
||
"rules": { | ||
"new-cap": ["error", { | ||
"capIsNewExceptions": [ | ||
"GetIntrinsic", | ||
], | ||
}], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# 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/es-define-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 a single custom sponsorship URL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: 'Tests: node.js < 10' | ||
|
||
on: [pull_request, push] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/node.yml@main | ||
with: | ||
range: '< 10' | ||
type: minors | ||
command: npm run tests-only | ||
skip-ls-check: true | ||
|
||
node: | ||
name: 'node < 10' | ||
needs: [tests] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: 'Tests: pretest/posttest' | ||
|
||
on: [pull_request, push] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/pretest.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: 'Tests: node.js >= 10' | ||
|
||
on: [pull_request, push] | ||
|
||
permissions: | ||
contents: read | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Automatic Rebase | ||
|
||
on: [pull_request_target] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
_: | ||
permissions: | ||
contents: write # for ljharb/rebase to push code to rebase | ||
pull-requests: read # for ljharb/rebase to get info about PR | ||
|
||
name: "Automatic Rebase" | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ljharb/rebase@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Require “Allow Edits” | ||
|
||
on: [pull_request_target] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
_: | ||
permissions: | ||
pull-requests: read # for ljharb/require-allow-edits to check 'allow edits' on PR | ||
|
||
name: "Require “Allow Edits”" | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: ljharb/require-allow-edits@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,5 @@ dist | |
npm-shrinkwrap.json | ||
package-lock.json | ||
yarn.lock | ||
|
||
.npmignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
package-lock=false | ||
allow-same-version=true | ||
message=v%s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"all": true, | ||
"check-coverage": false, | ||
"reporter": ["text-summary", "text", "html", "json"], | ||
"exclude": [ | ||
"coverage", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# 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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,49 @@ | ||
# es-define-property | ||
# es-define-property <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
|
||
[![github actions][actions-image]][actions-url] | ||
[![coverage][codecov-image]][codecov-url] | ||
[![License][license-image]][license-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
|
||
[![npm badge][npm-badge-png]][package-url] | ||
|
||
`Object.defineProperty`, but not IE 8's broken one. | ||
|
||
## Example | ||
|
||
```js | ||
const assert = require('assert'); | ||
|
||
const $defineProperty = require('es-define-property'); | ||
|
||
if ($defineProperty) { | ||
assert.equal($defineProperty, Object.defineProperty); | ||
} else if (Object.defineProperty) { | ||
assert.equal($defineProperty, false, 'this is IE 8'); | ||
} else { | ||
assert.equal($defineProperty, false, 'this is an ES3 engine'); | ||
} | ||
``` | ||
|
||
## Tests | ||
Simply clone the repo, `npm install`, and run `npm test` | ||
|
||
## Security | ||
|
||
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report. | ||
|
||
[package-url]: https://npmjs.org/package/es-define-property | ||
[npm-version-svg]: https://versionbadg.es/ljharb/es-define-property.svg | ||
[deps-svg]: https://david-dm.org/ljharb/es-define-property.svg | ||
[deps-url]: https://david-dm.org/ljharb/es-define-property | ||
[dev-deps-svg]: https://david-dm.org/ljharb/es-define-property/dev-status.svg | ||
[dev-deps-url]: https://david-dm.org/ljharb/es-define-property#info=devDependencies | ||
[npm-badge-png]: https://nodei.co/npm/es-define-property.png?downloads=true&stars=true | ||
[license-image]: https://img.shields.io/npm/l/es-define-property.svg | ||
[license-url]: LICENSE | ||
[downloads-image]: https://img.shields.io/npm/dm/es-define-property.svg | ||
[downloads-url]: https://npm-stat.com/charts.html?package=es-define-property | ||
[codecov-image]: https://codecov.io/gh/ljharb/es-define-property/branch/main/graphs/badge.svg | ||
[codecov-url]: https://app.codecov.io/gh/ljharb/es-define-property/ | ||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/es-define-property | ||
[actions-url]: https://github.com/ljharb/es-define-property/actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare const defineProperty: false | typeof Object.defineProperty; | ||
|
||
export = defineProperty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
var GetIntrinsic = require('get-intrinsic'); | ||
|
||
/** @type {import('.')} */ | ||
var $defineProperty = GetIntrinsic('%Object.defineProperty%', true) || false; | ||
if ($defineProperty) { | ||
try { | ||
$defineProperty({}, 'a', { value: 1 }); | ||
} catch (e) { | ||
// IE 8 has a broken defineProperty | ||
$defineProperty = false; | ||
} | ||
} | ||
|
||
module.exports = $defineProperty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
var $defineProperty = require('../'); | ||
|
||
var test = require('tape'); | ||
var gOPD = require('gopd'); | ||
|
||
test('defineProperty: supported', { skip: !$defineProperty }, function (t) { | ||
t.plan(4); | ||
|
||
t.equal(typeof $defineProperty, 'function', 'defineProperty is supported'); | ||
if ($defineProperty && gOPD) { // this `if` check is just to shut TS up | ||
var o = { a: 1 }; | ||
|
||
$defineProperty(o, 'b', { enumerable: true, value: 2 }); | ||
t.deepEqual( | ||
gOPD(o, 'b'), | ||
{ | ||
configurable: false, | ||
enumerable: true, | ||
value: 2, | ||
writable: false | ||
}, | ||
'property descriptor is as expected' | ||
); | ||
|
||
$defineProperty(o, 'c', { enumerable: false, value: 3, writable: true }); | ||
t.deepEqual( | ||
gOPD(o, 'c'), | ||
{ | ||
configurable: false, | ||
enumerable: false, | ||
value: 3, | ||
writable: true | ||
}, | ||
'property descriptor is as expected' | ||
); | ||
} | ||
|
||
t.equal($defineProperty, Object.defineProperty, 'defineProperty is Object.defineProperty'); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('defineProperty: not supported', { skip: !!$defineProperty }, function (t) { | ||
t.notOk($defineProperty, 'defineProperty is not supported'); | ||
|
||
t.match( | ||
typeof $defineProperty, | ||
/^(?:undefined|boolean)$/, | ||
'`typeof defineProperty` is `undefined` or `boolean`' | ||
); | ||
|
||
t.end(); | ||
}); |
Oops, something went wrong.