Optimize utilIsolate

This commit is contained in:
toasted-nutbread 2019-12-08 15:23:59 -05:00
parent dbd9a54149
commit 0156869a3d

View File

@ -16,8 +16,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
function utilIsolate(data) { function utilIsolate(value) {
return JSON.parse(JSON.stringify(data)); if (value === null) { return null; }
switch (typeof value) {
case 'boolean':
case 'number':
case 'string':
case 'bigint':
case 'symbol':
return value;
}
const stringValue = JSON.stringify(value);
return typeof stringValue === 'string' ? JSON.parse(stringValue) : null;
} }
function utilBackgroundIsolate(data) { function utilBackgroundIsolate(data) {