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.
All @zerodep packages support both ESM and CJS.
import { stringPadRight } from '@zerodep/string-padright';
// or
const { stringPadRight } = require('@zerodep/string-padright');
stringPadRight('abc', 10); // "abc "
stringPadRight(123, 10); // "123 "
stringPadRight(456n, 10); // "456 "
stringPadRight('bc', 5, 'a'); // "bcaaa"
stringPadRight(123, 6, '0'); // "123000"
stringPadRight(456n, 7, '_'); // "456____"
// 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