{"id":22021564,"url":"https://github.com/lamansky/is-instance-of","last_synced_at":"2025-05-07T06:41:25.019Z","repository":{"id":46193597,"uuid":"121562402","full_name":"lamansky/is-instance-of","owner":"lamansky","description":"[Node.js] Like instanceof, but uses class name strings.","archived":false,"fork":false,"pushed_at":"2021-11-08T11:44:02.000Z","size":6,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T07:22:03.446Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/lamansky.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-14T21:18:36.000Z","updated_at":"2023-05-26T02:09:10.000Z","dependencies_parsed_at":"2022-09-26T18:31:36.055Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/is-instance-of","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fis-instance-of","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fis-instance-of/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fis-instance-of/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fis-instance-of/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/is-instance-of/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252830582,"owners_count":21810771,"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":[],"created_at":"2024-11-30T06:12:56.527Z","updated_at":"2025-05-07T06:41:24.971Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# is-instance-of\n\nLike [`instanceof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof), but uses class name strings. This means the module works cross-frame, [unlike `instanceof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof$revision/1351859#instanceof_and_multiple_context_%28e.g._frames_or_windows%29).\n\n## Installation\n\nRequires [Node.js](https://nodejs.org/) 6.0.0 or above.\n\n```bash\nnpm i is-instance-of\n```\n\n## API\n\nThe module exports a single function.\n\n### Parameters\n\n1. Bindable: `x` (object): The object that may or may not be an instance of the specified class(es).\n2. `classes` (function, string, or array of functions/strings): Class names to look for in `x`’s prototype chain. (If one or more functions are provided, their names will be used, so that the check works cross-realm.)\n3. Object argument:\n    * Optional: `ci` (boolean): If `true`, class names will be compared case-insensitively. Defaults to `false`.\n\n### Return Value\n\n* `true` if `x` has any one of the `classes` in its prototype chain.\n* `false` otherwise.\n\n## Examples\n\n```javascript\nconst isInstanceOf = require('is-instance-of')\n\nisInstanceOf(new Date(), 'Date') // true\nisInstanceOf(new Date(), Date) // true\n\n// Case sensitivity / insensitivity\nisInstanceOf(new Date(), 'date') // false\nisInstanceOf(new Date(), 'date', {ci: true}) // true\n\n// Only one class name needs to be matched for true to be returned\nisInstanceOf(new Error(), ['Error', 'Date', RegExp]) // true\n\n// Supports the bind operator\n[]::isInstanceOf('Array') // true\n```\n\n## Nota Bene\n\nThis module’s strength is also its weakness. The module will consider `Date` in one frame/context to be equivalent to `Date` in another context, so long as they have the same name. The advantage of this approach is that this allows for cross-frame type checks. The disadvantage is that `Date` could be a completely different class in the other context and this module wouldn’t know the difference.\n\n## Related\n\n* [class-chain](https://github.com/lamansky/class-chain): Returns an object’s class and its ancestors.\n* [isit](https://github.com/lamansky/isit): Tests a value’s type against a string like `'positive integer'` or `'non-empty map'`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fis-instance-of","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Fis-instance-of","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fis-instance-of/lists"}