UNPKG

falcor-router

Version:

A router DataSource constructor for falcor that allows you to model all your cloud data sources as a single JSON resource.

42 lines (33 loc) 828 B
var convertPathKeyTo = require('./../convertPathKeyTo'); var isNumber = require('./../../support/isNumber'); function onRange(out, range) { out[out.length] = range; } /** * @param {Number|String} key must be a number */ function keyReduce(out, key, range) { if (!isNumber(key)) { return range; } /* eslint-disable no-param-reassign */ key = +key; if (range) { if (key - 1 === range.to) { range.to = key; } else if (key + 1 === range.from) { range.from = key; } else { range = null; } } if (!range) { range = {to: key, from: key}; out[out.length] = range; } /* eslint-enable no-param-reassign */ return range; } module.exports = convertPathKeyTo(onRange, keyReduce);