@zerodep/string-padright
TypeScript icon, indicating that this package has built-in type declarations

2.0.5 • Public • Published

@zerodep/string-padright

version language types license

CodeFactor Known Vulnerabilities

A utility to suffix a value with a specified character to create a string of a specific length. Non-string values will cause a ZeroDepError to be thrown.

Full documentation is available at the zerodep.app page.

Examples

All @zerodep packages support both ESM and CJS.

import { stringPadRight } from '@zerodep/string-padright';
// or
const { stringPadRight } = require('@zerodep/string-padright');

Using Default Space Separator

stringPadRight('abc', 10); // "abc       "
stringPadRight(123, 10); // "123       "
stringPadRight(456n, 10); // "456       "

Using Custom Separator

stringPadRight('bc', 5, 'a'); // "bcaaa"
stringPadRight(123, 6, '0'); // "123000"
stringPadRight(456n, 7, '_'); // "456____"

Edge Cases

// when the value exceeds the requested size the full value is returned
stringPadRight('abcdefghij', 5, 'x'); // "abcdefghij"

// non-string values
stringPadRight({ not: 'a string' }, 2); // throws ZeroDepError: Value is not a string

/@zerodep/string-padright/

    Package Sidebar

    Install

    npm i @zerodep/string-padright

    Homepage

    zerodep.app

    Weekly Downloads

    1

    Version

    2.0.5

    License

    MIT

    Unpacked Size

    8.59 kB

    Total Files

    7

    Last publish

    Collaborators

    • cdepage