Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 5, 2022 04:12 pm GMT

1 line of code: How to convert tabs to spaces

const tabsToSpaces = (str, tabsize = 4) => str.replaceAll("", " ".repeat(tabsize));

Returns the string and replaces a series of spaces (tab size) with a tab.

The repository & npm package

You can find the all the utility functions from this series at github.com/martinkr/onelinecode
The library is also published to npm as @onelinecode for your convenience.

The code and the npm package will be updated every time I publish a new article.

Follow me on Twitter: @martinkr and consider to buy me a coffee

Photo by zoo_monkey on Unsplash

Subscribe to the weekly modern frontend development newsletter


Original Link: https://dev.to/martinkr/1-line-of-code-how-to-convert-tabs-to-spaces-529p

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To