dvdzkwsk / redash

Tiny functional programming suite for JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pad methods?

levithomason opened this issue · comments

Curious if it is in the interest of this lib to support methods for padding strings.

I think some simple ones (padLeft, padRight, etc.) would be a welcome addition :D.

How about?:

pad(num: number, char: string, str: string): string
padLeft(num: number, char: string, str: string): string
padRight(num: number, char: string, str: string): string

num - the total minimum width of the returned string
char - the character to pad with
str - the input string to pad

---

pad(4, ' ', 'yo')          // => ' yo '
padLeft(16, 'X', '1234')   // => 'XXXXXXXXXXXX1234'
padRight(10, '-', '567')   // => '573-------'

Those all look good to me. I think there are some oddities with handling foreign characters, but I'd be satisfied with an implementation that works with the majority use case and then address issues should they arise.

All 3 of these have been added :).