1.0.3 • Published 2 years ago

fixed-string v1.0.3

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
2 years ago

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'
1.0.3

2 years ago

1.0.2

2 years ago