value-enhancer
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -168,2 +168,9 @@ 'use strict'; | ||
} | ||
toString() { | ||
return String(this.value); | ||
} | ||
toJSON(key) { | ||
const value = this.value; | ||
return value && value.toJSON ? value.toJSON(key) : value; | ||
} | ||
}; | ||
@@ -170,0 +177,0 @@ |
{ | ||
"name": "value-enhancer", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "A tiny library to enhance value with reactive wrapper.", |
@@ -80,2 +80,32 @@ import { SubscriberMode, Subscribers } from "./subscribers"; | ||
} | ||
/** | ||
* @returns the string representation of `this.value`. | ||
* | ||
* @example | ||
* ```js | ||
* const v$ = val(val(val(1))); | ||
* console.log(`${v$}`); // "1" | ||
* ``` | ||
*/ | ||
public toString(): string { | ||
return String(this.value); | ||
} | ||
/** | ||
* @returns the JSON representation of `this.value`. | ||
* | ||
* @example | ||
* ```js | ||
* const v$ = val(val(val({ a: 1 }))); | ||
* JSON.stringify(v$); // '{"a":1}' | ||
* ``` | ||
*/ | ||
public toJSON(key: string): unknown { | ||
const value = this.value as | ||
| undefined | ||
| null | ||
| { toJSON?: (key: string) => unknown }; | ||
return value && value.toJSON ? value.toJSON(key) : value; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
103130
1397