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

Remove duplicate hasProperty function #1275

Merged
merged 1 commit into from
Apr 26, 2023
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
10 changes: 0 additions & 10 deletions packages/controller-utils/src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,16 +525,6 @@ describe('util', () => {
});
});

describe('hasProperty', () => {
it('returns false for non existing properties', () => {
expect(util.hasProperty({ foo: 'bar' }, 'property')).toBe(false);
});

it('returns true for existing properties', () => {
expect(util.hasProperty({ foo: 'bar' }, 'foo')).toBe(true);
});
});

describe('isNonEmptyArray', () => {
it('returns false non arrays', () => {
// @ts-expect-error Invalid type for testing purposes
Expand Down
5 changes: 0 additions & 5 deletions packages/controller-utils/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,6 @@ export function isPlainObject(value: unknown): value is PlainObject {
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
}

export const hasProperty = (
object: PlainObject,
key: string | number | symbol,
) => Reflect.hasOwnProperty.call(object, key);

/**
* Like {@link Array}, but always non-empty.
*
Expand Down
3 changes: 1 addition & 2 deletions packages/ens-controller/src/EnsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import {
ExternalProvider,
JsonRpcFetchFunc,
} from '@ethersproject/providers';
import { createProjectLogger } from '@metamask/utils';
import { createProjectLogger, hasProperty } from '@metamask/utils';
import {
normalizeEnsName,
isValidHexAddress,
toChecksumHexAddress,
NETWORK_ID_TO_ETHERS_NETWORK_NAME_MAP,
convertHexToDecimal,
hasProperty,
} from '@metamask/controller-utils';
import { toASCII } from 'punycode/';
import ensNetworkMap from 'ethereum-ens-network-map';
Expand Down
2 changes: 1 addition & 1 deletion packages/notification-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@metamask/base-controller": "workspace:^",
"@metamask/controller-utils": "workspace:^",
"@metamask/utils": "^5.0.2",
"immer": "^9.0.6",
"nanoid": "^3.1.31"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Patch } from 'immer';
import { nanoid } from 'nanoid';
import { hasProperty } from '@metamask/controller-utils';
import { hasProperty } from '@metamask/utils';
import {
BaseControllerV2,
RestrictedControllerMessenger,
Expand Down
1 change: 1 addition & 0 deletions packages/permission-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@metamask/base-controller": "workspace:^",
"@metamask/controller-utils": "workspace:^",
"@metamask/types": "^1.1.0",
"@metamask/utils": "^5.0.2",
"@types/deep-freeze-strict": "^1.1.0",
"deep-freeze-strict": "^1.1.1",
"eth-rpc-errors": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/permission-controller/src/Caveat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Json } from '@metamask/types';
import { hasProperty } from '@metamask/controller-utils';
import { hasProperty } from '@metamask/utils';
import {
CaveatSpecificationMismatchError,
UnrecognizedCaveatTypeError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
RejectRequest as RejectApprovalRequest,
} from '@metamask/approval-controller';
import { ControllerMessenger } from '@metamask/base-controller';
import { Json, hasProperty, isPlainObject } from '@metamask/controller-utils';
import { hasProperty } from '@metamask/utils';
import { Json, isPlainObject } from '@metamask/controller-utils';
import { GetSubjectMetadata, SubjectType } from './SubjectMetadataController';
import * as errors from './errors';
import { EndowmentGetterParams } from './Permission';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import deepFreeze from 'deep-freeze-strict';
import { castDraft, Draft, Patch } from 'immer';
import { nanoid } from 'nanoid';
import { EthereumRpcError } from 'eth-rpc-errors';
import { hasProperty } from '@metamask/utils';
import {
AcceptRequest as AcceptApprovalRequest,
AddApprovalRequest,
Expand All @@ -18,7 +19,6 @@ import {
EventConstraint,
} from '@metamask/base-controller';
import {
hasProperty,
isNonEmptyArray,
isPlainObject,
isValidJson,
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ __metadata:
dependencies:
"@metamask/auto-changelog": ^3.1.0
"@metamask/base-controller": "workspace:^"
"@metamask/controller-utils": "workspace:^"
"@metamask/utils": ^5.0.2
"@types/jest": ^27.4.1
deepmerge: ^4.2.2
immer: ^9.0.6
Expand Down Expand Up @@ -1807,6 +1807,7 @@ __metadata:
"@metamask/base-controller": "workspace:^"
"@metamask/controller-utils": "workspace:^"
"@metamask/types": ^1.1.0
"@metamask/utils": ^5.0.2
"@types/deep-freeze-strict": ^1.1.0
"@types/jest": ^27.4.1
deep-freeze-strict: ^1.1.1
Expand Down