diff --git a/CHANGELOG.md b/CHANGELOG.md index acd2d71..ced1e4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.2 (WIP) + +* Add `BigInt` support + ## 2.0.1 (2023-01-23) * Optimize speed by always setting the `root` property diff --git a/lib/json-dry.js b/lib/json-dry.js index 98a8b13..da410ba 100644 --- a/lib/json-dry.js +++ b/lib/json-dry.js @@ -273,7 +273,7 @@ class RootValue { * * @author Jelle De Loecker * @since 2.0.0 - * @version 2.0.1 + * @version 2.0.2 * * @param {Object} holder The object that holds the value * @param {String} key The key this value is held under @@ -312,6 +312,8 @@ class RootValue { return new DateValue(holder, key, value, parent, this); } else if (dry_type === 'escape') { return new EscapedObjectValue(holder, key, value.value, parent, this); + } else if (dry_type === 'bigint') { + return new BigIntValue(holder, key, value, parent, this); } else { result = new UnknownUndrierValue(holder, key, value, parent, this); } @@ -330,7 +332,7 @@ class RootValue { * * @author Jelle De Loecker * @since 2.0.0 - * @version 2.0.1 + * @version 2.0.2 * * @param {Object} holder The object that holds the value * @param {String} key The key this value is held under @@ -356,6 +358,9 @@ class RootValue { case 'number': return new NumberValue(holder, key, value, parent, this); + + case 'bigint': + return new BigIntValue(holder, key, value, parent, this); default: return new Value(holder, key, value, parent, this); @@ -773,6 +778,23 @@ class NumberValue extends Value { } } +/** + * Represent a BigInt value + * + * @author Jelle De Loecker + * @since 2.0.2 + * @version 2.0.2 + */ +class BigIntValue extends Value { + driedValue() { + return {dry: 'bigint', value: '' + this.value}; + } + + initialRevive(value) { + return BigInt(value.value); + } +} + /** * Represent a regexp value * (For undrying) diff --git a/package.json b/package.json index 2984870..ccd3429 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "json-dry", "description": "Don't repeat yourself, JSON: Add support for (circular) references, class instances, ...", - "version": "2.0.1", + "version": "2.0.2-alpha", "author": "Jelle De Loecker ", "keywords": [ "json",