ciomanip

1.0.4-patch1 • Public • Published

CIOManip

A speedy and lightweight io manipulation tool

Examples 🧪

Importing/Requiring:

const std = require('ciomanip');

Reading from stdin (sync):

// ... require
const input = std.in.read('What\'s your name? ');
console.log('His name is ' + input + '!');

Set state width

std.setwidth(16);

Set state fill

Setting the fill will check if the width is more than 0,
if it is, it will use the width to fill in the text (1 -> 001)

std.setwidth(3);
std.setfill('0');
std.write('1'); // 001

Writing a list

Lists use the width and align each row to fit in the list

std.setwidth(16);
std.fillWith([
	['hello', 'world', 5],
	['world', 'hello'],
	[5, 'world', 'hello'],
]);

Writing anything

std.write('hello');

Write with a newline

std.writes('hello');

Writing a newline

std.line(); // console.log(); | process.stdout.write('\n');

Alignment

Left:

std.alignLeft('text'); // has no special functionality

Right:

std.setwidth(20);
std.alignRight('Hello world');

Left-to-Right Table:

Arguments: Array<any> left, Array<any> right, Number<> padding
std.setwidth(50);
std.leftRightTable(
	['Value1', 'Value2'],
	['I\'m on the right!'],
);

Normal Table:

std.setwidth(51);
std.writeTable([
	['hello, world!', 'hey'],
	['hello, world!', 'hey again']
]);

Formatted Table:

std.setwidth(51);
std.formatTable([
	['hello, world!', 'hey'],
	['hello, world!', 'hey again']
]);

Changing display mode:

Hex Mode (displays 0x<hex> rather than <number>)

std.hex();
std.writes(0xA); // 0xA
std.writes(10); // 0xA

Binary Mode

std.bin();
std.writes(0xA); // 1010
std.writes(10); // 1010

Plain Mode

std.plain();
std.write(0xA); // 10
std.write(10); // 10

Reset all settings:

std.reset();

Using different modes without a state change

std.dir.hex(0xA); // 0xA
std.dir.hex(10); // 0xA

std.dir.bin(0xA); // 1010
std.dir.bin(10); // 1010

std.dir.plain(10); // 10
std.dir.plain(0xA); // 10

Full example:

// Title
std.setwidth(16);
std.center('-');
std.write('Notes');

// Table
std.fillWith([
	['hello', 'world', 5],
	['world', 'hello'],
	[5, 'world', 'hello'],
]);

// Align
std.alignRight('Hello');
std.line();

// console.log(std.in.read('Hello, '));

std.reset();
std.hex();

std.writes(0x3A);

Package Sidebar

Install

npm i ciomanip

Weekly Downloads

16

Version

1.0.4-patch1

License

MIT

Unpacked Size

14.8 kB

Total Files

12

Last publish

Collaborators

  • battledash2