Skip to content

Commit

Permalink
Merge pull request #3044 from egorFiNE/fix_null_and_undefined
Browse files Browse the repository at this point in the history
Exchange: support null as undefined
  • Loading branch information
kroitor committed Jun 5, 2018
2 parents b69335b + eb34b9a commit 8252bb5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions js/base/Exchange.js
Expand Up @@ -956,25 +956,25 @@ module.exports = class Exchange {
}

filterBySinceLimit (array, since = undefined, limit = undefined) {
if (typeof since !== 'undefined')
if (typeof since !== 'undefined' && since !== null)
array = array.filter (entry => entry.timestamp >= since)
if (typeof limit !== 'undefined')
if (typeof limit !== 'undefined' && limit !== null)
array = array.slice (0, limit)
return array
}

filterBySymbolSinceLimit (array, symbol = undefined, since = undefined, limit = undefined) {

const symbolIsDefined = typeof symbol !== 'undefined'
const sinceIsDefined = typeof since !== 'undefined'
const symbolIsDefined = typeof symbol !== 'undefined' && symbol !== null
const sinceIsDefined = typeof since !== 'undefined' && since !== null

// single-pass filter for both symbol and since
if (symbolIsDefined || sinceIsDefined)
array = Object.values (array).filter (entry =>
((symbolIsDefined ? (entry.symbol === symbol) : true) &&
(sinceIsDefined ? (entry.timestamp >= since) : true)))

if (typeof limit !== 'undefined')
if (typeof limit !== 'undefined' && limit !== null)
array = Object.values (array).slice (0, limit)

return array
Expand All @@ -985,7 +985,7 @@ module.exports = class Exchange {
objects = Object.values (objects)

// return all of them if no values were passed
if (typeof values === 'undefined')
if (typeof values === 'undefined' || values === null)
return indexed ? indexBy (objects, key) : objects

let result = []
Expand Down

0 comments on commit 8252bb5

Please sign in to comment.