<commit_before>### About localStorage

[localStorage](http://diveintohtml5.info/storage.html) is a simple API within [modern browsers](http://caniuse.com/#search=localstorage) to allow web developers to store small amounts of data within the user's browser.

The HTML5 spec suggests storage quota with a limit of 5MB for localStorage but browsers can implement their own quota if they wish. If the quota is exceeded the browser may fail to store items in the cache. If this happens, basket.js will remove entries from the cache beginning with the oldest and try again. Some browsers like Opera will ask the user about increasing the quota when it exceeds a set threshold.

To free space basket.js will only remove cached scripts that it placed in localStorage itself. The data stored by other code in same origin will not be touched.

### API

* `basket.require()`
* `basket.get()`
* `basket.remove()`
* `basket.clear()`

### basket.require

`basket.require( details )`

**details** Either an object or an array of objects with the following fields:

* **uri** (*required*) The URI for the script. At present this must be a URI on the same origin as the caller.
* **key** The name that will be used to refer to this script. By default this is the *uri*.
* **expire** How long (in hours) before the cached item expires.
* **execute** Whether to cause the script to be executed once it has been retrieved. Defaults to true.
* **unique** A token stored with the cached item. If you request the same item again with a different token the script will be fetched and cached again.

`require()` returns a [promise](http://wiki.commonjs.org/wiki/Promises/A) that will be fulfilled when each of the requested items has been fetched, or rejected if any item fails.

#### Examples

**Single script**

```javascript
basket.require({ url: 'jquery.js' });
```

This fetches a single script and executes it. If the script was already in the localStorage cache it will be loaded from there, otherwise it will be loaded from the network. The script will then be injected into the document for the browser to execute.

**Multiple scripts**

```javascript
basket.require(
	{ url: 'jquery.js' },
	{ url: 'underscore.js' },
	{ url: 'backbone.js' }
);
```

Multiple scripts will be requested. The scripts are requested asynchronously and so my load and execute in any order.

**Ordering dependencies**

```javascript
basket.require({ url: 'jquery.js' })
	.then(function() {
		basket.require({ url: 'jquery-ui.js' });
	});
})
```

Here we ask basket.js to load jQuery. Once it has been fetched and executed, the promise returned by `require()` will be fulfilled and the callback passed to the `then()` method of the promise will be executed. Now we can do anything the requires jquery to be loaded including load any scripts that depend on it.

**Error handling**

```javascript
basket.require({ url: 'missing.js' })
	.then(function() {
		// Success
	}, function( error ) {
		// There was an error fetching the script
		console.log( error );<commit_msg>Fixes a small typo in documentation.<commit_after>### About localStorage

[localStorage](http://diveintohtml5.info/storage.html) is a simple API within [modern browsers](http://caniuse.com/#search=localstorage) to allow web developers to store small amounts of data within the user's browser.

The HTML5 spec suggests storage quota with a limit of 5MB for localStorage but browsers can implement their own quota if they wish. If the quota is exceeded the browser may fail to store items in the cache. If this happens, basket.js will remove entries from the cache beginning with the oldest and try again. Some browsers like Opera will ask the user about increasing the quota when it exceeds a set threshold.

To free space basket.js will only remove cached scripts that it placed in localStorage itself. The data stored by other code in same origin will not be touched.

### API

* `basket.require()`
* `basket.get()`
* `basket.remove()`
* `basket.clear()`

### basket.require

`basket.require( details )`

**details** Either an object or an array of objects with the following fields:

* **uri** (*required*) The URI for the script. At present this must be a URI on the same origin as the caller.
* **key** The name that will be used to refer to this script. By default this is the *uri*.
* **expire** How long (in hours) before the cached item expires.
* **execute** Whether to cause the script to be executed once it has been retrieved. Defaults to true.
* **unique** A token stored with the cached item. If you request the same item again with a different token the script will be fetched and cached again.

`require()` returns a [promise](http://wiki.commonjs.org/wiki/Promises/A) that will be fulfilled when each of the requested items has been fetched, or rejected if any item fails.

#### Examples

**Single script**

```javascript
basket.require({ url: 'jquery.js' });
```

This fetches a single script and executes it. If the script was already in the localStorage cache it will be loaded from there, otherwise it will be loaded from the network. The script will then be injected into the document for the browser to execute.

**Multiple scripts**

```javascript
basket.require(
	{ url: 'jquery.js' },
	{ url: 'underscore.js' },
	{ url: 'backbone.js' }
);
```

Multiple scripts will be requested. The scripts are requested asynchronously and so may load and execute in any order.

**Ordering dependencies**

```javascript
basket.require({ url: 'jquery.js' })
	.then(function() {
		basket.require({ url: 'jquery-ui.js' });
	});
})
```

Here we ask basket.js to load jQuery. Once it has been fetched and executed, the promise returned by `require()` will be fulfilled and the callback passed to the `then()` method of the promise will be executed. Now we can do anything the requires jquery to be loaded including load any scripts that depend on it.

**Error handling**

```javascript
basket.require({ url: 'missing.js' })
	.then(function() {
		// Success
	}, function( error ) {
		// There was an error fetching the script
		console.log( error );
{'fraction_non_alphanumeric': 0.09549638395792243, 'fraction_numerical': 0.0009861932938856016, 'mean_word_length': 4.295909486510009, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5652497', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1591, 'n_words': 861}