Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bjarneo/format2
Advanced string formatting for the CLI
https://github.com/bjarneo/format2
Last synced: 3 days ago
JSON representation
Advanced string formatting for the CLI
- Host: GitHub
- URL: https://github.com/bjarneo/format2
- Owner: bjarneo
- License: mit
- Created: 2016-01-02T12:30:59.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-03T13:16:03.000Z (almost 9 years ago)
- Last Synced: 2024-09-14T11:53:38.028Z (2 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
format2
======
[![Code Climate](https://codeclimate.com/github/bjarneo/format2/badges/gpa.svg)](https://codeclimate.com/github/bjarneo/format2)
[![Test Coverage](https://codeclimate.com/github/bjarneo/format2/badges/coverage.svg)](https://codeclimate.com/github/bjarneo/format2/coverage)
![Travis](https://travis-ci.org/bjarneo/format2.svg?branch=master)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
------
```js
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
------
```js
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](http://i.imgur.com/dJw4chC.png)Contribution
------
Contributions are appreciated.License
------
MIT-licensed. See LICENSE.