A utility to prefix 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 { stringPadLeft } from '@zerodep/string-padleft';
// or
const { stringPadLeft } = require('@zerodep/string-padleft');
stringPadLeft('abc', 10); // " abc"
stringPadLeft(123, 10); // " 123"
stringPadLeft(456n, 10); // " 456"
stringPadLeft('bc', 5, 'a'); // "aaabc"
stringPadLeft(123, 6, '0'); // "000123"
stringPadLeft(456n, 7, '_'); // "____456"
// when the value exceeds the requested size the full value is returned
stringPadLeft('abcdefghij', 5, 'x'); // "abcdefghij"
// non-string values
stringPadLeft({ not: 'a string' }, 2); // throws ZeroDepError: Value is not a string