JSPM

@zerodep/string-padright

2.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q28607F
  • License MIT

A utility to right-pad a string or number with a character

Package Exports

  • @zerodep/string-padright

Readme

@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