<commit_before>Require-IS
===

A conditional loading plugin for require-JS that works with builds.

Installation
---

Using volo:
```
volo add guybedford/require-is
```

Alternaively, download is.js and place it in the baseUrl folder of a Require-JS project.

Usage
---

Where conditional loads are needed, use the plugin syntax:

```
is![condition]?[moduleId]
```

### Example:

```
define(['is!mobile?mobile-code'], function(mobile) {
  
});
```

If the condition, `[mobile]` is true, then the module `mobile-code` is loaded, otherwise `null` is returned.

The above applies equally well to builds with the requireJS optimizer.

### Setting Conditions

There are two ways to set conditions.

**1. Using the RequireJS configuration:**

```
requirejs.config({
  config: {
    is: {
      mobile: true
    }
  }
});
```

Any number of conditions can be set to true or false in this way.

**2. Dynamically during runtime:**

```
require(['is'], function(is) {
  is.set('mobile');
});
```

Any further loads will then use the condition.

**Note that conditions are constants. They can only be set once. As soon as a condition has been used in the loading of a module, it cannot be changed again and any attempts to set it will throw an error.**

This is done in order that conditions can always be built into modules with the RequireJS optimizer.<commit_msg>readme updates<commit_after>Require-IS
===

A conditional loading plugin for [Require-JS](http://requirejs.org/) that works with builds.

Installation
---

Using [volo](https://github.com/volojs/volo):
```
volo add guybedford/require-is
```

Alternaively, download is.js and place it in the baseUrl folder of a Require-JS project.

Usage
---

Where conditional loads are needed, use the plugin syntax:

```
is![condition]?[moduleId]
```

### Example:

```javascript
define(['is!mobile?mobile-code'], function(mobile) {
  
});
```

If the condition, `[mobile]` is true, then the module `mobile-code` is loaded, otherwise `null` is returned.

The above applies equally well to builds with the [RequireJS optimizer](http://requirejs.org/docs/optimization.html).

### Setting Conditions

There are two ways to set conditions.

**1. Using the RequireJS configuration:**

```javascript
requirejs.config({
  config: {
    is: {
      mobile: true
    }
  }
});
```

Any number of conditions can be set to true or false in this way.

**2. Dynamically during runtime:**

```javascript
require(['is'], function(is) {
  is.set('mobile');
});
```

Any further loads will then use the condition.

**Note that conditions are constants. They can only be set once. As soon as a condition has been used in the loading of a module, it cannot be changed again and any attempts to set it will throw an error.**

This is done in order that conditions can always be built into modules with the RequireJS optimizer.

### Checking conditions

Sometimes it may be useful to check the value of a condition as well.

To do this, simply use the plugin with square brackets around the condition name.

Example:

```javascript
require(['is![mobile]', function(mobile) {
  if (mobile) {
    //only true if mobile condition has been set
  }
});
```
{'fraction_non_alphanumeric': 0.11510564490696941, 'fraction_numerical': 0.001261431725007884, 'mean_word_length': 4.034920634920635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '1105335', 'n_tokens_mistral': 937, 'n_tokens_neox': 895, 'n_words': 403}