diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 90c932f..ae06c40 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -76,8 +76,6 @@ rules: - error - props: true - no-prototype-builtins: warn - # https://eslint.org/docs/rules/no-return-assign no-return-assign: error diff --git a/src/Stream.js b/src/Stream.js index 83cccdb..4163b72 100644 --- a/src/Stream.js +++ b/src/Stream.js @@ -1,5 +1,5 @@ import * as messages from './messages'; -import { base64URLEncode, getLDHeaders } from './utils'; +import { base64URLEncode, getLDHeaders, objectHasOwnProperty } from './utils'; // The underlying event source implementation is abstracted via the platform object, which should // have these three properties: @@ -109,7 +109,7 @@ export default function Stream(platform, config, environment, diagnosticsAccumul es = platform.eventSourceFactory(url, options); for (const key in handlers) { - if (handlers.hasOwnProperty(key)) { + if (objectHasOwnProperty(handlers, key)) { es.addEventListener(key, handlers[key]); } } diff --git a/src/index.js b/src/index.js index de45825..8d07fe9 100644 --- a/src/index.js +++ b/src/index.js @@ -258,7 +258,7 @@ export function initialize(env, user, specifiedOptions, platform, extraOptionDef function variationDetailInternal(key, defaultValue, sendEvent, includeReasonInEvent) { let detail; - if (flags && flags.hasOwnProperty(key) && flags[key] && !flags[key].deleted) { + if (flags && utils.objectHasOwnProperty(flags, key) && flags[key] && !flags[key].deleted) { const flag = flags[key]; detail = getFlagDetail(flag); if (flag.value === null || flag.value === undefined) { @@ -294,7 +294,7 @@ export function initialize(env, user, specifiedOptions, platform, extraOptionDef } for (const key in flags) { - if (flags.hasOwnProperty(key)) { + if (utils.objectHasOwnProperty(flags, key)) { results[key] = variationDetailInternal(key, null, !options.sendEventsOnlyForVariation).value; } } @@ -407,7 +407,7 @@ export function initialize(env, user, specifiedOptions, platform, extraOptionDef } for (const key in flags) { - if (flags.hasOwnProperty(key) && flags[key]) { + if (utils.objectHasOwnProperty(flags, key) && flags[key]) { if (newFlags[key] && !utils.deepEquals(newFlags[key].value, flags[key].value)) { changes[key] = { previous: flags[key].value, current: getFlagDetail(newFlags[key]) }; } else if (!newFlags[key] || newFlags[key].deleted) { @@ -416,7 +416,7 @@ export function initialize(env, user, specifiedOptions, platform, extraOptionDef } } for (const key in newFlags) { - if (newFlags.hasOwnProperty(key) && newFlags[key] && (!flags[key] || flags[key].deleted)) { + if (utils.objectHasOwnProperty(newFlags, key) && newFlags[key] && (!flags[key] || flags[key].deleted)) { changes[key] = { current: getFlagDetail(newFlags[key]) }; } } diff --git a/src/utils.js b/src/utils.js index e9189f0..37f6b1a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -85,7 +85,7 @@ export function wrapPromiseCallback(promise, callback) { export function transformValuesToVersionedValues(flags) { const ret = {}; for (const key in flags) { - if (flags.hasOwnProperty(key)) { + if (objectHasOwnProperty(flags, key)) { ret[key] = { value: flags[key], version: 0 }; } } @@ -98,7 +98,7 @@ export function transformValuesToVersionedValues(flags) { export function transformVersionedValuesToValues(flagsState) { const ret = {}; for (const key in flagsState) { - if (flagsState.hasOwnProperty(key)) { + if (objectHasOwnProperty(flagsState, key)) { ret[key] = flagsState[key].value; } } @@ -169,6 +169,10 @@ export function extend(...objects) { return objects.reduce((acc, obj) => ({ ...acc, ...obj }), {}); } +export function objectHasOwnProperty(object, name) { + return Object.prototype.hasOwnProperty.call(object, name); +} + export function sanitizeUser(user) { if (!user) { return user;