FastPad is a blazing fast left-pad function with performances better than pad-left and the new native function repeat (Present in the new ES6 and Node 6).
How is it possible to be faster than pad-left, the one used by google and so on?
The algorithm is the Egyptian string concatenation algorithm found in the British museum by researchers a while ago.
Even though pad-left is very fast, I've done it better by caching the result as well as there is no need to redo the math if the input is the same as the cached input.
How to use
$ npm install fastpad --save
var pad = require('fastpad');
On a small scale, the execution time for a single record is 5 microseconds compared to 6 microseconds which the famous pad-left has.
Below you can see some benchmark results ( each test was ran 100 times ):
PAD That returns 0004pad Result: 2.000.000 ops / 48 milisecondspad Result: 20.000.000 ops / 439 milisecondspad Result: 200.000.000 ops / 3.9 secondsPAD That returns 000000testpad Result: 200.000.000 ops / 4.2 seconds