Initial commit
This commit is contained in:
11
node_modules/pg-numeric/CHANGELOG.md
generated
vendored
Normal file
11
node_modules/pg-numeric/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
## Unreleased
|
||||
|
||||
|
||||
## [1.0.2][] – 2019-11-10
|
||||
|
||||
### Fixed
|
||||
|
||||
- A negative sign is no longer stripped by mistake for numbers of the form −0.000…00(d) where the number of zeros after the decimal point is 2 mod 4.
|
||||
|
||||
|
||||
[1.0.2]: https://github.com/charmander/pg-numeric/compare/v1.0.1...v1.0.2
|
||||
13
node_modules/pg-numeric/LICENSE
generated
vendored
Normal file
13
node_modules/pg-numeric/LICENSE
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
Copyright 2019 Charmander <~@charmander.me>
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
11
node_modules/pg-numeric/README.md
generated
vendored
Normal file
11
node_modules/pg-numeric/README.md
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
A reader for the PostgreSQL binary format for numeric values, producing a string. Designed for [pg][].
|
||||
|
||||
```js
|
||||
const readNumeric = require('pg-numeric');
|
||||
|
||||
readNumeric(Buffer.from('000600020000000a000c0d801ed203db198f0834', 'hex'))
|
||||
// '1234567890.0987654321'
|
||||
```
|
||||
|
||||
|
||||
[pg]: https://github.com/brianc/node-postgres
|
||||
125
node_modules/pg-numeric/index.js
generated
vendored
Normal file
125
node_modules/pg-numeric/index.js
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
'use strict';
|
||||
|
||||
const readDigit = (buffer, index) => {
|
||||
const digit = buffer.readUInt16BE(8 + 2 * index);
|
||||
|
||||
if (digit > 9999) {
|
||||
throw new RangeError('Invalid numeric digit: ' + digit);
|
||||
}
|
||||
|
||||
return digit;
|
||||
};
|
||||
|
||||
const readNumeric = buffer => {
|
||||
const ndigits = buffer.readUInt16BE(0);
|
||||
let weight = buffer.readInt16BE(2);
|
||||
const sign = buffer.readUInt16BE(4);
|
||||
const dscale = buffer.readUInt16BE(6);
|
||||
let signText;
|
||||
let isNegativeZero;
|
||||
|
||||
switch (sign) {
|
||||
case 0x0000:
|
||||
signText = '';
|
||||
isNegativeZero = false;
|
||||
break;
|
||||
|
||||
case 0x4000:
|
||||
signText = '-';
|
||||
isNegativeZero = true;
|
||||
break;
|
||||
|
||||
case 0xc000:
|
||||
return 'NaN';
|
||||
|
||||
default:
|
||||
throw new RangeError('Invalid numeric sign: 0x' + sign.toString(16));
|
||||
}
|
||||
|
||||
if (2 * ndigits !== buffer.length - 8) {
|
||||
throw new RangeError('Invalid numeric length: ' + buffer.length + ' bytes of data representing ' + ndigits + ' digits');
|
||||
}
|
||||
|
||||
if (dscale > 0x3fff) {
|
||||
throw new RangeError('Invalid numeric dscale: 0x' + dscale.toString(16));
|
||||
}
|
||||
|
||||
let result = signText;
|
||||
let i = 0;
|
||||
|
||||
integerPart: {
|
||||
for (;;) {
|
||||
if (i >= ndigits) {
|
||||
// no non-zero digits
|
||||
weight = -1;
|
||||
}
|
||||
if (weight < 0) {
|
||||
result += '0';
|
||||
break integerPart;
|
||||
}
|
||||
|
||||
const digit = readDigit(buffer, i);
|
||||
i++;
|
||||
weight--;
|
||||
|
||||
if (digit !== 0) {
|
||||
isNegativeZero = false;
|
||||
result += String(digit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (weight >= 0 && i < ndigits) {
|
||||
const digit = readDigit(buffer, i);
|
||||
i++;
|
||||
weight--;
|
||||
|
||||
result += String(10000 + digit).substring(1);
|
||||
}
|
||||
|
||||
while (weight >= 0) {
|
||||
result += '0000';
|
||||
weight--;
|
||||
}
|
||||
}
|
||||
|
||||
fractionalPart: if (dscale !== 0) {
|
||||
result += '.';
|
||||
|
||||
const omitted = -1 - weight;
|
||||
|
||||
if (omitted > 0) {
|
||||
if (4 * omitted > dscale) {
|
||||
result += '0'.repeat(dscale);
|
||||
break fractionalPart;
|
||||
}
|
||||
|
||||
result += '0'.repeat(4 * omitted);
|
||||
}
|
||||
|
||||
while (-4 * weight <= dscale) {
|
||||
const digit = i < ndigits ? readDigit(buffer, i) : 0;
|
||||
i++;
|
||||
weight--;
|
||||
|
||||
if (isNegativeZero && digit !== 0) {
|
||||
isNegativeZero = false;
|
||||
}
|
||||
|
||||
result += String(10000 + digit).substring(1);
|
||||
}
|
||||
|
||||
{
|
||||
const digit = i < ndigits ? readDigit(buffer, i) : 0;
|
||||
result += String(10000 + digit).substr(1, dscale % 4);
|
||||
|
||||
if (isNegativeZero && digit >= Math.pow(10, 4 - dscale % 4)) {
|
||||
isNegativeZero = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isNegativeZero ? result.substring(1) : result;
|
||||
};
|
||||
|
||||
module.exports = readNumeric;
|
||||
23
node_modules/pg-numeric/package.json
generated
vendored
Normal file
23
node_modules/pg-numeric/package.json
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "pg-numeric",
|
||||
"version": "1.0.2",
|
||||
"description": "reads PostgreSQL binary format for numeric values into a string",
|
||||
"bugs": "https://github.com/charmander/pg-numeric/issues",
|
||||
"license": "ISC",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/charmander/pg-numeric"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@charmander/eslint-config-base": "1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user