<commit_before># type-ahead.js

A lightweight and extensible type ahead library. Browserify compatible.

## Demo

Check out http://marcojetson.github.io/type-ahead.js/

## Install
### Browserify via NPM

To use type-ahead with Browserify, install it into your project via npm:

```bash
npm install type-ahead
```

Once installed, include the library using `require`:

```javascript
var TypeAhead = require('type-ahead')
```

### Manually

You can also include the standalone library by downloading it [here](https://raw.githubusercontent.com/marcojetson/type-ahead.js/master/type-ahead.js) (or [minified](https://raw.githubusercontent.com/marcojetson/type-ahead.js/master/type-ahead.min.js)), and including it in your HTML page:

```html
<script type="text/javascript" src="type-ahead.js"></script>
```

## Usage

### Simple usage

```javascript
new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
]);
```


### AJAX

```javascript
var t = new TypeAhead(document.getElementById('my-control'));

t.getCandidates = function (callback) {
	$.getJSON('/suggest?q=' + this.query, function () {
		callback(response);
	});
};
```

*Example is using jQuery for simplicity*


### Min length and limit

```javascript
var opts = {
	minLength: 1,
	limit:false
}

var t = new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
], opts);
```

### Use objects instead of strings

```javascript
var t = new TypeAhead(document.getElementById('my-control'), [
	{name: 'Asia'},
	{name: 'Africa'},
	{name: 'Europe'},
	{name: 'North America'},
	{name: 'South America'},
	{name: 'Oceania'}
]);

t.getItemValue = function (item) {
    return item.name;
};
```

### Dynamically update list
Once you've created the `TypeAhead` instance, you can update the items in the autocomplete list via:

```javascript
var t = new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
]);

t.update([
	'Asia', 'Europe', 'South America', 'Oceania'
])
```

### Callback

If you want to run code after autocomplete updates the input (e.g. to update a model), simply add a `callback` function into the `opts` parameter:



## Contributing

Found an issue? Have a feature request? Open a [Github Issue]() and/or [fork this repo]().


```javascript
var opts = {
	callback:function(newValue){
		console.log(newValue);
		// Do code here
	}
};

var t = new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
], opts);
```
## License<commit_msg>I'm dumb. fixed README.<commit_after># type-ahead.js

A lightweight and extensible type ahead library. Browserify compatible.

## Demo

Check out http://marcojetson.github.io/type-ahead.js/

## Install
### Browserify via NPM

To use type-ahead with Browserify, install it into your project via npm:

```bash
npm install type-ahead
```

Once installed, include the library using `require`:

```javascript
var TypeAhead = require('type-ahead')
```

### Manually

You can also include the standalone library by downloading it [here](https://raw.githubusercontent.com/marcojetson/type-ahead.js/master/type-ahead.js) (or [minified](https://raw.githubusercontent.com/marcojetson/type-ahead.js/master/type-ahead.min.js)), and including it in your HTML page:

```html
<script type="text/javascript" src="type-ahead.js"></script>
```

## Usage

### Simple usage

```javascript
new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
]);
```


### AJAX

```javascript
var t = new TypeAhead(document.getElementById('my-control'));

t.getCandidates = function (callback) {
	$.getJSON('/suggest?q=' + this.query, function () {
		callback(response);
	});
};
```

*Example is using jQuery for simplicity*


### Min length and limit

```javascript
var opts = {
	minLength: 1,
	limit:false
}

var t = new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
], opts);
```

### Use objects instead of strings

```javascript
var t = new TypeAhead(document.getElementById('my-control'), [
	{name: 'Asia'},
	{name: 'Africa'},
	{name: 'Europe'},
	{name: 'North America'},
	{name: 'South America'},
	{name: 'Oceania'}
]);

t.getItemValue = function (item) {
    return item.name;
};
```

### Dynamically update list
Once you've created the `TypeAhead` instance, you can update the items in the autocomplete list via:

```javascript
var t = new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
]);

t.update([
	'Asia', 'Europe', 'South America', 'Oceania'
])
```

### Callback

If you want to run code after autocomplete updates the input (e.g. to update a model), simply add a `callback` function into the `opts` parameter:

```javascript
var opts = {
	callback:function(newValue){
		console.log(newValue);
		// Do code here
	}
};

var t = new TypeAhead(document.getElementById('my-control'), [
	'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania'
], opts);
```

## Contributing

Found an issue? Have a feature request? Open a [Github Issue]() and/or [fork this repo]().

## License
{'fraction_non_alphanumeric': 0.16877088748607502, 'fraction_numerical': 0.0003713330857779428, 'mean_word_length': 4.972283813747229, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, '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': 0}}
{'dir': 'git-commits-cleaned', 'id': '1930455', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1703, 'n_words': 518}