<commit_before># onetime [![Build Status](https://secure.travis-ci.org/sindresorhus/onetime.png?branch=master)](http://travis-ci.org/sindresorhus/onetime)

> Only call a function once

When called multiple times it will return the return value from the first call.


## Install

Download [manually](https://github.com/sindresorhus/onetime/releases) or with a package-manager.

#### [npm](https://npmjs.org/package/onetime)

```
npm install --save onetime
```

#### [Bower](http://bower.io)

```
bower install --save onetime
```

#### [Component](https://github.com/component/component)

```
component install sindresorhus/onetime
```


## Examples

### Node.js

```js
var onetime = require('onetime');
var i = 0;
var foo = onetime(function () {
	return i++;
});

foo(); //=> 0
foo(); //=> 0
foo(); //=> 0
```

### Bower

```html
<script src="bower_components/onetime/onetime.js"></script>
```

```js
var i = 0;
var foo = onetime(function () {
	return i++;
});

foo(); //=> 0
foo(); //=> 0
foo(); //=> 0
```


## API

### onetime(function, [shouldThrow])

#### function

Type: `Function`

Function that should only be called once.

#### shouldThrow

Type: `Boolean`  
Default: `false`

Set to `true` if you want it to fail with an error when called more than once.


## License

MIT © [<NAME>](http://sindresorhus.com)<commit_msg>Thanks @passy<commit_after># onetime [![Build Status](https://secure.travis-ci.org/sindresorhus/onetime.png?branch=master)](http://travis-ci.org/sindresorhus/onetime)

> Only call a function once

When called multiple times it will return the return value from the first call.


## Install

Download [manually](https://github.com/sindresorhus/onetime/releases) or with a package-manager.

#### [npm](https://npmjs.org/package/onetime)

```
npm install --save onetime
```

#### [Bower](http://bower.io)

```
bower install --save onetime
```

#### [Component](https://github.com/component/component)

```
component install sindresorhus/onetime
```


## Examples

### Node.js

```js
var onetime = require('onetime');
var i = 0;
var foo = onetime(function () {
	return i++;
});

foo(); //=> 0
foo(); //=> 0
foo(); //=> 0
```

### Bower

```html
<script src="bower_components/onetime/onetime.js"></script>
```

```js
var i = 0;
var foo = onetime(function () {
	return i++;
});

foo(); //=> 0
foo(); //=> 0
foo(); //=> 0
```


## API

### onetime(function, [shouldThrow])

#### function

Type: `Function`

Function that should only be called once.

#### shouldThrow

Type: `Boolean`  
Default: `false`

Set to `true` if you want it to fail with an error when called more than once.


## Thanks

Huge thanks to [@passy](https://github.com/passy) for lending me an adapter so I could code this. From Paris with code. xoxo.


## License

MIT © [<NAME>](http://sindresorhus.com)
{'fraction_non_alphanumeric': 0.1966392563460851, 'fraction_numerical': 0.00572041473006793, 'mean_word_length': 4.078039927404719, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 1}}
{'dir': 'git-commits-cleaned', 'id': '6285041', 'n_tokens_mistral': 1022, 'n_tokens_neox': 956, 'n_words': 264}