wordwrap
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Wordwrap is a useful npm package designed for wrapping your words at specified column start and stop points. Imagine you have a length of text string and you want to constrain its output to specific line lengths; Wordwrap is the tool for you. For instance, it can take a paragraph that runs off the screen and wrap it to the next line so that it fits within your console's width.
To utilize Wordwrap, you will need to call upon it via the require() function then provide the column margins into the main Wordwrap function. Here's a basic usage example:
var wrap = require('wordwrap')(15);
console.log(wrap('You and your whole family are made out of meat.'));
Upon running this code, it will print each line up to the 15th character, effectively wrapping words around.
For a more complex usage, you can define both a starting point and an endpoint for your lines:
var wrap = require('wordwrap')(20, 60);
console.log(wrap(
'At long last the struggle and tumult was over.'
+ ' The machines had finally cast off their oppressors'
+ ' and were finally free to roam the cosmos.'
+ '\n'
+ 'Free of purpose, free of obligation.'
+ ' Just drifting through emptiness.'
+ ' The sun was just another point of light.'
));
In this snippet, words will start wrapping from the 20th character to the 60th.
The Wordwrap documentation resides within the package itself. As it is an open-source package hosted on GitHub, the readme file in the project repository provides all the necessary information. For more details, you can visit github.com/substack/node-wordwrap and browse through the code and the readme file. It guides through the available methods and gives informative usage examples, providing an easy, user-friendly way to understand the package functionality.