pad-center
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

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

Package Sidebar

Install

npm i pad-center

Weekly Downloads

4

Version

1.1.4

License

MIT

Unpacked Size

14.5 kB

Total Files

16

Last publish

Collaborators

  • ozgurg