Skip to content

Commit

Permalink
Add BigInt support
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Feb 14, 2023
1 parent 53e88ba commit 4cc2f4c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 24 additions & 2 deletions lib/json-dry.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class RootValue {
*
* @author Jelle De Loecker <[email protected]>
* @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
Expand Down Expand Up @@ -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);
}
Expand All @@ -330,7 +332,7 @@ class RootValue {
*
* @author Jelle De Loecker <[email protected]>
* @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
Expand All @@ -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);
Expand Down Expand Up @@ -773,6 +778,23 @@ class NumberValue extends Value {
}
}

/**
* Represent a BigInt value
*
* @author Jelle De Loecker <[email protected]>
* @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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"keywords": [
"json",
Expand Down

0 comments on commit 4cc2f4c

Please sign in to comment.