Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

call-n-times

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

call-n-times - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

.verb.md

27

index.js

@@ -7,17 +7,27 @@ /* eslint-env node */

/**
* Synchronously calls `func` `n` number of times
*
* @name `call-n-times`
* @param {Function} `func` Called `n` times with the index as argument
* @param {Number} `n` Times `func` will be called
* @returns {Array} Return values of all the `func` calls
* @api public
*/
module.exports = function (func, n, cb) {
if (arguments.length < 2) {
throw 'Expected exactly 2 arguments'
throw new Error('Expected exactly 2 arguments')
}
if (typeof func !== 'function') {
throw 'Expected first argument to be a function'
throw new Error('Expected first argument to be a function')
}
if (typeof n !== 'number') {
throw 'Expected second argument to be a number'
throw new Error('Expected second argument to be a number')
}
if (n >= 0 !== true) {
throw 'Expected second argument to be equal to or greater than 0'
throw new Error('Expected second argument to be equal to or greater than 0')
}
if (isInteger(n) !== true) {
throw 'Expected second argument to be an integer'
throw new Error('Expected second argument to be an integer')
}

@@ -28,11 +38,8 @@

while (n > 0) {
returnVal = func()
for (var i = 0; i < n; i++) {
returnVal = func(i) // passes index to provided `func`
returns.push(returnVal)
n--
}
if (typeof cb === 'function') cb()
return returns
}
{
"dependencies": {
"validate.io-integer": "^1.0.2"
},
"devDependencies": {
"verb-cli": "^0.6.2",
"mocha": "^2.2.4",
"chai": "^2.3.0",
"sinon": "^1.14.1",
"sinon-chai": "^2.7.0",
"mightyiam": "^1.1.6",
"standard": "*",
"auto-package": "^1.0.0",
"license-generator": "^0.0.13",
"policystat": "^1.3.0"
},
"keywords": [
"call",
"repeat",
"sync"
],
"name": "call-n-times",
"version": "1.1.0",
"version": "2.0.0",
"description": "Calls a provided function n times, synchronously",
"main": "index.js",
"scripts": {
"test": "standard && jasmine"
"lint": "standard",
"unit": "mocha test/unit",
"generate-license": "license-generator install bsd-3-clause --year 2015 --fullname PolicyStat LLC --project call-n-times",
"test": "npm run lint && npm run generate-license && npm run unit"
},
"repository": {
"type": "git",
"url": "https://github.com/mightyiam/n-calls.git"
"url": "https://github.com/PolicyStat/call-n-times.git"
},
"keywords": [
"call",
"repeat",
"sync"
],
"author": "Shahar Or",
"license": "MIT",
"homepage": "https://github.com/PolicyStat/call-n-times",
"bugs": {
"url": "https://github.com/mightyiam/n-calls/issues"
"url": "https://github.com/PolicyStat/call-n-times/issues"
},
"homepage": "https://github.com/mightyiam/n-calls",
"devDependencies": {
"jasmine": "^2.2.0",
"jasmine-core": "^2.1.3",
"karma": "^0.12.31",
"karma-browserify": "^2.0.0",
"karma-chrome-launcher": "^0.1.7",
"karma-jasmine": "^0.3.4",
"standard": "*"
},
"dependencies": {
"validate.io-integer": "^1.0.2"
}
"author": "Shahar Or <mightyiampresence@gmail.com> (http://mightyi.am)",
"license": "BSD-3-Clause",
"copyright": "Copyright © 2015 PolicyStat LLC"
}

@@ -1,32 +0,12 @@

# call-n-times
[![NPM](https://nodei.co/npm/call-n-times.png)](https://nodei.co/npm/call-n-times/)
[![js-standard-style](https://raw.githubusercontent.com/feross/standard/master/badge.png)](https://github.com/feross/standard)
Calls a provided function a specified number of times, synchronously, and returns an array of the return values.
# call-n-times [![Build Status](https://travis-ci.org/PolicyStat/call-n-times.svg)](https://travis-ci.org/PolicyStat/call-n-times)
Can optionally call a provided callback right before returning.
## API
Should work in IE7+. Perhaps even older.
See [here](./index.js).
Tests included.
## License
``` js
var call = require("call-n-times");
var logAndReturnFoo = function(){
console.log("foo");
return "foo";
};
var returns = call(logAndReturnFoo, 3);
// 'Foo'
// 'Foo'
// 'Foo'
returns.length === 3;
// true
returns[0] === "foo"
// true
returns[1] === "foo"
// true
returns[2] === "foo"
// true
```
Copyright © 2015 PolicyStat LLC

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc