2.0.5 • Published 2 months ago

@zerodep/string-padright v2.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@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
2.0.5

2 months ago

2.0.4

2 months ago

2.0.1

10 months ago