expand-tabs-to-spaces
v1.0.1
Published
expand tabs to spaces
Downloads
4
Readme
expand-tabs-to-spaces
expand tabs to spaces
Install
npm install expand-tabs-to-spaces
Usage & Api
/*
expand tabs to spaces
expandTabs(str, options | tabSize )
options
.tabSize
tab spaces size, default 4.
.lengthFunc
a user-defined function returned the string length, for FullWidth codeset.
function(str){ ...; return length; }
if empty, use the str.length by default.
*/
var expandTabs = require("expand-tabs-to-spaces");
//a simple HalfWidth length function for test, refer halfwidth-kit/length @ npm
var halfWidthLength = function (str) {
return str.length + str.replace(/[\u0000-\u00ff\uFF61-\uFF9F\uFFE8-\uFFEE]+/g, "").length
}
expandTabs("a") === "a" &&
expandTabs("\ta") === " a" &&
expandTabs("\t\ta") === " a" &&
expandTabs("\ta\tb") === " a b" &&
expandTabs("\taa\tb") === " aa b" &&
expandTabs("\taaa\tb") === " aaa b" &&
expandTabs("\taaaa\tb") === " aaaa b" &&
expandTabs("\ta\tb", 8) === " a b" &&
expandTabs("\ta\tb", { tabSize: 8 }) === " a b" &&
expandTabs("\ta中文\tb", { lengthFunc: halfWidthLength }) === " a中文 b" &&
expandTabs("\t中文\tb", { lengthFunc: halfWidthLength }) === " 中文 b" &&
expandTabs("中\t文\tb", { lengthFunc: halfWidthLength }) === "中 文 b" &&
//multiple lines
expandTabs("\n\n\taaaa\tb\r\r中\t文\tb\n\r\ta中文\tb", { lengthFunc: halfWidthLength })
=== "\n\n aaaa b\r\r中 文 b\n\r a中文 b" &&