repeat-string
Repeat the given string n times. Fastest implementation for repeating a string.
Install
Install with npm:
$ npm install --save repeat-string
Usage
Repeat the given string
the specified number
of times.
Example:
Example
var repeat = require('repeat-string');
repeat('A', 5);
Params
string
{String}: The string to repeatnumber
{Number}: The number of times to repeat the stringreturns
{String}: Repeated string
Benchmarks
Repeat string is significantly faster than the native method (which is itself faster than repeating):
repeat-string █████████████████████████ (28,723,499 ops/sec)
repeat-string-1.5.4 ████████████████████████ (27,795,679 ops/sec)
repeating ████████ (10,271,694 ops/sec)
native ███████████████ (17,823,696 ops/sec)
repeat-string ███████████████████████ (21,416,711 ops/sec)
repeat-string-1.5.4 █████████████████████████ (22,949,513 ops/sec)
repeating █████████ (8,872,792 ops/sec)
native █████████████████ (16,288,558 ops/sec)
repeat-string █████████████████████████ (23,020,921 ops/sec)
repeat-string-1.5.4 ████████████████████████ (22,129,413 ops/sec)
repeating ████████ (7,833,673 ops/sec)
native ████████████████ (14,738,239 ops/sec)
repeat-string █████████████████████████ (23,066,376 ops/sec)
repeat-string-1.5.4 ████████████████████████ (22,891,258 ops/sec)
repeating █████ (5,528,905 ops/sec)
native ███████████ (10,527,513 ops/sec)
repeat-string ███████████████████████ (24,340,705 ops/sec)
repeat-string-1.5.4 █████████████████████████ (25,614,176 ops/sec)
repeating ████ (4,133,430 ops/sec)
native ███████ (7,888,010 ops/sec)
repeat-string █████████████████████████ (25,620,269 ops/sec)
repeat-string-1.5.4 ███████████████████████ (24,511,429 ops/sec)
repeating ███ (3,546,935 ops/sec)
native ██████ (6,673,426 ops/sec)
repeat-string █████████████████████████ (22,688,021 ops/sec)
repeat-string-1.5.4 ███████████████████████ (21,569,928 ops/sec)
repeating ███ (2,981,919 ops/sec)
native ██████ (5,509,279 ops/sec)
Run the benchmarks
Install dev dependencies:
npm i -d && node benchmark
About
Related projects
repeat-element: Create an array by repeating the given value n times. | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Contributors
Building docs
(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)
To generate the readme and API documentation with verb:
$ npm install -g verb verb-generate-readme && verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
This file was generated by verb-generate-readme, v0.2.0, on October 23, 2016.