pax_global_header00006660000000000000000000000064126602020270014507gustar00rootroot0000000000000052 comment=e480e85f0c17350850976f13451fcf772ffe61cd repeat-element-1.1.2/000077500000000000000000000000001266020202700144175ustar00rootroot00000000000000repeat-element-1.1.2/.editorconfig000066400000000000000000000004471266020202700171010ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false [test/fixtures/*] insert_final_newline = false trim_trailing_whitespace = false repeat-element-1.1.2/.gitattributes000066400000000000000000000003551266020202700173150ustar00rootroot00000000000000# Enforce Unix newlines *.* text eol=lf *.css text eol=lf *.html text eol=lf *.js text eol=lf *.json text eol=lf *.less text eol=lf *.md text eol=lf *.yml text eol=lf *.jpg binary *.gif binary *.png binary *.jpeg binaryrepeat-element-1.1.2/.gitignore000066400000000000000000000001701266020202700164050ustar00rootroot00000000000000*.sublime-* _gh_pages actual bower_components node_modules npm-debug.log temp test/actual tmp TODO.md vendor *.DS_Store repeat-element-1.1.2/.jshintrc000066400000000000000000000004301266020202700162410ustar00rootroot00000000000000{ "asi": false, "boss": true, "curly": true, "eqeqeq": true, "eqnull": true, "esnext": true, "immed": true, "latedef": true, "laxcomma": false, "newcap": true, "noarg": true, "node": true, "sub": true, "undef": true, "unused": true, "mocha": true }repeat-element-1.1.2/.verb.md000066400000000000000000000014211266020202700157530ustar00rootroot00000000000000# {%= name %} {%= badge("fury") %} > {%= description %} ## Install {%= include("install-npm", {save: true}) %} ## Usage ```js var repeat = require('{%= name %}'); repeat('a', 5); //=> ['a', 'a', 'a', 'a', 'a'] repeat('a', 1); //=> ['a'] repeat('a', 0); //=> [] repeat(null, 5) //» [ null, null, null, null, null ] repeat({some: 'object'}, 5) //» [ { some: 'object' }, // { some: 'object' }, // { some: 'object' }, // { some: 'object' }, // { some: 'object' } ] repeat(5, 5) //» [ 5, 5, 5, 5, 5 ] ``` ## Related projects {%= related(['repeat-string']) %} ## Running tests {%= include("tests") %} ## Contributing {%= include("contributing") %} ## Author {%= include("author") %} ## License {%= copyright() %} {%= license() %} *** {%= include("footer") %} repeat-element-1.1.2/LICENSE000066400000000000000000000020711266020202700154240ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 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-element-1.1.2/README.md000066400000000000000000000026371266020202700157060ustar00rootroot00000000000000# repeat-element [![NPM version](https://badge.fury.io/js/repeat-element.svg)](http://badge.fury.io/js/repeat-element) > Create an array by repeating the given value n times. ## Install Install with [npm](https://www.npmjs.com/) ```bash npm i repeat-element --save ``` ## Usage ```js var repeat = require('repeat-element'); repeat('a', 5); //=> ['a', 'a', 'a', 'a', 'a'] repeat('a', 1); //=> ['a'] repeat('a', 0); //=> [] repeat(null, 5) //» [ null, null, null, null, null ] repeat({some: 'object'}, 5) //» [ { some: 'object' }, // { some: 'object' }, // { some: 'object' }, // { some: 'object' }, // { some: 'object' } ] repeat(5, 5) //» [ 5, 5, 5, 5, 5 ] ``` ## Related projects [repeat-string](https://github.com/jonschlinkert/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string. ## Running tests Install dev dependencies: ```bash npm i -d && npm test ``` ## Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/repeat-element/issues) ## Author **Jon Schlinkert** + [github/jonschlinkert](https://github.com/jonschlinkert) + [twitter/jonschlinkert](http://twitter.com/jonschlinkert) ## License Copyright (c) 2015 Jon Schlinkert Released under the MIT license. *** _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on May 06, 2015._ repeat-element-1.1.2/benchmark/000077500000000000000000000000001266020202700163515ustar00rootroot00000000000000repeat-element-1.1.2/benchmark/check.js000077500000000000000000000022401266020202700177650ustar00rootroot00000000000000'use strict'; var chalk = require('chalk'); var path = require('path'); var glob = require('glob'); var repeat = require('../'); /** * Sanity check. Run to ensure that all fns return the same result. */ var fixtures = glob.sync(__dirname + '/fixtures/*.js').map(require); var expected = fixtures.map(fixture => repeat.apply(repeat, fixture).length); 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)); }); } }); repeat-element-1.1.2/benchmark/code/000077500000000000000000000000001266020202700172635ustar00rootroot00000000000000repeat-element-1.1.2/benchmark/code/array-from.js000066400000000000000000000002301266020202700216730ustar00rootroot00000000000000'use strict'; function getThis() { return this; } module.exports = function repeat(ele, num) { return Array.from({length: num}, getThis, ele); }; repeat-element-1.1.2/benchmark/code/array-map-call.js000066400000000000000000000002321266020202700224200ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { return Array.prototype.map.call([] + Array(num + 1), function () { return ele; }); }; repeat-element-1.1.2/benchmark/code/array-map-valueOf.js000066400000000000000000000002121266020202700231040ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { return Array.apply(null, Array(num)).map(String.prototype.valueOf, ele); }; repeat-element-1.1.2/benchmark/code/current.js000066400000000000000000000000431266020202700213000ustar00rootroot00000000000000module.exports = require('../..'); repeat-element-1.1.2/benchmark/code/for-concat.js000066400000000000000000000002401266020202700216500ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { var arr = []; for (var i = 0; i < num; i++) { arr = arr.concat(ele); } return arr; }; repeat-element-1.1.2/benchmark/code/for-join-1.js000077500000000000000000000002251266020202700215040ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { var arr = []; for (; 0 < num; num -= 1, arr[num] = ele); num++; return arr; }; repeat-element-1.1.2/benchmark/code/for-join-2.js000066400000000000000000000002041266020202700214770ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { var arr = []; for (; 0 < num; arr[--num] = ele); return arr; }; repeat-element-1.1.2/benchmark/code/for-length.js000066400000000000000000000004151266020202700216660ustar00rootroot00000000000000'use strict'; module.exports = repeat; function repeat(ele, num) { if (num === 0) return []; var res = [ele]; var len = res.length; if (len < num) { for (var i = num - 1 - len; i >= 0; i--) { res[i + len] = res[i % len]; } } return res; } repeat-element-1.1.2/benchmark/code/for-new-array-1.js000077500000000000000000000002341266020202700224520ustar00rootroot00000000000000module.exports = repeat; function repeat(ele, num) { var arr = new Array(num); for (var i = 0; i < num; i++) { arr[i] = ele; } return arr; } repeat-element-1.1.2/benchmark/code/for-new-array-2.js000066400000000000000000000002411266020202700224460ustar00rootroot00000000000000module.exports = repeat; function repeat(ele, num) { var arr = new Array(num); for (var i = num - 1; i >= 0; i--) { arr[i] = ele; } return arr; } repeat-element-1.1.2/benchmark/code/for-push.js000066400000000000000000000002301266020202700213570ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { var arr = []; for (var i = num; i > 0; i--) { arr.push(ele); } return arr; }; repeat-element-1.1.2/benchmark/code/new-array-map-1.js000066400000000000000000000002231266020202700224340ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { return Array.apply([], new Array(num)).map(function (nil) { return ele; }); }; repeat-element-1.1.2/benchmark/code/new-array-map-2.js000066400000000000000000000002251266020202700224370ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { return Array(num + 1).join(1).split('').map(function (nil) { return ele; }); }; repeat-element-1.1.2/benchmark/code/repeat-element.js000077500000000000000000000000611266020202700225300ustar00rootroot00000000000000'use strict'; module.exports = require('../..');repeat-element-1.1.2/benchmark/code/while-array-1.js000077500000000000000000000002111266020202700222000ustar00rootroot00000000000000'use strict'; module.exports = function repeat(val, num) { var arr = []; while (num--) { arr[num] = val; } return arr; }; repeat-element-1.1.2/benchmark/code/while-array-2.js000077500000000000000000000002261266020202700222070ustar00rootroot00000000000000'use strict'; module.exports = function repeat(val, num) { var arr = []; var i = 0; while (num--) { arr[i++] = val; } return arr; }; repeat-element-1.1.2/benchmark/code/while-array-3.js000077500000000000000000000002631266020202700222110ustar00rootroot00000000000000'use strict'; module.exports = function(val, num) { return repeat(val, num, []); }; function repeat(val, num, arr) { while (num--) { arr[num] = val; } return arr; } repeat-element-1.1.2/benchmark/code/while-bitwise.js000066400000000000000000000003511266020202700223740ustar00rootroot00000000000000 module.exports = repeat; function repeat(ele, num) { var arr = [ele]; var res = []; while (num > 0) { if (num & 1) { res.push.apply(res, arr); } num >>= 1; arr.push.apply(arr, arr); } return res; } repeat-element-1.1.2/benchmark/code/while-concat.js000077500000000000000000000002201266020202700221730ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { var res = []; while (num--) { res = res.concat(ele); } return res; }; repeat-element-1.1.2/benchmark/code/while-exp.js000066400000000000000000000002541266020202700215240ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { var res = [ele]; while (res.length < num) { res = res.concat(res); } return res.slice(0, num); }; repeat-element-1.1.2/benchmark/code/while-new-array-1.js000066400000000000000000000002161266020202700227710ustar00rootroot00000000000000module.exports = repeat; function repeat(ele, num) { var arr = new Array(num); while (num--) { arr[num] = ele; } return arr; } repeat-element-1.1.2/benchmark/code/while-new-array-2.js000066400000000000000000000002331266020202700227710ustar00rootroot00000000000000module.exports = repeat; function repeat(ele, num) { var arr = new Array(num); var i = 0; while (num--) { arr[i++] = ele; } return arr; } repeat-element-1.1.2/benchmark/code/while-push.js000066400000000000000000000002101266020202700216770ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { var arr = []; while (num--) { arr.push(ele); } return arr; }; repeat-element-1.1.2/benchmark/code/while-stack.js000066400000000000000000000003451266020202700220360ustar00rootroot00000000000000'use strict'; module.exports = function repeat(ele, num) { var res = [ele]; var max = num; while (num--) { res.push.apply(res, res); if (res.length >= max) { break; } } return res.slice(0, max); }; repeat-element-1.1.2/benchmark/code/while-unshift.js000077500000000000000000000002211266020202700224050ustar00rootroot00000000000000'use strict'; module.exports = function repeat(val, amount) { var res = []; while (amount--) { res.unshift(val); } return res; }; repeat-element-1.1.2/benchmark/fixtures/000077500000000000000000000000001266020202700202225ustar00rootroot00000000000000repeat-element-1.1.2/benchmark/fixtures/0.js000077500000000000000000000000531266020202700207200ustar00rootroot00000000000000'use strict'; module.exports = ['afa', 0];repeat-element-1.1.2/benchmark/fixtures/1.js000077500000000000000000000000531266020202700207210ustar00rootroot00000000000000'use strict'; module.exports = ['abc', 1];repeat-element-1.1.2/benchmark/fixtures/100.js000077500000000000000000000000571266020202700210650ustar00rootroot00000000000000'use strict'; module.exports = ['fas', 100]; repeat-element-1.1.2/benchmark/fixtures/2.js000066400000000000000000000000531266020202700207170ustar00rootroot00000000000000'use strict'; module.exports = ['def', 2];repeat-element-1.1.2/benchmark/fixtures/2000.js000077500000000000000000000000601266020202700211400ustar00rootroot00000000000000'use strict'; module.exports = ['lll', 2000]; repeat-element-1.1.2/benchmark/fixtures/20000.js000066400000000000000000000000611266020202700212160ustar00rootroot00000000000000'use strict'; module.exports = ['lll', 20000]; repeat-element-1.1.2/benchmark/fixtures/25.js000077500000000000000000000000541266020202700210100ustar00rootroot00000000000000'use strict'; module.exports = ['iai', 25];repeat-element-1.1.2/benchmark/fixtures/250.js000077500000000000000000000000571266020202700210730ustar00rootroot00000000000000'use strict'; module.exports = ['bbb', 250]; repeat-element-1.1.2/benchmark/fixtures/3.js000066400000000000000000000000531266020202700207200ustar00rootroot00000000000000'use strict'; module.exports = ['ghi', 3];repeat-element-1.1.2/benchmark/fixtures/4.js000066400000000000000000000000531266020202700207210ustar00rootroot00000000000000'use strict'; module.exports = ['xyz', 4];repeat-element-1.1.2/benchmark/fixtures/5.js000077500000000000000000000000531266020202700207250ustar00rootroot00000000000000'use strict'; module.exports = ['fff', 5];repeat-element-1.1.2/benchmark/fixtures/50.js000077500000000000000000000000561266020202700210100ustar00rootroot00000000000000'use strict'; module.exports = ['xyz', 50]; repeat-element-1.1.2/benchmark/index.js000077500000000000000000000003321266020202700200170ustar00rootroot00000000000000'use strict'; var Suite = require('benchmarked'); var suite = new Suite({ result: false, fixtures: 'fixtures/{3,5,25,2000}.js', add: 'code/{current,while-push-new-array}.js', cwd: __dirname }); suite.run(); repeat-element-1.1.2/benchmark/last.md000066400000000000000000000004271266020202700176410ustar00rootroot00000000000000#1: 2000.js current.js x 291,925 ops/sec ±0.66% (97 runs sampled) #2: 25.js current.js x 9,940,492 ops/sec ±0.72% (93 runs sampled) #3: 3.js current.js x 18,709,467 ops/sec ±0.97% (95 runs sampled) #4: 5.js current.js x 17,771,539 ops/sec ±0.77% (95 runs sampled) repeat-element-1.1.2/index.js000066400000000000000000000004741266020202700160710ustar00rootroot00000000000000/*! * repeat-element * * Copyright (c) 2015 Jon Schlinkert. * Licensed under the MIT license. */ 'use strict'; module.exports = function repeat(ele, num) { var arr = new Array(num); for (var i = 0; i < num; i++) { arr[i] = ele; } return arr; }; repeat-element-1.1.2/package.json000066400000000000000000000017011266020202700167040ustar00rootroot00000000000000{ "name": "repeat-element", "description": "Create an array by repeating the given value n times.", "version": "1.1.2", "homepage": "https://github.com/jonschlinkert/repeat-element", "author": { "name": "Jon Schlinkert", "url": "https://github.com/jonschlinkert" }, "repository": { "type": "git", "url": "git://github.com/jonschlinkert/repeat-element.git" }, "bugs": { "url": "https://github.com/jonschlinkert/repeat-element/issues" }, "license": { "type": "MIT", "url": "https://github.com/jonschlinkert/repeat-element/blob/master/LICENSE" }, "main": "index.js", "engines": { "node": ">=0.10.0" }, "scripts": { "test": "mocha" }, "files": [ "index.js" ], "keywords": [ "array", "element", "repeat", "string" ], "devDependencies": { "benchmarked": "^0.1.4", "chalk": "^1.0.0", "glob": "^5.0.5", "minimist": "^1.1.1", "mocha": "^2.2.4" } } repeat-element-1.1.2/test.js000066400000000000000000000025551266020202700157430ustar00rootroot00000000000000/*! * repeat-element * * Copyright (c) 2014 Jon Schlinkert, contributors. * Licensed under the MIT License */ 'use strict'; /* deps: mocha */ var fs = require('fs'); var path = require('path'); var assert = require('assert'); var argv = require('minimist')(process.argv.slice(2)); var files = fs.readdirSync('./benchmark/code'); var repeat = require('./'); var keys = Object.keys(argv); if (keys && keys[1]) { var lib = files.filter(function (fp) { return keys[1] === path.basename(fp, path.extname(fp)); }); repeat = require(path.resolve('./benchmark/code/' + lib[0])); } it('should repeat the given string:', function () { assert.deepEqual(repeat('a', 5), ['a', 'a', 'a', 'a', 'a']); assert.deepEqual(repeat('a', 50), ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a','a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a','a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a','a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a','a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']); assert.deepEqual(repeat('a', 1), ['a']); assert.deepEqual(repeat('a', 0), []); }); it('should repeat the given object:', function () { assert.deepEqual(repeat({a: 'b'}, 5), [{a: 'b'},{a: 'b'},{a: 'b'},{a: 'b'},{a: 'b'}]); }); it('should repeat null:', function () { assert.deepEqual(repeat(null, 5), [null, null, null, null, null]); });