Socket
Socket
Sign inDemoInstall

object.hasown

Package Overview
Dependencies
65
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    object.hasown

ES spec-compliant shim for Object.hasOwn


Version published
Weekly downloads
15M
decreased by-1.55%
Maintainers
1
Install size
3.59 MB
Created
Weekly downloads
 

Package description

What is object.hasown?

The object.hasown npm package is a polyfill for the `Object.hasOwn` method, which is a standardized way of checking if an object has a property as its own (not inherited from its prototype chain). This package provides a reliable way to perform this check across different JavaScript environments, including those that do not support the `Object.hasOwn` method natively.

What are object.hasown's main functionalities?

Checking for own property

This feature allows you to check if an object has a specific property as its own. The code sample demonstrates checking for the existence of properties 'a' and 'b' on an object.

const hasOwn = require('object.hasown');
const object = { a: 1 };
const hasA = hasOwn(object, 'a'); // true
const hasB = hasOwn(object, 'b'); // false

Other packages similar to object.hasown

Changelog

Source

v1.1.4 - 2024-03-22

Commits

  • [meta] remove useless ESM 28440a5
  • [actions] remove redundant finisher 579b54d
  • [Deps] update es-abstract f7f9aa1
  • [Dev Deps] update call-bind, npmignore, tape 8a2f213
  • [Refactor] use es-object-atoms instead of es-abstract f0efe3b
  • [Dev Deps] update call-bind, tape 683b500
  • [Deps] update define-properties, es-abstract f74ecf2
  • [meta] add missing engines.node 7ca6eeb
  • [Deps] update es-abstract d5aa232
  • [Dev Deps] update aud 26fa7f9

Readme

Source

object.hasown Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

An ES spec-compliant Object.hasOwn shim. Invoke its "shim" method to shim Object.hasOwn if it is unavailable or noncompliant.

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec.

Most common usage:

var assert = require('assert');
var hasOwn = require('object.hasown');

var obj = { a: 1, b: 2 };

assert(hasOwn(obj, 'a'));
assert(hasOwn(obj, 'b'));
assert('toString' in obj && !hasOwn(obj, 'toString'));

if (!Object.hasOwn) {
	hasOwn.shim();
}

assert.deepEqual(Object.hasOwn(obj, 'a'), hasOwn(obj, 'a'));

Tests

Simply clone the repo, npm install, and run npm test

Keywords

FAQs

Last updated on 22 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc