Skip to content

Commit

Permalink
[feature] Support line feed char "\n" in the "formatter function".
Browse files Browse the repository at this point in the history
  • Loading branch information
congshengwu committed Mar 31, 2022
1 parent fc11677 commit 67dd13b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/util/toString.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export default function toString(obj) {
let result = JSON.stringify(obj, function (key, val) {
if (typeof val === "function") {
return `~--demo--~${val}~--demo--~`;
// This "replace function" is used to remove the useless line feeds among code.
return `~--demo--~${val}~--demo--~`.replace(/\n/g, '');
}
return val;
});
Expand All @@ -10,7 +11,7 @@ export default function toString(obj) {
result = result
.replace('"~--demo--~', "")
.replace('~--demo--~"', "")
.replace(/\\n/g, "")
.replace(/\\\\/g, '\\') // When the formatter function convert to string, '\n' in the return string will be replaced by '\\n', this "replace function" will replace it back to line feed '\n'.
.replace(/\\\"/g, '"'); //最后一个replace将release模式中莫名生成的\"转换成"
} while (result.indexOf("~--demo--~") >= 0);
// 添加此行把unicode转为中文(否则formatter函数中含有中文在release版本中显示不出来)
Expand Down

0 comments on commit 67dd13b

Please sign in to comment.