[Pkg-javascript-commits] [node-repeat-string] 01/04: Import Upstream version 1.5.4
Praveen Arimbrathodiyil
praveen at moszumanska.debian.org
Sun Oct 16 11:04:10 UTC 2016
This is an automated email from the git hooks/post-receive script.
praveen pushed a commit to branch master
in repository node-repeat-string.
commit e8a9a933c41d6fd3d062fcf40dfa525cc9100731
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date: Sun Oct 16 14:48:22 2016 +0530
Import Upstream version 1.5.4
---
.editorconfig | 22 +++++
.eslintrc.json | 122 +++++++++++++++++++++++++++
.gitattributes | 10 +++
.gitignore | 54 ++++++++++++
.travis.yml | 12 +++
.verb.md | 19 +++++
LICENSE | 24 ++++++
README.md | 118 ++++++++++++++++++++++++++
benchmark/check.js | 37 ++++++++
benchmark/code/add.js | 35 ++++++++
benchmark/code/array.js | 7 ++
benchmark/code/for-bitwise.js | 17 ++++
benchmark/code/for-join.js | 8 ++
benchmark/code/for-str-cache-2.js | 36 ++++++++
benchmark/code/for-str-cache.js | 29 +++++++
benchmark/code/for-str.js | 9 ++
benchmark/code/native.js | 5 ++
benchmark/code/new-array-for.js | 8 ++
benchmark/code/new-array-join.js | 6 ++
benchmark/code/repeat-string-1.3.0.js | 29 +++++++
benchmark/code/repeat-string.js | 3 +
benchmark/code/repeating.js | 3 +
benchmark/code/unshift.js | 11 +++
benchmark/code/while-array-1.js | 9 ++
benchmark/code/while-array-2.js | 11 +++
benchmark/code/while-array-3.js | 12 +++
benchmark/code/while-bitwise.js | 17 ++++
benchmark/code/while-square-root.js | 16 ++++
benchmark/code/while-str-stack.js | 14 ++++
benchmark/code/while-str.js | 9 ++
benchmark/code/while.js | 15 ++++
benchmark/exp.js | 23 +++++
benchmark/fixtures/0.js | 3 +
benchmark/fixtures/1.js | 3 +
benchmark/fixtures/100.js | 4 +
benchmark/fixtures/2.js | 3 +
benchmark/fixtures/2000.js | 4 +
benchmark/fixtures/20000.js | 4 +
benchmark/fixtures/25.js | 3 +
benchmark/fixtures/250.js | 4 +
benchmark/fixtures/3.js | 3 +
benchmark/fixtures/4.js | 3 +
benchmark/fixtures/5.js | 3 +
benchmark/fixtures/50.js | 4 +
benchmark/index.js | 12 +++
benchmark/last.md | 24 ++++++
benchmark/staging/fns.js | 154 ++++++++++++++++++++++++++++++++++
benchmark/staging/fns2.js | 46 ++++++++++
bower.json | 39 +++++++++
component.json | 28 +++++++
index.js | 68 +++++++++++++++
package.json | 66 +++++++++++++++
test.js | 62 ++++++++++++++
53 files changed, 1290 insertions(+)
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..991900b
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,22 @@
+# http://editorconfig.org
+root = true
+
+[*]
+indent_style = space
+end_of_line = lf
+charset = utf-8
+indent_size = 2
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false
+insert_final_newline = false
+
+[test/**]
+trim_trailing_whitespace = false
+insert_final_newline = false
+
+[templates/**]
+trim_trailing_whitespace = false
+insert_final_newline = false
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..948dbdb
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,122 @@
+{
+ "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"]
+ }
+}
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..4a3f1d3
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,10 @@
+# Enforce Unix newlines
+* text eol=lf
+
+# binaries
+*.ai binary
+*.psd binary
+*.jpg binary
+*.gif binary
+*.png binary
+*.jpeg binary
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ed2333b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,54 @@
+# Numerous always-ignore extensions
+*.DS_Store
+*.csv
+*.dat
+*.diff
+*.err
+*.gz
+*.log
+*.orig
+*.out
+*.pid
+*.rej
+*.seed
+*.swo
+*.swp
+*.vi
+*.yo-rc.json
+*.zip
+*~
+.ruby-version
+lib-cov
+
+# OS or Editor folders
+*.esproj
+*.sublime-project
+*.sublime-workspace
+._*
+.cache
+.DS_Store
+.idea
+.project
+.settings
+.tmproj
+nbproject
+Thumbs.db
+
+# Komodo
+*.komodoproject
+.komodotools
+
+# grunt-html-validation
+validation-status.json
+validation-report.json
+
+# Vendor packages
+node_modules
+bower_components
+vendor
+
+# General folders and files to ignore
+_gh_pages
+tmp
+temp
+TODO.md
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..09768f0
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,12 @@
+sudo: false
+language: node_js
+node_js:
+ - "stable"
+ - "5"
+ - "4"
+ - "0.12"
+ - "0.10"
+matrix:
+ fast_finish: true
+ allow_failures:
+ - node_js: "0.10"
diff --git a/.verb.md b/.verb.md
new file mode 100644
index 0000000..74f7c7e
--- /dev/null
+++ b/.verb.md
@@ -0,0 +1,19 @@
+## 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
+{%= docs('benchmark/last.md') %}
+```
+
+**Run the benchmarks**
+
+Install dev dependencies:
+
+```sh
+npm i -d && node benchmark
+```
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..5a9956a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..975c2be
--- /dev/null
+++ b/README.md
@@ -0,0 +1,118 @@
+# repeat-string [![NPM version](https://img.shields.io/npm/v/repeat-string.svg)](https://www.npmjs.com/package/repeat-string) [![Build Status](https://img.shields.io/travis/jonschlinkert/repeat-string.svg)](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 repeat-string --save
+```
+
+## Usage
+
+### [repeat](index.js#L41)
+
+Repeat the given `string` the specified `number` of times.
+
+**Example:**
+
+**Params**
+
+* `string` **{String}**: The string to repeat
+* `number` **{Number}**: The number of times to repeat the string
+* `returns` **{String}**: Repeated string
+
+**Example**
+
+```js
+var repeat = require('repeat-string');
+repeat('A', 5);
+//=> AAAAA
+```
+
+## Benchmarks
+
+Repeat string is significantly faster than the native method (which is itself faster than [repeating](https://github.com/sindresorhus/repeating)):
+
+```sh
+#1: 5
+ native x 10,484,023 ops/sec ±1.24% (89 runs sampled)
+ repeat-string x 16,189,255 ops/sec ±1.05% (91 runs sampled)
+ repeating x 9,051,715 ops/sec ±1.18% (90 runs sampled)
+
+#2: 50
+ native x 7,975,566 ops/sec ±1.29% (91 runs sampled)
+ repeat-string x 15,317,972 ops/sec ±1.16% (87 runs sampled)
+ repeating x 6,279,112 ops/sec ±1.29% (89 runs sampled)
+
+#3: 250
+ native x 6,212,752 ops/sec ±1.33% (91 runs sampled)
+ repeat-string x 14,565,168 ops/sec ±0.83% (93 runs sampled)
+ repeating x 5,787,124 ops/sec ±1.25% (92 runs sampled)
+
+#4: 2000
+ native x 4,912,163 ops/sec ±1.27% (91 runs sampled)
+ repeat-string x 17,129,748 ops/sec ±1.01% (91 runs sampled)
+ repeating x 4,613,043 ops/sec ±1.37% (91 runs sampled)
+
+#5: 20000
+ native x 4,506,624 ops/sec ±1.33% (90 runs sampled)
+ repeat-string x 14,877,672 ops/sec ±1.00% (93 runs sampled)
+ repeating x 4,305,756 ops/sec ±1.36% (89 runs sampled)
+```
+
+**Run the benchmarks**
+
+Install dev dependencies:
+
+```sh
+npm i -d && node benchmark
+```
+
+## 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)
+
+## Contributing
+
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/repeat-string/issues/new).
+
+## Building docs
+
+Generate readme and API documentation with [verb](https://github.com/verbose/verb):
+
+```sh
+$ npm install verb && npm run docs
+```
+
+Or, if [verb](https://github.com/verbose/verb) is installed globally:
+
+```sh
+$ 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](https://github.com/verbose/verb), v0.9.0, on February 29, 2016._
\ No newline at end of file
diff --git a/benchmark/check.js b/benchmark/check.js
new file mode 100755
index 0000000..5d6a3af
--- /dev/null
+++ b/benchmark/check.js
@@ -0,0 +1,37 @@
+'use strict';
+
+var chalk = require('chalk');
+var path = require('path');
+var glob = require('glob');
+
+/**
+ * Sanity check. Run to ensure that all fns return the same result.
+ */
+
+var fixtures = glob.sync(__dirname + '/fixtures/*.js').map(require);
+var expected = [0, 3, 300, 6, 6000, 60000, 75, 750, 9, 12, 15, 150];
+
+glob.sync(__dirname + '/code/*.js').forEach(function (fp) {
+ var fn = require(path.resolve(__dirname, 'code', fp));
+ var name = path.basename(fp, path.extname(fp));
+ var problems = [];
+
+ fixtures.forEach(function (fixture, idx) {
+ var answer = fn.apply(fn, fixture).length;
+
+ if (answer !== expected[idx]) {
+ problems.push(['repeat(' + fixture.join(', ') + ').length', answer, expected[idx]]);
+ }
+ });
+
+ if (problems.length === 0) {
+ console.log(' ' + chalk.bold.green('✔') + ' ' + chalk.bold(name));
+ } else {
+ console.log(' ' + chalk.bold.red('✖') + ' ' + chalk.bold(name));
+
+ problems.forEach(function (item, idx, arr) {
+ var str = item[0] + ' gave ' + item[1] + ', expected ' + item[2];
+ console.log((idx === arr.length - 1 ? ' ┗ ' : ' ┣ ') + chalk.red(str));
+ });
+ }
+});
diff --git a/benchmark/code/add.js b/benchmark/code/add.js
new file mode 100644
index 0000000..8630c58
--- /dev/null
+++ b/benchmark/code/add.js
@@ -0,0 +1,35 @@
+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;
diff --git a/benchmark/code/array.js b/benchmark/code/array.js
new file mode 100644
index 0000000..f0627ad
--- /dev/null
+++ b/benchmark/code/array.js
@@ -0,0 +1,7 @@
+'use strict';
+
+module.exports = function repeat(str, num) {
+ var arr = [];
+ arr[num] = '';
+ return arr.join(str);
+};
\ No newline at end of file
diff --git a/benchmark/code/for-bitwise.js b/benchmark/code/for-bitwise.js
new file mode 100644
index 0000000..a74e3c0
--- /dev/null
+++ b/benchmark/code/for-bitwise.js
@@ -0,0 +1,17 @@
+'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;
+}
\ No newline at end of file
diff --git a/benchmark/code/for-join.js b/benchmark/code/for-join.js
new file mode 100755
index 0000000..523b51d
--- /dev/null
+++ b/benchmark/code/for-join.js
@@ -0,0 +1,8 @@
+'use strict';
+
+module.exports = function repeat(val, num) {
+ num += 1;
+ var arr;
+ for (arr = []; 0 < num; num -= 1, arr[num] = '');
+ return arr.join(val);
+};
diff --git a/benchmark/code/for-str-cache-2.js b/benchmark/code/for-str-cache-2.js
new file mode 100755
index 0000000..e66d605
--- /dev/null
+++ b/benchmark/code/for-str-cache-2.js
@@ -0,0 +1,36 @@
+'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);
+}
diff --git a/benchmark/code/for-str-cache.js b/benchmark/code/for-str-cache.js
new file mode 100755
index 0000000..977883b
--- /dev/null
+++ b/benchmark/code/for-str-cache.js
@@ -0,0 +1,29 @@
+'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);
+};
+
diff --git a/benchmark/code/for-str.js b/benchmark/code/for-str.js
new file mode 100755
index 0000000..a84cd11
--- /dev/null
+++ b/benchmark/code/for-str.js
@@ -0,0 +1,9 @@
+'use strict';
+
+module.exports = function repeat(val, amount) {
+ var res = '';
+ for (var i = 0; i < amount; i++) {
+ res += val;
+ }
+ return res;
+};
diff --git a/benchmark/code/native.js b/benchmark/code/native.js
new file mode 100644
index 0000000..7629dd8
--- /dev/null
+++ b/benchmark/code/native.js
@@ -0,0 +1,5 @@
+'use strict';
+
+module.exports = function repeat(str, num) {
+ return str.repeat(num);
+};
diff --git a/benchmark/code/new-array-for.js b/benchmark/code/new-array-for.js
new file mode 100755
index 0000000..f0bd1a6
--- /dev/null
+++ b/benchmark/code/new-array-for.js
@@ -0,0 +1,8 @@
+'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);
+};
diff --git a/benchmark/code/new-array-join.js b/benchmark/code/new-array-join.js
new file mode 100755
index 0000000..885dd8e
--- /dev/null
+++ b/benchmark/code/new-array-join.js
@@ -0,0 +1,6 @@
+'use strict';
+
+module.exports = function repeat(val, num) {
+ if (arguments.length === 1) return '';
+ return new Array(num + 1).join(val);
+};
diff --git a/benchmark/code/repeat-string-1.3.0.js b/benchmark/code/repeat-string-1.3.0.js
new file mode 100755
index 0000000..e28b72a
--- /dev/null
+++ b/benchmark/code/repeat-string-1.3.0.js
@@ -0,0 +1,29 @@
+'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);
+};
diff --git a/benchmark/code/repeat-string.js b/benchmark/code/repeat-string.js
new file mode 100755
index 0000000..0f85e82
--- /dev/null
+++ b/benchmark/code/repeat-string.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = require('../..');
\ No newline at end of file
diff --git a/benchmark/code/repeating.js b/benchmark/code/repeating.js
new file mode 100755
index 0000000..077d10b
--- /dev/null
+++ b/benchmark/code/repeating.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = require('repeating');
diff --git a/benchmark/code/unshift.js b/benchmark/code/unshift.js
new file mode 100755
index 0000000..8ca5b71
--- /dev/null
+++ b/benchmark/code/unshift.js
@@ -0,0 +1,11 @@
+'use strict';
+
+module.exports = function repeat(val, amount) {
+ var res = [];
+
+ while (amount--) {
+ res.unshift(val);
+ }
+
+ return res.join('');
+};
diff --git a/benchmark/code/while-array-1.js b/benchmark/code/while-array-1.js
new file mode 100755
index 0000000..9f49c77
--- /dev/null
+++ b/benchmark/code/while-array-1.js
@@ -0,0 +1,9 @@
+'use strict';
+
+module.exports = function repeat(val, num) {
+ var arr = [];
+ while (num--) {
+ arr[num] = val;
+ }
+ return arr.join('');
+};
\ No newline at end of file
diff --git a/benchmark/code/while-array-2.js b/benchmark/code/while-array-2.js
new file mode 100755
index 0000000..72e0dcb
--- /dev/null
+++ b/benchmark/code/while-array-2.js
@@ -0,0 +1,11 @@
+'use strict';
+
+module.exports = function repeat(val, num) {
+ var arr = [];
+ var i = 0;
+
+ while (num--) {
+ arr[i++] = val;
+ }
+ return arr.join('');
+};
\ No newline at end of file
diff --git a/benchmark/code/while-array-3.js b/benchmark/code/while-array-3.js
new file mode 100755
index 0000000..6a6acff
--- /dev/null
+++ b/benchmark/code/while-array-3.js
@@ -0,0 +1,12 @@
+'use strict';
+
+module.exports = function(val, num) {
+ return repeat(val, num, []).join('');
+};
+
+function repeat(val, num, arr) {
+ while (num--) {
+ arr[num] = val;
+ }
+ return arr;
+}
\ No newline at end of file
diff --git a/benchmark/code/while-bitwise.js b/benchmark/code/while-bitwise.js
new file mode 100644
index 0000000..8f71249
--- /dev/null
+++ b/benchmark/code/while-bitwise.js
@@ -0,0 +1,17 @@
+'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;
+}
\ No newline at end of file
diff --git a/benchmark/code/while-square-root.js b/benchmark/code/while-square-root.js
new file mode 100644
index 0000000..9f18f44
--- /dev/null
+++ b/benchmark/code/while-square-root.js
@@ -0,0 +1,16 @@
+'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);
+};
\ No newline at end of file
diff --git a/benchmark/code/while-str-stack.js b/benchmark/code/while-str-stack.js
new file mode 100644
index 0000000..b7f7d2f
--- /dev/null
+++ b/benchmark/code/while-str-stack.js
@@ -0,0 +1,14 @@
+'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);
+};
\ No newline at end of file
diff --git a/benchmark/code/while-str.js b/benchmark/code/while-str.js
new file mode 100755
index 0000000..4138f11
--- /dev/null
+++ b/benchmark/code/while-str.js
@@ -0,0 +1,9 @@
+'use strict';
+
+module.exports = function repeat(val, amount) {
+ var str = '';
+ while (amount--) {
+ str += val;
+ }
+ return str;
+};
\ No newline at end of file
diff --git a/benchmark/code/while.js b/benchmark/code/while.js
new file mode 100755
index 0000000..5a75b27
--- /dev/null
+++ b/benchmark/code/while.js
@@ -0,0 +1,15 @@
+'use strict';
+
+module.exports = function repeat(str, count) {
+ var res = '';
+
+ while (count > 0) {
+ if (count & 1) {
+ res += str;
+ }
+ count >>= 1;
+ str += str;
+ }
+
+ return res;
+};
diff --git a/benchmark/exp.js b/benchmark/exp.js
new file mode 100755
index 0000000..c9da78d
--- /dev/null
+++ b/benchmark/exp.js
@@ -0,0 +1,23 @@
+'use resict';
+
+// var chalk = require('chalk');
+// var path = require('path');
+// var glob = require('glob');
+
+// glob.sync(__dirname + '/code/*.js').forEach(function(fp) {
+// var pad = require(path.resolve(__dirname, 'code', fp));
+// console.log(pad('1', 3));
+// });
+
+function repeat(str, num) {
+ var max = str.length * num;
+ num = Math.ceil(Math.sqrt(num));
+
+ while (num--) {
+ str += str;
+ }
+
+ return str.slice(0, max);
+}
+
+console.log(repeat('foo', 6))
\ No newline at end of file
diff --git a/benchmark/fixtures/0.js b/benchmark/fixtures/0.js
new file mode 100755
index 0000000..53f16e3
--- /dev/null
+++ b/benchmark/fixtures/0.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = ['afa', 0];
\ No newline at end of file
diff --git a/benchmark/fixtures/1.js b/benchmark/fixtures/1.js
new file mode 100755
index 0000000..01a8a3c
--- /dev/null
+++ b/benchmark/fixtures/1.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = ['abc', 1];
\ No newline at end of file
diff --git a/benchmark/fixtures/100.js b/benchmark/fixtures/100.js
new file mode 100755
index 0000000..87ea1f0
--- /dev/null
+++ b/benchmark/fixtures/100.js
@@ -0,0 +1,4 @@
+'use strict';
+
+module.exports = ['fas', 100];
+
diff --git a/benchmark/fixtures/2.js b/benchmark/fixtures/2.js
new file mode 100644
index 0000000..a0608a3
--- /dev/null
+++ b/benchmark/fixtures/2.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = ['def', 2];
\ No newline at end of file
diff --git a/benchmark/fixtures/2000.js b/benchmark/fixtures/2000.js
new file mode 100755
index 0000000..2769f08
--- /dev/null
+++ b/benchmark/fixtures/2000.js
@@ -0,0 +1,4 @@
+'use strict';
+
+module.exports = ['lll', 2000];
+
diff --git a/benchmark/fixtures/20000.js b/benchmark/fixtures/20000.js
new file mode 100644
index 0000000..fcc0285
--- /dev/null
+++ b/benchmark/fixtures/20000.js
@@ -0,0 +1,4 @@
+'use strict';
+
+module.exports = ['lll', 20000];
+
diff --git a/benchmark/fixtures/25.js b/benchmark/fixtures/25.js
new file mode 100755
index 0000000..aad5d68
--- /dev/null
+++ b/benchmark/fixtures/25.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = ['iai', 25];
\ No newline at end of file
diff --git a/benchmark/fixtures/250.js b/benchmark/fixtures/250.js
new file mode 100755
index 0000000..6751c83
--- /dev/null
+++ b/benchmark/fixtures/250.js
@@ -0,0 +1,4 @@
+'use strict';
+
+module.exports = ['bbb', 250];
+
diff --git a/benchmark/fixtures/3.js b/benchmark/fixtures/3.js
new file mode 100644
index 0000000..3d143fb
--- /dev/null
+++ b/benchmark/fixtures/3.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = ['ghi', 3];
\ No newline at end of file
diff --git a/benchmark/fixtures/4.js b/benchmark/fixtures/4.js
new file mode 100644
index 0000000..ad88e61
--- /dev/null
+++ b/benchmark/fixtures/4.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = ['xyz', 4];
\ No newline at end of file
diff --git a/benchmark/fixtures/5.js b/benchmark/fixtures/5.js
new file mode 100755
index 0000000..6c32928
--- /dev/null
+++ b/benchmark/fixtures/5.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = ['fff', 5];
\ No newline at end of file
diff --git a/benchmark/fixtures/50.js b/benchmark/fixtures/50.js
new file mode 100755
index 0000000..09b9ca2
--- /dev/null
+++ b/benchmark/fixtures/50.js
@@ -0,0 +1,4 @@
+'use strict';
+
+module.exports = ['xyz', 50];
+
diff --git a/benchmark/index.js b/benchmark/index.js
new file mode 100755
index 0000000..d3c2b84
--- /dev/null
+++ b/benchmark/index.js
@@ -0,0 +1,12 @@
+'use strict';
+
+var Suite = require('benchmarked');
+
+var suite = new Suite({
+ result: false,
+ fixtures: 'fixtures/{5,50,250,2000,20000}.js',
+ add: 'code/{repeat-string,repeating,native}.js',
+ cwd: __dirname
+});
+
+suite.run();
diff --git a/benchmark/last.md b/benchmark/last.md
new file mode 100644
index 0000000..30f4e4c
--- /dev/null
+++ b/benchmark/last.md
@@ -0,0 +1,24 @@
+#1: 5
+ native x 10,484,023 ops/sec ±1.24% (89 runs sampled)
+ repeat-string x 16,189,255 ops/sec ±1.05% (91 runs sampled)
+ repeating x 9,051,715 ops/sec ±1.18% (90 runs sampled)
+
+#2: 50
+ native x 7,975,566 ops/sec ±1.29% (91 runs sampled)
+ repeat-string x 15,317,972 ops/sec ±1.16% (87 runs sampled)
+ repeating x 6,279,112 ops/sec ±1.29% (89 runs sampled)
+
+#3: 250
+ native x 6,212,752 ops/sec ±1.33% (91 runs sampled)
+ repeat-string x 14,565,168 ops/sec ±0.83% (93 runs sampled)
+ repeating x 5,787,124 ops/sec ±1.25% (92 runs sampled)
+
+#4: 2000
+ native x 4,912,163 ops/sec ±1.27% (91 runs sampled)
+ repeat-string x 17,129,748 ops/sec ±1.01% (91 runs sampled)
+ repeating x 4,613,043 ops/sec ±1.37% (91 runs sampled)
+
+#5: 20000
+ native x 4,506,624 ops/sec ±1.33% (90 runs sampled)
+ repeat-string x 14,877,672 ops/sec ±1.00% (93 runs sampled)
+ repeating x 4,305,756 ops/sec ±1.36% (89 runs sampled)
\ No newline at end of file
diff --git a/benchmark/staging/fns.js b/benchmark/staging/fns.js
new file mode 100755
index 0000000..bdfd010
--- /dev/null
+++ b/benchmark/staging/fns.js
@@ -0,0 +1,154 @@
+/**
+ * Pad a number with leading zeros to "pad" places:
+ *
+ * @param number: The number to pad
+ * @param pad: The maximum number of leading zeros
+ */
+
+
+
+// http://jsperf.com/ways-to-0-pad-a-number/19
+function padNumberLoop(val, amount) {
+ var res = '' + val;
+
+ while (res.length < amount) {
+ res = '0' + res;
+ }
+ return res;
+}
+
+// padStr is the zero-pad string, e.g.: "0000"
+// http://jsperf.com/ways-to-0-pad-a-number/19
+function padNumberString(number, padStr) {
+ var len = padStr.length;
+ number = number.toString();
+ return number.length >= len ? number : (padStr + number).slice(-len);
+}
+
+
+
+function pad(number, amount) {
+ var res = '' + number;
+ var len = res.length;
+ while (len < amount) {
+ res.unshift(0);
+ }
+ return res.join('');
+}
+
+function pad(number, amount) {
+ var res = '' + number;
+ var len = res.length;
+ var str = '';
+
+ while (len < amount) {
+ str += '0';
+ }
+ return str + res;
+}
+
+function pad(number, amount) {
+ var res = '' + number;
+ var len = res.length;
+
+ while (len < amount) {
+ res = '0' + res;
+ }
+
+ return res;
+}
+
+
+// http://jsperf.com/ways-to-0-pad-a-number/19
+function padWhile(num, count) {
+ var pad = count - (num + '').length;
+ while (--pad > -1) {
+ num = '0' + num;
+ }
+ return num;
+};
+
+// http://jsperf.com/ways-to-0-pad-a-number/19
+String.prototype.padLeft = function(ch, len) {
+ return this.length >= len ? this : (ch + this).padLeft(ch, len)
+}
+
+// http://twitter.com/cowboy/status/15344233981
+// http://jsperf.com/pad-number/3
+function pad(n, d) {
+ return Array(Math.max(0, d - (n + '').length + 1)).join(0) + n;
+};
+
+
+
+// http://jsperf.com/pad-number/3
+function pad4(n, d) {
+ return ('00000000000000' + n).slice(-d);
+}
+
+
+/**
+ * http://jsperf.com/string-padding-methods
+ */
+
+String.prototype.lpad = function(padString, length) {
+ var str = this;
+ while (str.length < length) {
+ str = padString + str;
+ }
+ return str;
+};
+
+String.prototype.rpad = function(padString, length) {
+ var str = this;
+ while (str.length < length) {
+ str = str + padString;
+ }
+ return str;
+};
+
+function padLeft(str, padString, length) {
+ while (str.length < length) {
+ str = padString + str;
+ }
+ return str;
+};
+
+// #1 tied for fastest
+function padRight(str, padString, length) {
+ while (str.length < length) {
+ str = str + padString;
+ }
+ return str;
+};
+
+// #1 tied for fastest
+function padString(str, padString, length, left) {
+ while (str.length < length) {
+ str = left ? str + padString : padString + str;
+ }
+ return str;
+};
+
+function padArray(str, padString, length, left) {
+ return (left ? str : '') + (new Array(length - str.length).join(padString)) + (left ? '' : str);
+}
+
+
+function padArrayLeft(str, padString, length) {
+ return str + (new Array(length - str.length).join(padString));
+};
+
+function padArrayRight(str, padString, length) {
+ return new Array(length - str.length).join(padString) + str;
+};
+
+
+function pad(val, len) {
+ var zeros = '0000000000000000000000000000000000000000000000000000000000000000';
+ return zeros.substr(0, len) + val;
+}
+
+function pad(val, amount) {
+ return ('0000000000000000' + val).slice(-amount);
+}
\ No newline at end of file
diff --git a/benchmark/staging/fns2.js b/benchmark/staging/fns2.js
new file mode 100755
index 0000000..89c4ce9
--- /dev/null
+++ b/benchmark/staging/fns2.js
@@ -0,0 +1,46 @@
+var zeros = '0000000000000000';
+
+// ===Method 1===:
+var str = 'test';
+// zerosding length = zeros.length
+zeros.length
+//=> 16
+
+// zeros-left
+str + zeros.substr(str.length);
+//=> 'test000000000000'
+
+// zeros-left
+zeros.substr(str.length) + str;
+//=> '000000000000test'
+
+// ===Method 2 AND 3===:
+
+var str = "test";
+(zeros + str).slice(-16)
+//=> '000000000000test'
+
+// equiv to:
+// speed tests http://jsperf.com/zerosding6000
+var str = "test";
+(zeros + str).substr(-16)
+//=> '000000000000test'
+
+//zerosding right
+var str = "test";
+(str + zeros).substr(0, 16)
+//=> 'test000000000000'
+
+var str = "test";
+(str + zeros).slice(0, 16)
+//=> 'test000000000000'
+
+
+var str = "test";
+(str + zeros).slice(-16)
+//=> '0000000000000000'
+
+var str = "test";
+(str + zeros).substr(-16)
+
+//=> '0000000000000000'
\ No newline at end of file
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..a433a35
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,39 @@
+{
+ "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"
+ ]
+}
\ No newline at end of file
diff --git a/component.json b/component.json
new file mode 100644
index 0000000..014bdff
--- /dev/null
+++ b/component.json
@@ -0,0 +1,28 @@
+{
+ "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"
+ ]
+}
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..496c6db
--- /dev/null
+++ b/index.js
@@ -0,0 +1,68 @@
+/*!
+ * repeat-string <https://github.com/jonschlinkert/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);
+}
+
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..5024292
--- /dev/null
+++ b/package.json
@@ -0,0 +1,66 @@
+{
+ "name": "repeat-string",
+ "description": "Repeat the given string n times. Fastest implementation for repeating a string.",
+ "version": "1.5.4",
+ "homepage": "https://github.com/jonschlinkert/repeat-string",
+ "author": "Jon Schlinkert (http://github.com/jonschlinkert)",
+ "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": {
+ "benchmarked": "^0.1.5",
+ "chalk": "^1.1.1",
+ "glob": "^7.0.0",
+ "gulp-format-md": "^0.1.7",
+ "mocha": "*",
+ "repeating": "^2.0.0",
+ "should": "*"
+ },
+ "keywords": [
+ "fast",
+ "fastest",
+ "fill",
+ "left",
+ "left-pad",
+ "multiple",
+ "pad",
+ "padding",
+ "repeat",
+ "repeating",
+ "repetition",
+ "right",
+ "right-pad",
+ "string",
+ "times"
+ ],
+ "verb": {
+ "related": {
+ "list": [
+ "repeat-element"
+ ]
+ },
+ "toc": false,
+ "layout": "default",
+ "tasks": [
+ "readme"
+ ],
+ "plugins": [
+ "gulp-format-md"
+ ],
+ "reflinks": [
+ "verb"
+ ]
+ }
+}
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..001bf6e
--- /dev/null
+++ b/test.js
@@ -0,0 +1,62 @@
+/*!
+ * repeat-string <https://github.com/jonschlinkert/repeat-string>
+ *
+ * Copyright (c) 2014-2015, Jon Schlinkert.
+ * Licensed under the MIT License.
+ */
+
+'use strict';
+
+require('mocha');
+require('should');
+var repeat = require('./');
+
+describe('repeat', function() {
+ it('should return an empty string when a number is not given:', function() {
+ repeat('a').should.equal('');
+ });
+
+ it('should return an empty string when zero or null is given as the number:', function() {
+ repeat('', 0).should.equal('');
+ repeat('a', 0).should.equal('');
+ repeat('', null).should.equal('');
+ repeat('a', null).should.equal('');
+ });
+
+ it('should repeat the given string n times', function() {
+ repeat(' ', 0).should.equal('');
+ repeat('a', 0).should.equal('');
+ repeat('a', 1).should.equal('a');
+ repeat('a', 2).should.equal('aa');
+ repeat('a', 3).should.equal('aaa');
+ repeat(' ', 3).should.equal(' ');
+ repeat('a ', 3).should.equal('a a a ');
+ repeat('a', 10).should.equal('aaaaaaaaaa');
+ repeat('b ', 10).should.equal('b b b b b b b b b b ');
+ repeat('a ', 10).should.equal('a a a a a a a a a a ');
+ repeat('abc ', 25).should.equal('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() {
+ repeat('a', '0').should.equal('');
+ repeat('a', '1').should.equal('a');
+ repeat('a', '2').should.equal('aa');
+ repeat('a', '10').should.equal('aaaaaaaaaa');
+ repeat('b ', '10').should.equal('b b b b b b b b b b ');
+ repeat('a ', '10').should.equal('a a a a a a a a a a ');
+ });
+
+ it('should cache strings until the string changes:', function() {
+ repeat('a', '5').should.equal('aaaaa');
+ repeat('b ', '5').should.equal('b b b b b ');
+ repeat('a ', '5').should.equal('a a a a a ');
+ repeat('c ', '5').should.equal('c c c c c ');
+ repeat('a ', '5').should.equal('a a a a a ');
+ repeat('b ', '5').should.equal('b b b b b ');
+ });
+
+ it('should throw an error when no string is given:', function() {
+ (function() {repeat(10); }).should.throw('repeat-string expects a string.');
+ (function() {repeat(null); }).should.throw('repeat-string expects a string.');
+ });
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-repeat-string.git
More information about the Pkg-javascript-commits
mailing list