Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
repeat-string
Advanced tools
Repeat the given string n times. Fastest implementation for repeating a string.
The repeat-string npm package is a minimalistic library that allows users to repeat a given string a specified number of times. It is useful for creating padding, indentation, or repeating patterns in strings.
String repetition
Repeats the '*' character 3 times to produce the string '***'.
"*".repeat(3)
This package is a polyfill for the String.prototype.repeat method as per the ECMAScript 6 (ES2015) specification. It provides the same functionality as repeat-string but also ensures compatibility with older environments that do not support the native .repeat() method.
The pad package offers string padding functionalities. While repeat-string focuses solely on repeating strings, pad allows you to add characters to the start or end of a string to reach a desired length, which can include repeating a character or string.
Repeat-element is similar to repeat-string but is designed to repeat any given element, not just strings. It can be used to create an array with repeated elements, which can then be joined into a string if needed.
Repeat the given string n times. Fastest implementation for repeating a string.
npm i repeat-string --save
bower install repeat-string --save
Repeat the given string
the specified number
of times.
string
{String}: The string to repeatnumber
{Number}: The number of times to repeat the stringreturns
{String}: Repeated stringExample:
var repeat = require('repeat-string');
repeat('A', 5);
//=> AAAAA
Repeat string is significantly faster than repeating.
#1: 2000x
repeating.js x 6,547,013 ops/sec ±0.55% (97 runs sampled)
repeat-string.js x 17,295,983 ops/sec ±0.86% (90 runs sampled)
#2: 250x
repeating.js x 7,043,588 ops/sec ±0.84% (97 runs sampled)
repeat-string.js x 16,247,722 ops/sec ±0.63% (94 runs sampled)
#3: 5x
repeating.js x 11,895,182 ops/sec ±0.63% (99 runs sampled)
repeat-string.js x 16,097,331 ops/sec ±0.67% (93 runs sampled)
#4: 50x
repeating.js x 9,572,600 ops/sec ±0.57% (99 runs sampled)
repeat-string.js x 16,681,594 ops/sec ±0.78% (94 runs sampled)
Run the benchmarks
Install dev dependencies:
npm i -d && node benchmark
Jon Schlinkert
Other projects that I maintain:
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb on January 18, 2015.
FAQs
Repeat the given string n times. Fastest implementation for repeating a string.
The npm package repeat-string receives a total of 12,463,545 weekly downloads. As such, repeat-string popularity was classified as popular.
We found that repeat-string demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.