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

2.0.5 • Public • Published

@zerodep/string-padleft

version language types license

CodeFactor Known Vulnerabilities

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.

Examples

All @zerodep packages support both ESM and CJS.

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

Using Default Space Separator

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

Using Custom Separator

stringPadLeft('bc', 5, 'a'); // "aaabc"
stringPadLeft(123, 6, '0'); // "000123"
stringPadLeft(456n, 7, '_'); // "____456"

Edge Cases

// 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

Readme

Keywords

Package Sidebar

Install

npm i @zerodep/string-padleft

Homepage

zerodep.app

Weekly Downloads

2

Version

2.0.5

License

MIT

Unpacked Size

8.54 kB

Total Files

7

Last publish

Collaborators

  • cdepage