Skip to content

Commit

Permalink
[readme] use evalmd
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 26, 2023
1 parent 8178901 commit 7648a08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
43 changes: 16 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $ npm i is-data-descriptor --save

```js
var isDataDesc = require('is-data-descriptor');
var assert = require('assert');
```

## Examples
Expand All @@ -22,45 +23,34 @@ var isDataDesc = require('is-data-descriptor');

```js
// `value` can be anything
isDataDesc({value: 'foo'})
isDataDesc({value: function() {}})
isDataDesc({value: true})
//=> true
assert.equal(isDataDesc({ value: 'foo' }), true);
assert.equal(isDataDesc({ value() {} }), true);
assert.equal(isDataDesc({ value: true }), true);
```

`false` when not an object

```js
isDataDesc('a')
//=> false
isDataDesc(null)
//=> false
isDataDesc([])
//=> false
assert.equal(isDataDesc('a'), false);
assert.equal(isDataDesc(null), false);
assert.equal(isDataDesc([]), false);
```

`false` when the object has invalid properties

```js
isDataDesc({value: 'foo', bar: 'baz'})
//=> false
isDataDesc({value: 'foo', bar: 'baz'})
//=> false
isDataDesc({value: 'foo', get: function(){}})
//=> false
isDataDesc({get: function(){}, value: 'foo'})
//=> false
assert.equal(isDataDesc({ value: 'foo', bar: 'baz' }), false);
assert.equal(isDataDesc({ value: 'foo', bar: 'baz' }), false);
assert.equal(isDataDesc({ value: 'foo', get() {} }), false);
assert.equal(isDataDesc({ get() {}, value: 'foo' }), false);
```

`false` when a value is not the correct type

```js
isDataDesc({value: 'foo', enumerable: 'foo'})
//=> false
isDataDesc({value: 'foo', configurable: 'foo'})
//=> false
isDataDesc({value: 'foo', writable: 'foo'})
//=> false
assert.equal(isDataDesc({ value: 'foo', enumerable: 'foo' }), false);
assert.equal(isDataDesc({ value: 'foo', configurable: 'foo' }), false);
assert.equal(isDataDesc({ value: 'foo', writable: 'foo' }), false);
```

## Valid properties
Expand All @@ -84,13 +74,12 @@ var foo = {};
Object.defineProperty(foo, 'bar', {
enumerable: true,
whatever: 'blah', // invalid, but doesn't cause an error
get: function() {
get() {
return 'baz';
}
});

console.log(foo.bar);
//=> 'baz'
assert.equal(foo.bar, 'baz');
```

## Related projects
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"node": ">=0.10.0"
},
"scripts": {
"prelint": "evalmd README.md",
"lint": "eslint --ext=js,mjs .",
"pretest": "npm run lint",
"tests-only": "nyc tape 'test/**/*.js'",
Expand All @@ -30,6 +31,7 @@
"@ljharb/eslint-config": "^21.1.0",
"aud": "^2.0.3",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"nyc": "^10.3.2",
"tape": "^5.7.2"
},
Expand Down

0 comments on commit 7648a08

Please sign in to comment.