GithubHelp home page GithubHelp logo

center-text's Introduction

center-text Build status

Center text horizontally

This was built as part of a CLI presentation to horizontally center text. As a result, this will properly center ANSI colored text.

It was not designed to work with non-monospaced text.

Getting Started

Install the module with: npm install center-text

// In an 40 column terminal
var centerText = require('center-text');
centerText('Hello World!');
// Returns '              Hello World!              ';

Documentation

center-text exposes a function, centerText, as its module.exports.

centerText(text, options)

Return string of centered text

  • text String - Content to center
  • options Object
    • columns Number - Amount of columns to center between. If not provided, process.stdout.columns will be used.
    • leftBias Boolean - If truthy, uneven offsets will pad to the right more than the left.

Examples

An example of leftBias in action:

centerText('aa', {
  columns: 3
});
// Returns ' aa'

centerText('aa', {
  columns: 3,
  leftBias: true
});
// Returns 'aa '

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via grunt and test via npm test.

Donating

Support this project and others by twolfson via gittip.

Support via Gittip

Unlicense

As of Nov 30 2013, Todd Wolfson has released this repository and its contents to the public domain.

It has been released under the UNLICENSE.

center-text's People

Contributors

twolfson avatar

Watchers

Bryan Miño 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.