Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Node.js 8, add TypeScript definition #3

Merged
merged 1 commit into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
sudo: false
language: node_js
node_js:
- '5'
- '4'
- '0.12'
- '0.10'
- '10'
- '8'
22 changes: 22 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
Check if a value is an object.

Keep in mind that array, function, regexp, etc, are objects in JavaScript.

@example
```
import isObj = require('is-obj');

isObj({foo: 'bar'});
//=> true

isObj([1, 2, 3]);
//=> true

isObj('foo');
//=> false
```
*/
declare function isObj(x: unknown): x is object;

export = isObj;
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
module.exports = function (x) {
var type = typeof x;

module.exports = x => {
const type = typeof x;
return x !== null && (type === 'object' || type === 'function');
};
8 changes: 8 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {expectType} from 'tsd';
import isObj = require('.');

const foo = 'foo';

if (isObj(foo)) {
expectType<object>(foo);
}
20 changes: 4 additions & 16 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

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:
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 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.
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.
64 changes: 33 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
{
"name": "is-obj",
"version": "1.0.1",
"description": "Check if a value is an object",
"license": "MIT",
"repository": "sindresorhus/is-obj",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"obj",
"object",
"is",
"check",
"test",
"type"
],
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "is-obj",
"version": "1.0.1",
"description": "Check if a value is an object",
"license": "MIT",
"repository": "sindresorhus/is-obj",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"obj",
"object",
"is",
"check",
"test",
"type"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ See [`is-plain-obj`](https://github.com/sindresorhus/is-plain-obj) if you want t
## Install

```
$ npm install --save is-obj
$ npm install is-obj
```


Expand Down
46 changes: 24 additions & 22 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import test from 'ava';
import m from './';
import isObj from '.';

test(t => {
t.true(m({}));
t.true(m(new Object())); // eslint-disable-line
t.true(m(new Date()));
t.true(m(new RegExp()));
t.true(m(Object.create(null)));
t.true(m({foo: true}));
t.true(m([]));
t.true(m(['foo', 'bar']));
t.true(m(() => {}));
t.true(m(arguments));
t.true(m(/./));
t.true(m(Object(0)));
t.true(m(Object('foo')));
t.true(m(Object(false)));
t.false(m(null));
t.false(m(undefined));
t.false(m(NaN));
t.false(m(''));
t.false(m(0));
t.false(m(false));
test('main', function (t) {
/* eslint-disable no-new-object */
t.true(isObj({}));
t.true(isObj(new Object()));
t.true(isObj(new Date()));
t.true(isObj(new RegExp()));
t.true(isObj(Object.create(null)));
t.true(isObj({foo: true}));
t.true(isObj([]));
t.true(isObj(['foo', 'bar']));
t.true(isObj(() => {}));
t.true(isObj(arguments)); // eslint-disable-line prefer-rest-params
t.true(isObj(/./));
t.true(isObj(new Object(0)));
t.true(isObj(new Object('foo')));
t.true(isObj(new Object(false)));
t.false(isObj(null));
t.false(isObj(undefined));
t.false(isObj(NaN));
t.false(isObj(''));
t.false(isObj(0));
t.false(isObj(false));
/* eslint-enable no-new-object */
});