Files
30-seconds-of-code/javascript/snippets/expand-tabs.md
2023-05-01 22:35:56 +03:00

516 B

title, type, tags, author, cover, dateModified
title type tags author cover dateModified
Expand tabs into spaces snippet
string
regexp
chalarangelo houses-rock-sea 2020-09-15T16:28:04+03:00

Convert tabs to spaces, where each tab corresponds to count spaces.

  • Use String.prototype.replace() with a regular expression and String.prototype.repeat() to replace each tab character with count spaces.
const expandTabs = (str, count) => str.replace(/\t/g, ' '.repeat(count));
expandTabs('\t\tlorem', 3); // '      lorem'