Skip to content

Commit fb9184b

Browse files
committed
fix: compatibility issues on node 14 with Object.hasOwn()
1 parent 66baca6 commit fb9184b

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/targets/php/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const convertType = (obj: any[] | any, indent?: string, lastIndent?: stri
2525
case '[object Object]': {
2626
const result: string[] = [];
2727
for (const i in obj) {
28-
if (Object.hasOwn(obj, i)) {
28+
if (Object.prototype.hasOwnProperty.call(obj, i)) {
2929
result.push(
3030
`${convertType(i, indent)} => ${convertType(obj[i], `${indent}${indent}`, indent)}`,
3131
);

src/targets/targets.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,36 +83,36 @@ export const isTarget = (target: Target): target is Target => {
8383
throw new Error(`you tried to add a target which is not an object, got type: "${got}"`);
8484
}
8585

86-
if (!Object.hasOwn(target, 'info')) {
86+
if (!Object.prototype.hasOwnProperty.call(target, 'info')) {
8787
throw new Error('targets must contain an `info` object');
8888
}
8989

90-
if (!Object.hasOwn(target.info, 'key')) {
90+
if (!Object.prototype.hasOwnProperty.call(target.info, 'key')) {
9191
throw new Error('targets must have an `info` object with the property `key`');
9292
}
9393

9494
if (!target.info.key) {
9595
throw new Error('target key must be a unique string');
9696
}
9797

98-
if (Object.hasOwn(targets, target.info.key)) {
98+
if (Object.prototype.hasOwnProperty.call(targets, target.info.key)) {
9999
throw new Error(`a target already exists with this key, \`${target.info.key}\``);
100100
}
101101

102-
if (!Object.hasOwn(target.info, 'title')) {
102+
if (!Object.prototype.hasOwnProperty.call(target.info, 'title')) {
103103
throw new Error('targets must have an `info` object with the property `title`');
104104
}
105105

106106
if (!target.info.title) {
107107
throw new Error('target title must be a non-zero-length string');
108108
}
109109

110-
if (!Object.hasOwn(target.info, 'extname')) {
110+
if (!Object.prototype.hasOwnProperty.call(target.info, 'extname')) {
111111
throw new Error('targets must have an `info` object with the property `extname`');
112112
}
113113

114114
if (
115-
!Object.hasOwn(target, 'clientsById') ||
115+
!Object.prototype.hasOwnProperty.call(target, 'clientsById') ||
116116
!target.clientsById ||
117117
Object.keys(target.clientsById).length === 0
118118
) {
@@ -121,11 +121,11 @@ export const isTarget = (target: Target): target is Target => {
121121
);
122122
}
123123

124-
if (!Object.hasOwn(target.info, 'default')) {
124+
if (!Object.prototype.hasOwnProperty.call(target.info, 'default')) {
125125
throw new Error('targets must have an `info` object with the property `default`');
126126
}
127127

128-
if (!Object.hasOwn(target.clientsById, target.info.default)) {
128+
if (!Object.prototype.hasOwnProperty.call(target.clientsById, target.info.default)) {
129129
throw new Error(
130130
`target ${target.info.key} is configured with a default client ${
131131
target.info.default
@@ -152,31 +152,31 @@ export const isClient = (client: Client): client is Client => {
152152
throw new Error('clients must be objects');
153153
}
154154

155-
if (!Object.hasOwn(client, 'info')) {
155+
if (!Object.prototype.hasOwnProperty.call(client, 'info')) {
156156
throw new Error('targets client must contain an `info` object');
157157
}
158158

159-
if (!Object.hasOwn(client.info, 'key')) {
159+
if (!Object.prototype.hasOwnProperty.call(client.info, 'key')) {
160160
throw new Error('targets client must have an `info` object with property `key`');
161161
}
162162

163163
if (!client.info.key) {
164164
throw new Error('client.info.key must contain an identifier unique to this target');
165165
}
166166

167-
if (!Object.hasOwn(client.info, 'title')) {
167+
if (!Object.prototype.hasOwnProperty.call(client.info, 'title')) {
168168
throw new Error('targets client must have an `info` object with property `title`');
169169
}
170170

171-
if (!Object.hasOwn(client.info, 'description')) {
171+
if (!Object.prototype.hasOwnProperty.call(client.info, 'description')) {
172172
throw new Error('targets client must have an `info` object with property `description`');
173173
}
174174

175-
if (!Object.hasOwn(client.info, 'link')) {
175+
if (!Object.prototype.hasOwnProperty.call(client.info, 'link')) {
176176
throw new Error('targets client must have an `info` object with property `link`');
177177
}
178178

179-
if (!Object.hasOwn(client, 'convert') || typeof client.convert !== 'function') {
179+
if (!Object.prototype.hasOwnProperty.call(client, 'convert') || typeof client.convert !== 'function') {
180180
throw new Error(
181181
'targets client must have a `convert` property containing a conversion function',
182182
);
@@ -190,11 +190,11 @@ export const addTargetClient = (targetId: TargetId, client: Client) => {
190190
return;
191191
}
192192

193-
if (!Object.hasOwn(targets, targetId)) {
193+
if (!Object.prototype.hasOwnProperty.call(targets, targetId)) {
194194
throw new Error(`Sorry, but no ${targetId} target exists to add clients to`);
195195
}
196196

197-
if (Object.hasOwn(targets[targetId], client.info.key)) {
197+
if (Object.prototype.hasOwnProperty.call(targets[targetId], client.info.key)) {
198198
throw new Error(
199199
`the target ${targetId} already has a client with the key ${client.info.key}, please use a different key`,
200200
);

0 commit comments

Comments
 (0)