Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds pad for adding zero padding to a number. #514

Open
wants to merge 60 commits into
base: master
Choose a base branch
from

Conversation

jfrux
Copy link

@jfrux jfrux commented Oct 11, 2018

I've been using this a lot lately and figured I'd submit if you are interested in upstreaming.
I can make mods if something looks shady.

Basically it just does zero-padding of numbers.

README exerpt:

pad

adds zero-padding to a number and returns a string, allows composing

number1: 1,
size1: 3,
size2: '5',
example: pad('number1','size1'), // 001
example2: pad('number1','size1'), // 001
example3: pad(raw(8),'size2') // 00008

README.md Outdated
string1: '3',
string2: '5',
example: pad('number1','string1'), // 001
example2: pad(raw(8),'string2') // 00001
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be //00008 right?

Same typo exists in the PR description.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, missed that. Sorry!

@mriska
Copy link
Contributor

mriska commented Oct 11, 2018

Questions:

  • Should this be called pad or leftPad - If we want to have a rightPad later?
  • Would/should it work with padding strings as well as numbers?
  • Should it be possible to choose the padCharacter yourself? - I think this might be interesting if it is used for padding strings.

@kellyselden, your thoughts?

@jfrux
Copy link
Author

jfrux commented Oct 11, 2018

@mriska Great points, I like those ideas.
I could work on that for sure.

size1: 3,
size2: '5',
example1: pad('number1','size1'), // 001
example2: pad('number1','size1'), // 001
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example1 and example2 are now the same.

@jfrux
Copy link
Author

jfrux commented Oct 11, 2018

@kellyselden
Copy link
Owner

Thanks for those links. I think it makes sense to match those apis. Lets call it padLeft, default to space char, and allow your own char.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants