Skip to content

Latest commit

 

History

History
87 lines (61 loc) · 1.7 KB

README.md

File metadata and controls

87 lines (61 loc) · 1.7 KB

Downloads Version

pad-center

pad-center fills between the start and end characters with character you want while maintaining the length. Like padStart and padEnd but from center, padCenter!

Use cases

  • Barcode generation
  • It's not goal of the package, but you can use it for masking strings
  • Tell me what you are using it for 🙂

Install

npm install pad-center

This package is a pure ESM package.

Usage

import padCenter from "pad-center";

padCenter({
    startWith: "053",
    endWith: "0",
    fillWith: "*",
    length: 11
});
// "053*******0"

padCenter({
    startWith: "GH1",
    endWith: "9",
    fillWith: "0",
    length: 10
});
// "GH10000009"

padCenter({
    startWith: "O",
    endWith: "G",
    fillWith: "_",
    length: 8
});
// "O______G"

API

padCenter(params) : string

params

Default: {}
Type: object
Required: Yes

params.startWith

Type: string | number
Required: Yes

params.endWith

Type: string | number
Required: Yes

params.fillWith

Type: string | number
Required: Yes

params.length

Type: number
Required: Yes

License

License