From 0ff81be54ea5e9e5b7294d4bc02671a2ab9cd495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=89=AC?= Date: Fri, 30 Mar 2018 16:14:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dformatter=E9=87=8C=E5=8D=B3?= =?UTF-8?q?=E4=BD=BF=E8=BE=93=E5=85=A5'\\n'=E4=B9=9F=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E7=AC=A6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ src/util/toString.js | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index dbe9c43..9154f84 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /node_modules *.sh +# webstorm +.idea diff --git a/src/util/toString.js b/src/util/toString.js index b4a6904..e0611db 100644 --- a/src/util/toString.js +++ b/src/util/toString.js @@ -1,13 +1,14 @@ export default function toString(obj) { let result = JSON.stringify(obj, function(key, val) { - if (typeof val === 'function') { - return `~--demo--~${val}~--demo--~`; - } - return val; - }); + if (typeof val === 'function') { + return `~--demo--~${val}~--demo--~`; + } + return val; + }); - do { - result = result.replace('\"~--demo--~', '').replace('~--demo--~\"', '').replace(/\\n/g, '').replace(/\\\"/g,"\"");//最后一个replace将release模式中莫名生成的\"转换成" - } while (result.indexOf('~--demo--~') >= 0); - return result; + do { + result = result.replace('\"~--demo--~', '').replace('~--demo--~\"', ''); + } while (result.indexOf('~--demo--~') >= 0); + result = result.replace(/\\n/g, '').replace(/\\\"/g,"\"");//最后一个replace将release模式中莫名生成的\"转换成" + return result; }