Giter Club home page Giter Club logo

ciomanip's Introduction

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

ciomanip's People

Contributors

battledash-2 avatar

Watchers

 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.