We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当前的代码中为了避免 template strings 产生多余的缩进,导致代码格式很奇怪,可以使用 tagged templates 来优化代码格式。
// 为了避免多余的缩进,将 template strings 置与行首 function getCodeSnippet() { return ` var world = 'world'; console.log('hello, ' world); `; } // 不必将 template strings 置与行首 function getCodeSnippet() { return unIndex` var world = 'world'; console.log('hello, ' world); `; } // tagged templates 移除多余的缩进 function unIndent(strings, ...values) { const text = strings .map((s, i) => (i === 0 ? s : values[i - 1] s)) .join(""); const lines = text.replace(/^\n/u, "").replace(/\n\s*$/u, "").split("\n"); const lineIndents = lines.filter(line => line.trim()).map(line => line.match(/ */u)[0].length); const minLineIndent = Math.min(...lineIndents); return lines.map(line => line.slice(minLineIndent)).join("\n"); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
这个特性解决了什么问题?
当前的代码中为了避免 template strings 产生多余的缩进,导致代码格式很奇怪,可以使用 tagged templates 来优化代码格式。
这个 API 长什么样?
The text was updated successfully, but these errors were encountered: