540 B
540 B
title, type, language, tags, author, cover, dateModified
| title | type | language | tags | author | cover | dateModified | ||
|---|---|---|---|---|---|---|---|---|
| Expand tabs into spaces | snippet | javascript |
|
chalarangelo | naming-conventions | 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 andString.prototype.repeat()to replace each tab character withcountspaces.
const expandTabs = (str, count) => str.replace(/\t/g, ' '.repeat(count));
expandTabs('\t\tlorem', 3); // ' lorem'