1 | 'use strict';
|
2 |
|
3 | const Decimal128Type = require('../types/decimal128');
|
4 | const assert = require('assert');
|
5 |
|
6 | module.exports = function castDecimal128(value) {
|
7 | if (value == null) {
|
8 | return value;
|
9 | }
|
10 |
|
11 | if (typeof value === 'object' && typeof value.$numberDecimal === 'string') {
|
12 | return Decimal128Type.fromString(value.$numberDecimal);
|
13 | }
|
14 |
|
15 | if (value instanceof Decimal128Type) {
|
16 | return value;
|
17 | }
|
18 |
|
19 | if (typeof value === 'string') {
|
20 | return Decimal128Type.fromString(value);
|
21 | }
|
22 |
|
23 | if (Buffer.isBuffer(value)) {
|
24 | return new Decimal128Type(value);
|
25 | }
|
26 |
|
27 | if (typeof value === 'number') {
|
28 | return Decimal128Type.fromString(String(value));
|
29 | }
|
30 |
|
31 | if (typeof value.valueOf === 'function' && typeof value.valueOf() === 'string') {
|
32 | return Decimal128Type.fromString(value.valueOf());
|
33 | }
|
34 |
|
35 | assert.ok(false);
|
36 | }; |
\ | No newline at end of file |