pax_global_header 0000666 0000000 0000000 00000000064 13003165452 0014511 g ustar 00root root 0000000 0000000 52 comment=4398e75c25f694eae2052cd3d108d6b04913492c
repeat-string-1.6.1/ 0000775 0000000 0000000 00000000000 13003165452 0014302 5 ustar 00root root 0000000 0000000 repeat-string-1.6.1/.editorconfig 0000664 0000000 0000000 00000000405 13003165452 0016756 0 ustar 00root root 0000000 0000000 root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
insert_final_newline = false repeat-string-1.6.1/.eslintrc.json 0000664 0000000 0000000 00000007125 13003165452 0017103 0 ustar 00root root 0000000 0000000 {
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
},
"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},
"globals": {
"document": false,
"navigator": false,
"window": false
},
"rules": {
"accessor-pairs": 2,
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": [2, "never"],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"constructor-super": 2,
"curly": [2, "multi-line"],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": [2, 2, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [2, "functions"],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 0,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-proto": 0,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 0,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-useless-call": 0,
"no-with": 2,
"one-var": [0, { "initialized": "never" }],
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [0, "never"],
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
"semi-spacing": [2, { "before": false, "after": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, "never"],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [2, "any"],
"yoda": [2, "never"]
}
}
repeat-string-1.6.1/.gitattributes 0000664 0000000 0000000 00000000177 13003165452 0017202 0 ustar 00root root 0000000 0000000 # Enforce Unix newlines
* text eol=lf
# binaries
*.ai binary
*.psd binary
*.jpg binary
*.gif binary
*.png binary
*.jpeg binary repeat-string-1.6.1/.gitignore 0000664 0000000 0000000 00000000331 13003165452 0016267 0 ustar 00root root 0000000 0000000 # always ignore files
*.DS_Store
*.sublime-*
# test related, or directories generated by tests
test/actual
actual
coverage
# npm
node_modules
npm-debug.log
# misc
_gh_pages
bower_components
vendor
temp
tmp
TODO.md
repeat-string-1.6.1/.travis.yml 0000664 0000000 0000000 00000000154 13003165452 0016413 0 ustar 00root root 0000000 0000000 sudo: false
os:
- linux
- osx
language: node_js
node_js:
- node
- '6'
- '5'
- '0.12'
- '0.10'
repeat-string-1.6.1/.verb.md 0000664 0000000 0000000 00000000473 13003165452 0015644 0 ustar 00root root 0000000 0000000 ## Usage
{%= apidocs("index.js") %}
## Benchmarks
Repeat string is significantly faster than the native method (which is itself faster than [repeating](https://github.com/sindresorhus/repeating)):
```sh
{%= bench() %}
```
**Run the benchmarks**
Install dev dependencies:
```sh
npm i -d && node benchmark
```
repeat-string-1.6.1/LICENSE 0000664 0000000 0000000 00000002100 13003165452 0015300 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2014-2015, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
repeat-string-1.6.1/README.md 0000664 0000000 0000000 00000011701 13003165452 0015561 0 ustar 00root root 0000000 0000000 # repeat-string [](https://www.npmjs.com/package/repeat-string) [](https://npmjs.org/package/repeat-string) [](https://npmjs.org/package/repeat-string) [](https://travis-ci.org/jonschlinkert/repeat-string)
> Repeat the given string n times. Fastest implementation for repeating a string.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save repeat-string
```
## Usage
### [repeat](index.js#L41)
Repeat the given `string` the specified `number` of times.
**Example:**
**Example**
```js
var repeat = require('repeat-string');
repeat('A', 5);
//=> AAAAA
```
**Params**
* `string` **{String}**: The string to repeat
* `number` **{Number}**: The number of times to repeat the string
* `returns` **{String}**: Repeated string
## Benchmarks
Repeat string is significantly faster than the native method (which is itself faster than [repeating](https://github.com/sindresorhus/repeating)):
```sh
# 2x
repeat-string █████████████████████████ (26,953,977 ops/sec)
repeating █████████ (9,855,695 ops/sec)
native ██████████████████ (19,453,895 ops/sec)
# 3x
repeat-string █████████████████████████ (19,445,252 ops/sec)
repeating ███████████ (8,661,565 ops/sec)
native ████████████████████ (16,020,598 ops/sec)
# 10x
repeat-string █████████████████████████ (23,792,521 ops/sec)
repeating █████████ (8,571,332 ops/sec)
native ███████████████ (14,582,955 ops/sec)
# 50x
repeat-string █████████████████████████ (23,640,179 ops/sec)
repeating █████ (5,505,509 ops/sec)
native ██████████ (10,085,557 ops/sec)
# 250x
repeat-string █████████████████████████ (23,489,618 ops/sec)
repeating ████ (3,962,937 ops/sec)
native ████████ (7,724,892 ops/sec)
# 2000x
repeat-string █████████████████████████ (20,315,172 ops/sec)
repeating ████ (3,297,079 ops/sec)
native ███████ (6,203,331 ops/sec)
# 20000x
repeat-string █████████████████████████ (23,382,915 ops/sec)
repeating ███ (2,980,058 ops/sec)
native █████ (5,578,808 ops/sec)
```
**Run the benchmarks**
Install dev dependencies:
```sh
npm i -d && node benchmark
```
## About
### Related projects
[repeat-element](https://www.npmjs.com/package/repeat-element): Create an array by repeating the given value n times. | [homepage](https://github.com/jonschlinkert/repeat-element "Create an array by repeating the given value n times.")
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
### Contributors
| **Commits** | **Contributor**
|
| --- | --- |
| 51 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [LinusU](https://github.com/LinusU) |
| 2 | [tbusser](https://github.com/tbusser) |
| 1 | [doowb](https://github.com/doowb) |
| 1 | [wooorm](https://github.com/wooorm) |
### Building docs
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
```sh
$ npm install -g verb verb-generate-readme && verb
```
### Running tests
Install dev dependencies:
```sh
$ npm install -d && npm test
```
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
### License
Copyright © 2016, [Jon Schlinkert](http://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/repeat-string/blob/master/LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on October 23, 2016._ repeat-string-1.6.1/benchmark/ 0000775 0000000 0000000 00000000000 13003165452 0016234 5 ustar 00root root 0000000 0000000 repeat-string-1.6.1/benchmark/code/ 0000775 0000000 0000000 00000000000 13003165452 0017146 5 ustar 00root root 0000000 0000000 repeat-string-1.6.1/benchmark/code/add.js 0000664 0000000 0000000 00000001122 13003165452 0020230 0 ustar 00root root 0000000 0000000 module.exports = repeat;
function repeat(str, num) {
if (typeof str !== 'string') {
throw new TypeError('repeat-string expects a string.');
}
var len = str.length;
var max = len * num;
if (num === 1 || len === max) return str;
if (num === 2) return str + str;
if (cache !== str || typeof cache === 'undefined') {
res = cache = str;
num--;
}
var rlen = res.length;
while (max > rlen && num > 0) {
if (num & 1) {
res += str;
}
num >>= 1;
str += str;
}
return res.substr(0, max);
}
/**
* Results cache
*/
var res = '';
var cache;
repeat-string-1.6.1/benchmark/code/array.js 0000664 0000000 0000000 00000000167 13003165452 0020626 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(str, num) {
var arr = [];
arr[num] = '';
return arr.join(str);
}; repeat-string-1.6.1/benchmark/code/for-bitwise.js 0000664 0000000 0000000 00000000333 13003165452 0021735 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = repeat;
function repeat(str, num) {
var res = '';
for (;;) {
if (num & 1) {
res += str;
}
num >>>= 1;
if (!num) return res;
str += str;
}
return res;
} repeat-string-1.6.1/benchmark/code/for-join.js 0000775 0000000 0000000 00000000242 13003165452 0021230 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(val, num) {
num += 1;
var arr;
for (arr = []; 0 < num; num -= 1, arr[num] = '');
return arr.join(val);
};
repeat-string-1.6.1/benchmark/code/for-str-cache-2.js 0000775 0000000 0000000 00000000751 13003165452 0022306 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = repeat;
var res = '';
var cache;
function repeat(str, num) {
cache = cache || str;
if (cache !== str) {
res = '';
cache = str;
}
var max = (str.length * num);
var i = 0;
if (res.length >= max) {
return res.slice(0, max);
}
for (; num > 0; i++) {
if (num & 1) {
res += str;
}
if (res.length >= max) {
return res.slice(0, max);
}
num >>= 1;
str += str;
}
return res.slice(0, max);
}
repeat-string-1.6.1/benchmark/code/for-str-cache.js 0000775 0000000 0000000 00000000654 13003165452 0022151 0 ustar 00root root 0000000 0000000 'use strict';
var res = '';
var cache;
module.exports = function repeat(str, count) {
var max = (str.length * count);
var i = 0;
cache = cache || str;
if (cache !== str) {
res = '';
cache = str;
}
if (res.length >= max) {
return res.slice(0, max);
}
for (; i < count; i++) {
res += str;
if (res.length >= max) {
return res.slice(0, max);
}
}
return res.slice(0, max);
};
repeat-string-1.6.1/benchmark/code/for-str.js 0000775 0000000 0000000 00000000231 13003165452 0021077 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(val, amount) {
var res = '';
for (var i = 0; i < amount; i++) {
res += val;
}
return res;
};
repeat-string-1.6.1/benchmark/code/native.js 0000664 0000000 0000000 00000000131 13003165452 0020765 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(str, num) {
return str.repeat(num);
};
repeat-string-1.6.1/benchmark/code/new-array-for.js 0000775 0000000 0000000 00000000257 13003165452 0022204 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(val, amount) {
for (var i = 0, res = new Array(amount); i < amount + 1;) {
res[i++] = '';
}
return res.join(val);
};
repeat-string-1.6.1/benchmark/code/new-array-join.js 0000775 0000000 0000000 00000000217 13003165452 0022351 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(val, num) {
if (arguments.length === 1) return '';
return new Array(num + 1).join(val);
};
repeat-string-1.6.1/benchmark/code/repeat-string-1.3.0.js 0000775 0000000 0000000 00000000645 13003165452 0022735 0 ustar 00root root 0000000 0000000 'use strict';
var res = '';
var cache;
module.exports = function repeat(str, num) {
var max = str.length * num;
cache = cache || str;
if (cache !== str) {
res = '';
cache = str;
}
while (num > 0 && max > res.length) {
if (num & 1) {
res += str;
}
if (max <= res.length) {
return res.substr(0, max);
}
num >>= 1;
str += str;
}
return res.substr(0, max);
};
repeat-string-1.6.1/benchmark/code/repeat-string-1.5.4.js 0000664 0000000 0000000 00000002204 13003165452 0022731 0 ustar 00root root 0000000 0000000 /*!
* repeat-string
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
/**
* Results cache
*/
var res = '';
var cache;
/**
* Expose `repeat`
*/
module.exports = repeat;
/**
* Repeat the given `string` the specified `number`
* of times.
*
* **Example:**
*
* ```js
* var repeat = require('repeat-string');
* repeat('A', 5);
* //=> AAAAA
* ```
*
* @param {String} `string` The string to repeat
* @param {Number} `number` The number of times to repeat the string
* @return {String} Repeated string
* @api public
*/
function repeat(str, num) {
if (typeof str !== 'string') {
throw new TypeError('repeat-string expects a string.');
}
// cover common, quick use cases
if (num === 1) return str;
if (num === 2) return str + str;
var max = str.length * num;
if (cache !== str || typeof cache === 'undefined') {
cache = str;
res = '';
}
while (max > res.length && num > 0) {
if (num & 1) {
res += str;
}
num >>= 1;
if (!num) break;
str += str;
}
return res.substr(0, max);
}
repeat-string-1.6.1/benchmark/code/repeat-string.js 0000775 0000000 0000000 00000000061 13003165452 0022270 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = require('../..'); repeat-string-1.6.1/benchmark/code/repeating.js 0000775 0000000 0000000 00000000175 13003165452 0021470 0 ustar 00root root 0000000 0000000 'use strict';
var repeating = require('repeating');
module.exports = function(str, num) {
return repeating(num, str);
};
repeat-string-1.6.1/benchmark/code/unshift.js 0000775 0000000 0000000 00000000232 13003165452 0021164 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(val, amount) {
var res = [];
while (amount--) {
res.unshift(val);
}
return res.join('');
};
repeat-string-1.6.1/benchmark/code/while-array-1.js 0000775 0000000 0000000 00000000217 13003165452 0022071 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(val, num) {
var arr = [];
while (num--) {
arr[num] = val;
}
return arr.join('');
}; repeat-string-1.6.1/benchmark/code/while-array-2.js 0000775 0000000 0000000 00000000235 13003165452 0022072 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(val, num) {
var arr = [];
var i = 0;
while (num--) {
arr[i++] = val;
}
return arr.join('');
}; repeat-string-1.6.1/benchmark/code/while-array-3.js 0000775 0000000 0000000 00000000273 13003165452 0022075 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function(val, num) {
return repeat(val, num, []).join('');
};
function repeat(val, num, arr) {
while (num--) {
arr[num] = val;
}
return arr;
} repeat-string-1.6.1/benchmark/code/while-bitwise.js 0000664 0000000 0000000 00000000342 13003165452 0022257 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = repeat;
function repeat(str, num) {
var res = '';
while (num > 0) {
if (num & 1) {
res += str;
}
num >>>= 1;
if (!num) return res;
str += str;
}
return res;
} repeat-string-1.6.1/benchmark/code/while-square-root.js 0000664 0000000 0000000 00000000363 13003165452 0023075 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(str, num) {
var max = str.length * num;
num = Math.ceil(Math.sqrt(num));
while (num--) {
str += str;
if (str.length > max) {
break;
}
}
return str.slice(0, max);
}; repeat-string-1.6.1/benchmark/code/while-str-stack.js 0000664 0000000 0000000 00000000320 13003165452 0022520 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(str, num) {
var max = str.length * num;
while (num--) {
str += str;
if (str.length >= max) {
break;
}
}
return str.slice(0, max);
}; repeat-string-1.6.1/benchmark/code/while-str.js 0000775 0000000 0000000 00000000210 13003165452 0021416 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(val, amount) {
var str = '';
while (amount--) {
str += val;
}
return str;
}; repeat-string-1.6.1/benchmark/code/while.js 0000775 0000000 0000000 00000000311 13003165452 0020612 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function repeat(str, count) {
var res = '';
while (count > 0) {
if (count & 1) {
res += str;
}
count >>= 1;
str += str;
}
return res;
};
repeat-string-1.6.1/benchmark/fixtures/ 0000775 0000000 0000000 00000000000 13003165452 0020105 5 ustar 00root root 0000000 0000000 repeat-string-1.6.1/benchmark/fixtures/0.js 0000775 0000000 0000000 00000000053 13003165452 0020603 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['afa', 0]; repeat-string-1.6.1/benchmark/fixtures/1.js 0000775 0000000 0000000 00000000053 13003165452 0020604 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['abc', 1]; repeat-string-1.6.1/benchmark/fixtures/10.js 0000664 0000000 0000000 00000000056 13003165452 0020664 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['abcabc', 5]; repeat-string-1.6.1/benchmark/fixtures/100.js 0000775 0000000 0000000 00000000057 13003165452 0020750 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['fas', 100];
repeat-string-1.6.1/benchmark/fixtures/2.js 0000664 0000000 0000000 00000000053 13003165452 0020602 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['def', 2]; repeat-string-1.6.1/benchmark/fixtures/2000.js 0000775 0000000 0000000 00000000060 13003165452 0021023 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['lll', 2000];
repeat-string-1.6.1/benchmark/fixtures/20000.js 0000664 0000000 0000000 00000000061 13003165452 0021101 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['lll', 20000];
repeat-string-1.6.1/benchmark/fixtures/25.js 0000775 0000000 0000000 00000000054 13003165452 0020673 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['iai', 25]; repeat-string-1.6.1/benchmark/fixtures/250.js 0000775 0000000 0000000 00000000057 13003165452 0020756 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['bbb', 250];
repeat-string-1.6.1/benchmark/fixtures/3.js 0000664 0000000 0000000 00000000053 13003165452 0020603 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['ghi', 3]; repeat-string-1.6.1/benchmark/fixtures/4.js 0000664 0000000 0000000 00000000053 13003165452 0020604 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['xyz', 4]; repeat-string-1.6.1/benchmark/fixtures/5.js 0000775 0000000 0000000 00000000053 13003165452 0020610 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['fff', 5]; repeat-string-1.6.1/benchmark/fixtures/50.js 0000775 0000000 0000000 00000000056 13003165452 0020673 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = ['xyz', 50];
repeat-string-1.6.1/benchmark/helper.js 0000664 0000000 0000000 00000004005 13003165452 0020050 0 ustar 00root root 0000000 0000000 'use strict';
var fs = require('fs');
var path = require('path');
var repeat = require('repeat-string');
var isObject = require('isobject');
var text = require('text-table');
var table = [];
function bench() {
var filepath = path.join(__dirname, 'last.md');
var str = fs.readFileSync(filepath, 'utf8');
var sections = str.split(/\n(?=\n?(?:# benchmark))/);
sections.shift();
var len = sections.length;
var idx = -1;
var res = [];
while (++idx < len) {
parseSection(sections[idx].trim());
}
return text(table);
}
function parseSection(str) {
var lines = str.split('\n').filter(Boolean);
lines.pop();
if (!lines.length) return;
var heading = lines.shift().trim();
var m = /^.*\/fixtures\/([^(]+)/.exec(heading);
var title = (m ? m[1] : heading).trim();
var tok = {title: title};
tok.title = path.basename(title, path.extname(title)) + 'x';
return createLines(tok, lines);
}
function createLines(tok, lines) {
var len = lines.length;
var idx = -1;
while (++idx < len) {
var line = lines[idx];
var obj = parseStats(line);
tok[obj.name] = obj;
}
var vals = values(tok);
var max = Math.max.apply(Math, vals);
table.push([], ['# ' + tok.title])
for (var key in tok) {
if (tok.hasOwnProperty(key)) {
if (isObject(tok[key])) {
table.push(format(tok[key], max, 100));
}
}
}
}
function format(tok, max, diff) {
return [tok.name.trim(), bar(tok, max, diff).trim(), '(' + tok.val + ' ops/sec)'];
}
function parseStats(line) {
var str = line.trim();
var m = /^([^ ]+) x ([\d,.]+)/.exec(str);
var tok = {num: 0, val: ''};
if (!m) return tok;
tok.name = m[1];
tok.val = m[2];
tok.num = String(tok.val).split(',').join('');
return tok;
}
function values(obj) {
var vals = [];
for (var key in obj) {
if (key === 'title') continue;
vals.push(obj[key].num);
}
return vals;
}
function bar(tok, longest) {
return repeat('█', (tok.num / longest) * 25);
}
/**
* Expose `.bench` helper
*/
module.exports.bench = bench;
repeat-string-1.6.1/benchmark/index.js 0000775 0000000 0000000 00000001360 13003165452 0017704 0 ustar 00root root 0000000 0000000 'use strict';
var util = require('util');
var cyan = require('ansi-cyan');
var argv = require('yargs-parser')(process.argv.slice(2));
var Suite = require('benchmarked');
var suite = new Suite({
cwd: __dirname,
fixtures: 'fixtures/{2,3,10,50,250,2000,20000}.js',
code: 'code/{repeat-string,repeating,native}.js'
});
if (argv.dry) {
console.log();
suite.dryRun(function(code, fixture) {
console.log(cyan('%s > %s'), code.key, fixture.key);
var args = require(fixture.path);
var res = code.run.apply(null, args);
console.log(util.inspect(res, {depth: null}));
if (Array.isArray(res)) {
console.log();
console.log(cyan(' total:'), res.length, 'items');
}
console.log();
});
} else {
suite.run();
}
repeat-string-1.6.1/benchmark/last.md 0000664 0000000 0000000 00000003335 13003165452 0017525 0 ustar 00root root 0000000 0000000 Benchmarking: (7 of 7)
· 2
· 3
· 10
· 50
· 250
· 2000
· 20000
# benchmark/fixtures/2.js (43 B)
repeat-string x 26,953,977 ops/sec ±0.53% (86 runs sampled)
repeating x 9,855,695 ops/sec ±1.06% (89 runs sampled)
native x 19,453,895 ops/sec ±1.24% (84 runs sampled)
fastest is repeat-string
# benchmark/fixtures/3.js (43 B)
repeat-string x 19,445,252 ops/sec ±0.68% (89 runs sampled)
repeating x 8,661,565 ops/sec ±0.94% (89 runs sampled)
native x 16,020,598 ops/sec ±0.84% (87 runs sampled)
fastest is repeat-string
# benchmark/fixtures/10.js (46 B)
repeat-string x 23,792,521 ops/sec ±0.47% (91 runs sampled)
repeating x 8,571,332 ops/sec ±1.33% (90 runs sampled)
native x 14,582,955 ops/sec ±0.86% (89 runs sampled)
fastest is repeat-string
# benchmark/fixtures/50.js (46 B)
repeat-string x 23,640,179 ops/sec ±0.72% (89 runs sampled)
repeating x 5,505,509 ops/sec ±1.01% (90 runs sampled)
native x 10,085,557 ops/sec ±0.84% (89 runs sampled)
fastest is repeat-string
# benchmark/fixtures/250.js (47 B)
repeat-string x 23,489,618 ops/sec ±0.98% (88 runs sampled)
repeating x 3,962,937 ops/sec ±0.94% (92 runs sampled)
native x 7,724,892 ops/sec ±0.75% (90 runs sampled)
fastest is repeat-string
# benchmark/fixtures/2000.js (48 B)
repeat-string x 20,315,172 ops/sec ±0.78% (90 runs sampled)
repeating x 3,297,079 ops/sec ±0.91% (92 runs sampled)
native x 6,203,331 ops/sec ±0.84% (89 runs sampled)
fastest is repeat-string
# benchmark/fixtures/20000.js (49 B)
repeat-string x 23,382,915 ops/sec ±0.67% (88 runs sampled)
repeating x 2,980,058 ops/sec ±0.73% (89 runs sampled)
native x 5,578,808 ops/sec ±0.79% (89 runs sampled)
fastest is repeat-string
repeat-string-1.6.1/bower.json 0000664 0000000 0000000 00000001451 13003165452 0016314 0 ustar 00root root 0000000 0000000 {
"name": "repeat-string",
"description": "Repeat the given string n times. Fastest implementation for repeating a string.",
"repository": "jonschlinkert/repeat-string",
"license": "MIT",
"homepage": "https://github.com/jonschlinkert/repeat-string",
"authors": [
"Jon Schlinkert (http://github.com/jonschlinkert)"
],
"main": [
"index.js"
],
"devDependencies": {
"benchmarked": "^0.1.5",
"chalk": "^1.1.1",
"glob": "^7.0.0",
"gulp-format-md": "^0.1.7",
"mocha": "^2.4.5",
"repeating": "^2.0.0",
"should": "^8.2.2"
},
"keywords": [
"fast",
"fastest",
"fill",
"left",
"left-pad",
"multiple",
"pad",
"padding",
"repeat",
"repeating",
"repetition",
"right",
"right-pad",
"string",
"times"
]
} repeat-string-1.6.1/component.json 0000664 0000000 0000000 00000001022 13003165452 0017172 0 ustar 00root root 0000000 0000000 {
"name": "repeat-string",
"description": "Repeat the given string n times. Fastest implementation for repeating a string.",
"version": "1.5.0",
"repository": "https://github.com/jonschlinkert/repeat-string",
"license": "MIT",
"main": "index.js",
"scripts": [
"index.js"
],
"keywords": [
"fast",
"fastest",
"fill",
"left",
"left-pad",
"multiple",
"pad",
"padding",
"repetition",
"repeat",
"repeating",
"right",
"right-pad",
"string",
"times"
]
}
repeat-string-1.6.1/index.js 0000664 0000000 0000000 00000002275 13003165452 0015755 0 ustar 00root root 0000000 0000000 /*!
* repeat-string
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
/**
* Results cache
*/
var res = '';
var cache;
/**
* Expose `repeat`
*/
module.exports = repeat;
/**
* Repeat the given `string` the specified `number`
* of times.
*
* **Example:**
*
* ```js
* var repeat = require('repeat-string');
* repeat('A', 5);
* //=> AAAAA
* ```
*
* @param {String} `string` The string to repeat
* @param {Number} `number` The number of times to repeat the string
* @return {String} Repeated string
* @api public
*/
function repeat(str, num) {
if (typeof str !== 'string') {
throw new TypeError('expected a string');
}
// cover common, quick use cases
if (num === 1) return str;
if (num === 2) return str + str;
var max = str.length * num;
if (cache !== str || typeof cache === 'undefined') {
cache = str;
res = '';
} else if (res.length >= max) {
return res.substr(0, max);
}
while (max > res.length && num > 1) {
if (num & 1) {
res += str;
}
num >>= 1;
str += str;
}
res += str;
res = res.substr(0, max);
return res;
}
repeat-string-1.6.1/package.json 0000664 0000000 0000000 00000003303 13003165452 0016567 0 ustar 00root root 0000000 0000000 {
"name": "repeat-string",
"description": "Repeat the given string n times. Fastest implementation for repeating a string.",
"version": "1.6.1",
"homepage": "https://github.com/jonschlinkert/repeat-string",
"author": "Jon Schlinkert (http://github.com/jonschlinkert)",
"contributors": [
"Brian Woodward (https://github.com/doowb)",
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Linus Unnebäck (http://linus.unnebäck.se)",
"Thijs Busser (http://tbusser.net)",
"Titus (wooorm.com)"
],
"repository": "jonschlinkert/repeat-string",
"bugs": {
"url": "https://github.com/jonschlinkert/repeat-string/issues"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=0.10"
},
"scripts": {
"test": "mocha"
},
"devDependencies": {
"ansi-cyan": "^0.1.1",
"benchmarked": "^0.2.5",
"gulp-format-md": "^0.1.11",
"isobject": "^2.1.0",
"mocha": "^3.1.2",
"repeating": "^3.0.0",
"text-table": "^0.2.0",
"yargs-parser": "^4.0.2"
},
"keywords": [
"fast",
"fastest",
"fill",
"left",
"left-pad",
"multiple",
"pad",
"padding",
"repeat",
"repeating",
"repetition",
"right",
"right-pad",
"string",
"times"
],
"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"related": {
"list": [
"repeat-element"
]
},
"helpers": [
"./benchmark/helper.js"
],
"reflinks": [
"verb"
]
}
}
repeat-string-1.6.1/test.js 0000664 0000000 0000000 00000004357 13003165452 0015630 0 ustar 00root root 0000000 0000000 /*!
* repeat-string
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var repeat = require('./');
describe('repeat', function() {
it('should return an empty string when a number is not given:', function() {
assert.equal(repeat('a'), '');
});
it('should return an empty string when zero or null is given as the number:', function() {
assert.equal(repeat('', 0), '');
assert.equal(repeat('a', 0), '');
assert.equal(repeat('', null), '');
assert.equal(repeat('a', null), '');
});
it('should repeat the given string n times', function() {
assert.equal(repeat(' ', 0), '');
assert.equal(repeat('a', 0), '');
assert.equal(repeat('a', 1), 'a');
assert.equal(repeat('a', 2), 'aa');
assert.equal(repeat('a', 3), 'aaa');
assert.equal(repeat(' ', 3), ' ');
assert.equal(repeat('a ', 3), 'a a a ');
assert.equal(repeat('a', 10), 'aaaaaaaaaa');
assert.equal(repeat('b ', 10), 'b b b b b b b b b b ');
assert.equal(repeat('a ', 10), 'a a a a a a a a a a ');
assert.equal(repeat('abc ', 25), 'abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc ');
});
it('should allow the multiplier to be a string:', function() {
assert.equal(repeat('a', '0'), '');
assert.equal(repeat('a', '1'), 'a');
assert.equal(repeat('a', '2'), 'aa');
assert.equal(repeat('a', '10'), 'aaaaaaaaaa');
assert.equal(repeat('b ', '10'), 'b b b b b b b b b b ');
assert.equal(repeat('a ', '10'), 'a a a a a a a a a a ');
});
it('should cache strings until the string changes:', function() {
assert.equal(repeat('a', '5'), 'aaaaa');
assert.equal(repeat('b ', '5'), 'b b b b b ');
assert.equal(repeat('a ', '5'), 'a a a a a ');
assert.equal(repeat('c ', '5'), 'c c c c c ');
assert.equal(repeat('a ', '5'), 'a a a a a ');
assert.equal(repeat('b ', '5'), 'b b b b b ');
});
it('should throw an error when no string is given:', function() {
assert.throws(function() {repeat(10); }, /expected a string/);
assert.throws(function() {repeat(null); }, /expected a string/);
});
});