You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
7 lines
3.6 KiB
7 lines
3.6 KiB
{ |
|
"version": 3, |
|
"sources": ["../../../src/dialects/postgres/range.js"], |
|
"sourcesContent": ["'use strict';\n\nconst _ = require('lodash');\n\nfunction stringifyRangeBound(bound) {\n if (bound === null) {\n return '' ;\n }\n if (bound === Infinity || bound === -Infinity) {\n return bound.toString().toLowerCase();\n }\n return JSON.stringify(bound);\n}\n\nfunction parseRangeBound(bound, parseType) {\n if (!bound) {\n return null;\n }\n if (bound === 'infinity') {\n return Infinity;\n }\n if (bound === '-infinity') {\n return -Infinity;\n }\n return parseType(bound);\n\n}\n\nfunction stringify(data) {\n if (data === null) return null;\n\n if (!Array.isArray(data)) throw new Error('range must be an array');\n if (!data.length) return 'empty';\n if (data.length !== 2) throw new Error('range array length must be 0 (empty) or 2 (lower and upper bounds)');\n\n if (Object.prototype.hasOwnProperty.call(data, 'inclusive')) {\n if (data.inclusive === false) data.inclusive = [false, false];\n else if (!data.inclusive) data.inclusive = [true, false];\n else if (data.inclusive === true) data.inclusive = [true, true];\n } else {\n data.inclusive = [true, false];\n }\n\n _.each(data, (value, index) => {\n if (_.isObject(value)) {\n if (Object.prototype.hasOwnProperty.call(value, 'inclusive')) data.inclusive[index] = !!value.inclusive;\n if (Object.prototype.hasOwnProperty.call(value, 'value')) data[index] = value.value;\n }\n });\n\n const lowerBound = stringifyRangeBound(data[0]);\n const upperBound = stringifyRangeBound(data[1]);\n\n return `${(data.inclusive[0] ? '[' : '(') + lowerBound},${upperBound}${data.inclusive[1] ? ']' : ')'}`;\n}\nexports.stringify = stringify;\n\nfunction parse(value, parser) {\n if (value === null) return null;\n if (value === 'empty') {\n return [];\n }\n\n let result = value\n .substring(1, value.length - 1)\n .split(',', 2);\n\n if (result.length !== 2) return value;\n\n result = result.map((item, index) => {\n return {\n value: parseRangeBound(item, parser),\n inclusive: index === 0 ? value[0] === '[' : value[value.length - 1] === ']'\n };\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