(data)
| 27 | } |
| 28 | |
| 29 | function stringify(data) { |
| 30 | if (data === null) return null; |
| 31 | |
| 32 | if (!Array.isArray(data)) throw new Error('range must be an array'); |
| 33 | if (!data.length) return 'empty'; |
| 34 | if (data.length !== 2) throw new Error('range array length must be 0 (empty) or 2 (lower and upper bounds)'); |
| 35 | |
| 36 | if (Object.prototype.hasOwnProperty.call(data, 'inclusive')) { |
| 37 | if (data.inclusive === false) data.inclusive = [false, false]; |
| 38 | else if (!data.inclusive) data.inclusive = [true, false]; |
| 39 | else if (data.inclusive === true) data.inclusive = [true, true]; |
| 40 | } else { |
| 41 | data.inclusive = [true, false]; |
| 42 | } |
| 43 | |
| 44 | _.each(data, (value, index) => { |
| 45 | if (_.isObject(value)) { |
| 46 | if (Object.prototype.hasOwnProperty.call(value, 'inclusive')) data.inclusive[index] = !!value.inclusive; |
| 47 | if (Object.prototype.hasOwnProperty.call(value, 'value')) data[index] = value.value; |
| 48 | } |
| 49 | }); |
| 50 | |
| 51 | const lowerBound = stringifyRangeBound(data[0]); |
| 52 | const upperBound = stringifyRangeBound(data[1]); |
| 53 | |
| 54 | return `${(data.inclusive[0] ? '[' : '(') + lowerBound},${upperBound}${data.inclusive[1] ? ']' : ')'}`; |
| 55 | } |
| 56 | exports.stringify = stringify; |
| 57 | |
| 58 | function parse(value, parser) { |
no test coverage detected