Code Monkey home page Code Monkey logo

node-wordwrap's Introduction

wordwrap

Wrap your words.

example

made out of meat

meat.js

var wrap = require('wordwrap')(15);
console.log(wrap('You and your whole family are made out of meat.'));

output:

You and your
whole family
are made out
of meat.

centered

center.js

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.'
));

output:

                    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.
                    Free of purpose, free of obligation.
                    Just drifting through emptiness. The
                    sun was just another point of light.

methods

var wrap = require('wordwrap');

wrap(stop), wrap(start, stop, params={mode:"soft"})

Returns a function that takes a string and returns a new string.

Pad out lines with spaces out to column start and then wrap until column stop. If a word is longer than stop - start characters it will overflow.

In "soft" mode, split chunks by /(\S+\s+/ and don't break up chunks which are longer than stop - start, in "hard" mode, split chunks with /\b/ and break up chunks longer than stop - start.

wrap.hard(start, stop)

Like wrap() but with params.mode = "hard".

node-wordwrap's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.