fixed-string
v1.0.3
Published
FixedString is a class that allows you to manipulate fixed length strings. It is useful for creating fixed length records for files, printed receipts or other purposes.
Downloads
18
Readme
FixedString
FixedString is a class that allows you to manipulate fixed length strings. It is useful for creating fixed length records for files, printed receipts or other purposes.
Installation
npm install fixed-string
Usage
const FixedString = require('../fixed-string').default;
const fixedLine = new FixedString(20);
fixedLine.rightAlign('abc'); // ' abc'
fixedLine.leftAlign('def'); // 'def abc'
fixedLine.centerAlign('xyz'); // 'def xyz abc'
// use a specific position
fixedLine.insert('012',9); // 'def 012 abc'
//limit the length of the inserted string
// notice the behavior, the insertion is truncated to three characters
// but it chops off the left end (because it is right aligned)
fixedLine.rightAlign('WXYZ',9,3); // 'def XYZ abc'