format2

Advanced string formatting for the CLI

Usage no npm install needed!

<script type="module">
  import format2 from 'https://cdn.skypack.dev/format2';
</script>

README

format2

Code Climate Test Coverage Travis

What

This lib is for formatting strings for the CLI. For example if you want to create a list shown in the advanced example.

Installation

It's available on npm.

$ npm install --save format2

Basic example

var format2 = require('format2');

format2('should replace {0:3} with "#" and two trailing spaces', '#');

Output:
should replace #   with "#" and two trailing spaces

// Should cut the string and replace with only one hashtag
format2('{1:2}', '##');

Output:
#

Advanced example

var format2 = require('format2');
var formatting = '{0:3} | {0:25} | {0:25} | {0:25}';

console.log(format2(
    formatting,
    '#',
    'Artist',
    'Song',
    'Album'
));
console.log(format2(
    formatting,
    '-'.repeat(3),
    '-'.repeat(24),
    '-'.repeat(24),
    '-'.repeat(24)
));
console.log(format2(
    formatting,
    '1.',
    'Bjarne Oeverli',
    'Let me node you',
    'Best of Node'
));
console.log(format2(
    formatting,
    '2.',
    'Bjarne Oeverli',
    'Node',
    'Best of Node'
));

Output

Contribution

Contributions are appreciated.

License

MIT-licensed. See LICENSE.