postgrejs
Version:
Professional PostgreSQL client NodeJS
56 lines (55 loc) • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArrayLsegType = exports.LsegType = void 0;
const constants_js_1 = require("../constants.js");
const LSEG_PATTERN1 = /^\[ *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *, *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *]$/;
const LSEG_PATTERN2 = /^\( *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *, *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *\)$/;
const LSEG_PATTERN3 = /^\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\) *, *\( *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *\)$/;
const LSEG_PATTERN4 = /^(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *, *(-?\d+\.?\d*) *, *(-?\d+\.?\d*)$/;
exports.LsegType = {
name: 'lseg',
oid: constants_js_1.DataTypeOIDs.lseg,
jsType: 'object',
parseBinary(v) {
return {
x1: v.readDoubleBE(0),
y1: v.readDoubleBE(8),
x2: v.readDoubleBE(16),
y2: v.readDoubleBE(24),
};
},
encodeBinary(buf, v) {
buf.writeDoubleBE(v.x1);
buf.writeDoubleBE(v.y1);
buf.writeDoubleBE(v.x2);
buf.writeDoubleBE(v.y2);
},
parseText(v) {
const m = v.match(LSEG_PATTERN1) ||
v.match(LSEG_PATTERN2) ||
v.match(LSEG_PATTERN3) ||
v.match(LSEG_PATTERN4);
if (!m)
return undefined;
return {
x1: parseFloat(m[1]),
y1: parseFloat(m[2]),
x2: parseFloat(m[3]),
y2: parseFloat(m[4]),
};
},
isType(v) {
return (typeof v === 'object' &&
Object.keys(v).length === 4 &&
typeof v.x1 === 'number' &&
typeof v.y1 === 'number' &&
typeof v.x2 === 'number' &&
typeof v.y2 === 'number');
},
};
exports.ArrayLsegType = {
...exports.LsegType,
name: '_lseg',
oid: constants_js_1.DataTypeOIDs._lseg,
elementsOID: constants_js_1.DataTypeOIDs.lseg,
};