repeat-string icon indicating copy to clipboard operation
repeat-string copied to clipboard

Infinity and early conditions

Open customcommander opened this issue 4 years ago • 2 comments

This pull request has a few things going on:

  1. Mocha was a bit out of date. Upgraded it but that meant having to stop testing on Node.js 6 and below. These versions of Node.js aren't supported anymore so probably not a big deal anyway.
  2. Added a few missing tests: numbers aren't rounded and negative numbers produce empty strings
  3. There were var and const. No need to have both so replaced with const.
  4. Early exit condition when the string to repeat is empty
  5. Breaking change: can't repeat a string when number is Infinity

Infinity

The native String#repeat method does throw an error when Infinity is given as a parameter. So this changes aligns with the native behaviour. Also there's an issue with how Infinity works right now: with the same string to repeat, it will produce a different string:

const repeat = require('repeat-string');

repeat('🌯', Infinity)
//=> '🌯🌯'
repeat('🌯', Infinity)
//=> '🌯🌯🌯🌯'
repeat('🌯', Infinity)
//=> '🌯🌯🌯🌯🌯🌯' 

This didn't seem right to me so took the liberty to throw an error instead.

customcommander avatar Apr 16 '21 20:04 customcommander

@jonschlinkert 👋

customcommander avatar Apr 20 '21 18:04 customcommander

@customcommander nice work! I only had the one comment, everything else is great. thank you!

jonschlinkert avatar Apr 20 '21 18:04 jonschlinkert