fixed-string

1.0.3 • Public • Published

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'

Package Sidebar

Install

npm i fixed-string

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

10.1 kB

Total Files

6

Last publish

Collaborators

  • felipep