Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Aug 31, 2015
0 parents commit a1915ae
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
@@ -0,0 +1,22 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
end_of_line = lf
charset = utf-8
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
insert_final_newline = false

[{,test/}{actual,fixtures}/**]
trim_trailing_whitespace = false
insert_final_newline = false

[templates/**]
trim_trailing_whitespace = false
insert_final_newline = false
10 changes: 10 additions & 0 deletions .gitattributes
@@ -0,0 +1,10 @@
# Enforce Unix newlines
* text eol=lf

# binaries
*.ai binary
*.psd binary
*.jpg binary
*.gif binary
*.png binary
*.jpeg binary
15 changes: 15 additions & 0 deletions .gitignore
@@ -0,0 +1,15 @@
*.DS_Store
*.sublime-*
_gh_pages
bower_components
node_modules
npm-debug.log
actual
test/actual
temp
tmp
TODO.md
vendor
.idea
benchmark
coverage
18 changes: 18 additions & 0 deletions .jshintrc
@@ -0,0 +1,18 @@
{
"asi": false,
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"esnext": true,
"immed": true,
"latedef": false,
"laxcomma": false,
"mocha": true,
"newcap": true,
"noarg": true,
"node": true,
"sub": true,
"undef": true,
"unused": true
}
11 changes: 11 additions & 0 deletions .travis.yml
@@ -0,0 +1,11 @@
sudo: false
language: node_js
node_js:
- "0.10"
- "0.12"
- "0.13"
- "iojs"
matrix:
fast_finish: true
allow_failures:
- node_js: "0.13"
37 changes: 37 additions & 0 deletions .verb.md
@@ -0,0 +1,37 @@
# {%= name %} {%= badge("fury") %}

> {%= description %}
## Install
{%= include("install-npm", {save: true}) %}

## Usage

```js
var isDataDescriptor = require('{%= name %}');
```

## API
<!-- add a path or glob pattern for files with code comments to use for docs -->
{%%= apidocs("index.js") %}

## Related projects
<!-- add an array of related projects, then un-escape the helper -->
{%%= related([]) %}

## Running tests
{%= include("tests") %}

## Contributing
{%= include("contributing") %}

## Author
{%= include("author") %}

## License
{%= copyright() %}
{%= license() %}

***

{%= include("footer") %}
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015, Jon Schlinkert.

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.
57 changes: 57 additions & 0 deletions index.js
@@ -0,0 +1,57 @@
/*!
* is-data-descriptor <https://github.com/jonschlinkert/is-data-descriptor>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/

'use strict';

var diff = require('arr-diff');
var typeOf = require('kind-of');

// data descriptor properties
var data = {
configurable: 'boolean',
enumerable: 'boolean',
writable: 'boolean'
};

function isDataDescriptor(obj) {
if (typeOf(obj) !== 'object') {
return false;
}

var dataKeys = Object.keys(data);
var keys = getKeys(obj);

if (obj.hasOwnProperty('value')) {
if (diff(keys, dataKeys).length !== 1) {
return false;
}
for (var key in obj) {
if (key === 'value') continue;
if (typeOf(obj[key]) !== data[key]) {
return false;
}
}
}
return true;
}

/**
* Get object keys. `Object.keys()` only gets
* enumerable properties.
*/

function getKeys(obj) {
var keys = [];
for (var key in obj) keys.push(key);
return keys;
}

/**
* Expose `isDataDescriptor`
*/

module.exports = isDataDescriptor;
31 changes: 31 additions & 0 deletions package.json
@@ -0,0 +1,31 @@
{
"name": "is-data-descriptor",
"description": "Returns true if a value appears to be a valid JavaScript data descriptor.",
"version": "0.1.0",
"homepage": "https://github.com/jonschlinkert/is-data-descriptor",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/is-data-descriptor",
"bugs": {
"url": "https://github.com/jonschlinkert/is-data-descriptor/issues"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
},
"dependencies": {
"arr-diff": "^1.1.0",
"kind-of": "^2.0.1"
},
"devDependencies": {
"mocha": "*",
"should": "*"
},
"keywords": []
}
37 changes: 37 additions & 0 deletions test.js
@@ -0,0 +1,37 @@
'use strict';

/* deps: mocha */
var assert = require('assert');
var should = require('should');
var isDescriptor = require('./');
var noop = function(){};

describe('isDescriptor', function () {
describe('value type', function () {
it('should be false when not an object:', function () {
assert(!isDescriptor('a'));
assert(!isDescriptor(null));
assert(!isDescriptor([]));
});
});

describe('data descriptor:', function () {
it('should be false when the object has invalid properties:', function () {
assert(!isDescriptor({value: 'foo', bar: 'baz'}));
assert(!isDescriptor({value: 'foo', bar: 'baz'}));
assert(!isDescriptor({value: 'foo', get: noop}));
assert(!isDescriptor({get: noop, value: noop}));
});

it('should be true when the object has valid properties:', function () {
assert(isDescriptor({value: 'foo'}));
assert(isDescriptor({value: noop}));
});

it('should be false when a value is not the correct type:', function () {
assert(!isDescriptor({value: 'foo', enumerable: 'foo'}));
assert(!isDescriptor({value: 'foo', configurable: 'foo'}));
assert(!isDescriptor({value: 'foo', writable: 'foo'}));
});
});
});

0 comments on commit a1915ae

Please sign in to comment.