Git Product home page Git Product logo

isobject's Introduction

isobject NPM version NPM monthly downloads NPM total downloads Linux Build Status

Returns true if the value is an object and not an array or null.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.

Install

Install with npm:

$ npm install --save isobject

Use is-plain-object if you want only objects that are created by the Object constructor.

Install

Install with npm:

$ npm install isobject

Usage

import isObject from 'isobject';

True

All of the following return true:

isObject({});
isObject(Object.create({}));
isObject(Object.create(Object.prototype));
isObject(Object.create(null));
isObject({});
isObject(new Foo);
isObject(/foo/);

False

All of the following return false:

isObject();
isObject(function () {});
isObject(1);
isObject([]);
isObject(undefined);
isObject(null);

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

Contributors

Commits Contributor
30 jonschlinkert
8 doowb
7 TrySound
3 onokumus
1 LeSuisse
1 tmcw
1 ZhouHansen

Author

Jon Schlinkert

License

Copyright © 2019, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on April 28, 2019.

isobject's People

Contributors

doowb avatar jonschlinkert avatar lesuisse avatar mahovich avatar onokumus avatar tmcw avatar trysound avatar zhouhanseng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

isobject's Issues

Implement type predicate

Summary

Currently isObject returns the type boolean, but i think it would improve the package if it returned val is { [key: string]: unknown }.

Current behaviour

const test: { example: "hello" } | string[] = ...;

if(isObject(test)) {
  test.example = "world" // Error since test could be a string array
}

Improved behaviour

const test: { example: "hello" } | string[] = ...;

if(isObject(test)) {
  test.example = "world" // No error 
}

SEMVER publishing

What was the reason for 3.0.1 major bump to 4.0.0?

I don't see release changelog or a CHANGELOG.md in the repo that explains any BREAKING CHANGES which would help explain the version changes.

Perhaps https://www.npmjs.com/package/commitizen would be a benefit to this lib :-)

No lock file found in the isobject project on Tag: 4.0.0

Issue: There is no package-lock.json or npm-shrinkwrap.json file uploaded to the GitHub repository https://github.com/jonschlinkert/isobject

Questions: We are conducting a research study on the lock files used in JS projects. We were curious:

  1. Will you upload any lock files to GitHub as recommended above? (Yes/No), and why?:
  2. Do you have any additional comments? (If so, please write it down):

For any publication or research report based on this study, we will share all responses from developers in an anonymous way. Both your projects and personal information will be kept confidential.

Rationale: NPM introduced package-lock.json and npm-shrimpwrap.json files to capture the exact dependency tree installed at any point in time. When package.json defines the required dependencies and their respective versions using semantic versioning (e.g., “express”: “^4.16.4”), npm always downloads the latest version of packages to satisfy the specified version ranges (e.g., 4.17.1)[1]. If the latest version of any package keeps changing and has backward incompatibility issues with previous versions, the project may have an inconsistent running environment and get intermittent failures. In such scenarios, it can be very difficult for developers to debug programs and settle down the software environment [2].

List of Risks:

  • Nondeterministic package downloads and installations across different environments [3]
  • Produce irreproducible builds [4]
  • Inconsistent results of program execution [5]

Suggested Solution: Please fixate the dependencies by either specifying the exact library version in the package.json file or by uploading the package-lock.json or npm-shrinkwrap.json file to GitHub.

References:
https://docs.npmjs.com/cli/v7/configuring-npm/package-lock-json
https://blog.logrocket.com/why-you-should-use-package-lock-json/
2019. 10 npm Security Best Practices. https://snyk.io/blog/ten-npm-security-best-practices/.
Pronnoy Goswami, Saksham Gupta, Zhiyuan Li, Na Meng, and Daphne Yao. 2020. Investigating The Reproducibility of NPM Packages. In2020 IEEE International
2021. Npm Security Best Practices. https://bytesafe.dev/posts/npm-security-best-practices/#no9-deterministic-results.

suggestion: why Array.isArray(val) === false?

I noticed you are using Array.isArray(val) === false...

return val != null && typeof val === 'object' && Array.isArray(val) === false;

doesn't it make more sense...

return val != null && typeof val === 'object' && !Array.isArray(val);

or even...

return !!val && typeof val === 'object' && !Array.isArray(val);

I noticed you used that way here...
https://github.com/jonschlinkert/use/blob/843c0e1b6934cef9570e7a9962501bf84212c3b5/index.js#L146
It's shorter and imho more descriptive. Just a suggestion though.
Happy to do a pr is needed.
Thanks.

Odd module

So what is the point of this? Test if some value is an "object"?

Are Function objects supposed to pass? Clearly they fail, but the documentation makes no mention of them. Regular expressions welcome, but not arrays? Documenting the intentions may help, but can't imagine this is a useful dependency.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.