{"id":15654090,"url":"https://github.com/jonschlinkert/has-value","last_synced_at":"2026-03-16T11:36:10.597Z","repository":{"id":21017390,"uuid":"24310408","full_name":"jonschlinkert/has-value","owner":"jonschlinkert","description":"Returns true if a value exists, false if empty. Works with deeply nested values using object paths.","archived":false,"fork":false,"pushed_at":"2018-03-03T20:49:13.000Z","size":33,"stargazers_count":26,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-25T00:04:08.124Z","etag":null,"topics":["check","dot-notation","javascript","microlib","object","property","util","value"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-22T01:48:51.000Z","updated_at":"2024-07-23T02:03:56.000Z","dependencies_parsed_at":"2022-09-01T22:41:01.741Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/has-value","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fhas-value","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fhas-value/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fhas-value/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fhas-value/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/has-value/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251801199,"owners_count":21645969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["check","dot-notation","javascript","microlib","object","property","util","value"],"created_at":"2024-10-03T12:49:28.043Z","updated_at":"2026-03-16T11:36:05.549Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","readme":"# has-value [![NPM version](https://img.shields.io/npm/v/has-value.svg?style=flat)](https://www.npmjs.com/package/has-value) [![NPM monthly downloads](https://img.shields.io/npm/dm/has-value.svg?style=flat)](https://npmjs.org/package/has-value) [![NPM total downloads](https://img.shields.io/npm/dt/has-value.svg?style=flat)](https://npmjs.org/package/has-value) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/has-value.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/has-value)\n\n\u003e Returns true if a value exists, false if empty. Works with deeply nested values using object paths.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save has-value\n```\n\n## Heads up!\n\nBreaking changes in v2.0! See the [release history](#release-history) for details.\n\n## Usage\n\n```js\nconst has = require('has-value');\n\nconsole.log(has()) //=\u003e true\nconsole.log(has('foo')) //=\u003e true\n```\n\n**Works for:**\n\n* booleans\n* functions\n* numbers\n* strings\n* nulls\n* object\n* arrays\n\n**isEmpty**\n\nTo do the opposite and test for empty values, do:\n\n```js\nconst isEmpty = (...args) =\u003e !has(...args);\n```\n\n## Supported types\n\n### Arrays\n\n```js\nconsole.log(has({ foo: { bar: ['a'] } }, 'foo.bar'));    //=\u003e true\nconsole.log(has({ foo: { bar: [0] } }, 'foo.bar'));      //=\u003e true\nconsole.log(has({ foo: { bar: [[[]]] } }, 'foo.bar'));   //=\u003e false\nconsole.log(has({ foo: { bar: [[], []] } }, 'foo.bar')); //=\u003e false\nconsole.log(has({ foo: { bar: [] } }, 'foo.bar'));       //=\u003e false\n```\n\n### Booleans\n\n```js\nconsole.log(has({ foo: { bar: true } }, 'foo.bar'));  //=\u003e true\nconsole.log(has({ foo: { bar: false } }, 'foo.bar')); //=\u003e true\n```\n\n### Buffers\n\n```js\nconsole.log(has({ foo: { bar: new Buffer() } }, 'foo.bar'));      //=\u003e false\nconsole.log(has({ foo: { bar: new Buffer('foo') } }, 'foo.bar')); //=\u003e true\n```\n\n### Dates\n\nDates are always true.\n\n```js\nconsole.log(has({ foo: { bar: new Date() } }, 'foo.bar')); //=\u003e true\n```\n\n### Errors\n\nReturns `false` if `err.message` is an empty string.\n\n```js\nconsole.log(has({ foo: { bar: new Error() } }, 'foo.bar'));      //=\u003e false\nconsole.log(has({ foo: { bar: new Error('foo') } }, 'foo.bar')); //=\u003e true\n```\n\n### Functions\n\nFunctions are always true.\n\n```js\nconsole.log(has({ foo: { bar: function(foo) {} } }, 'foo.bar')); //=\u003e true\nconsole.log(has({ foo: { bar: function() {} } }, 'foo.bar'));    //=\u003e true\n```\n\n### Maps\n\n```js\nconsole.log(has({ foo: { bar: new Map() } }, 'foo.bar'));                 //=\u003e false\nconsole.log(has({ foo: { bar: new Map([['foo', 'bar']]) } }, 'foo.bar')); //=\u003e true\n```\n\n### Null\n\n`null` is always true, as it's assumed that this is a user-defined value, versus `undefined` which is not.\n\n```js\nconsole.log(has({ foo: { bar: null } }, 'foo.bar')); //=\u003e true\n```\n\n### Objects\n\n```js\nconsole.log(has({ foo: { bar: {} } }, 'foo.bar')); //=\u003e false\nconsole.log(has({ foo: { bar: { a: 'a' }} } }, 'foo.bar'));        //=\u003e true\nconsole.log(has({ foo: { bar: { foo: undefined } } }, 'foo.bar')); //=\u003e false\nconsole.log(has({ foo: { bar: { foo: null } } }, 'foo.bar'));      //=\u003e true\n```\n\n### Numbers\n\n```js\nconsole.log(has({ foo: { bar: 1 } }, 'foo.bar')); //=\u003e true\nconsole.log(has({ foo: { bar: 0 } }, 'foo.bar')); //=\u003e true\n```\n\n### Regular expressions\n\n```js\nconsole.log(has({ foo: { bar: new RegExp() } }, 'foo.bar'));      //=\u003e false\nconsole.log(has({ foo: { bar: new RegExp('foo') } }, 'foo.bar')); //=\u003e true\n```\n\n### Sets\n\n```js\nconsole.log(has({ foo: { bar: new Set() } }, 'foo.bar'));               //=\u003e false\nconsole.log(has({ foo: { bar: new Set(['foo', 'bar']) } }, 'foo.bar')); //=\u003e true\n```\n\n### Strings\n\n```js\nconsole.log(has({ foo: { bar: 'a' } }, 'foo.bar')); //=\u003e true\nconsole.log(has({ foo: { bar: '' } }, 'foo.bar'));  //=\u003e false\n```\n\n## Undefined\n\n```js\nconsole.log(has({ foo: { bar:  } }, 'foo.bar'));          //=\u003e false\nconsole.log(has({ foo: { bar: void 0 } }, 'foo.bar'));    //=\u003e false\nconsole.log(has({ foo: { bar: undefined } }, 'foo.bar')); //=\u003e false\n```\n\n## Release history\n\n### v2.0.0\n\n**Breaking changes**\n\n* Now returns false if the first argument is not an object, function or array, and the second argument is not a string or array.\n\n### v1.0.0\n\n* `zero` always returns true\n* `array` now recurses, so that an array of empty arrays will return `false`\n* `null` now returns true\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning 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:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [define-property](https://www.npmjs.com/package/define-property): Define a non-enumerable property on an object. Uses Reflect.defineProperty when available, otherwise Object.defineProperty. | [homepage](https://github.com/jonschlinkert/define-property \"Define a non-enumerable property on an object. Uses Reflect.defineProperty when available, otherwise Object.defineProperty.\")\n* [get-value](https://www.npmjs.com/package/get-value): Use property paths like 'a.b.c' to get a nested value from an object. Even works… [more](https://github.com/jonschlinkert/get-value) | [homepage](https://github.com/jonschlinkert/get-value \"Use property paths like 'a.b.c' to get a nested value from an object. Even works when keys have dots in them (no other dot-prop library can do this!).\")\n* [set-value](https://www.npmjs.com/package/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths. | [homepage](https://github.com/jonschlinkert/set-value \"Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.\")\n* [unset-value](https://www.npmjs.com/package/unset-value): Delete nested properties from an object using dot notation. | [homepage](https://github.com/jonschlinkert/unset-value \"Delete nested properties from an object using dot notation.\")\n\n### Contributors\n\n| **Commits** | **Contributor** | \n| --- | --- |\n| 32 | [jonschlinkert](https://github.com/jonschlinkert) |\n| 2 | [rmharrison](https://github.com/rmharrison) |\n| 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |\n\n### Author\n\n**Jon Schlinkert**\n\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on March 03, 2018._","funding_links":[],"categories":["Modules","模块"],"sub_categories":["Object","对象"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fhas-value","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fhas-value","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fhas-value/lists"}