<commit_before># multi-profile [![NPM version](https://badge.fury.io/js/multi-profile.png)](http://badge.fury.io/js/multi-profile) [![Build Status](https://travis-ci.org/kaelzhang/node-multi-profile.png?branch=master)](https://travis-ci.org/kaelzhang/node-multi-profile) [![Dependency Status](https://gemnasium.com/kaelzhang/node-multi-profile.png)](https://gemnasium.com/kaelzhang/node-multi-profile)

Multi-profile is a module to manage global configurations for multiple profiles.

## Installation

```sh
npm install multi-profile --save
```

## Usage

```js
var multi_profile = require('multi-profile');
var data = {};
var profile = multi_profile({
    path: '~/.cortex',
    context: data,
    schema: {
        port: {
            value: 8888,
            type: {
                validator: function (v, key, attr) {
                    if(v <= 9000){
                        attr.error('`port` must greater than 9000');
                    }
                    // If you've already called `attr.error`, it will be considered a failure,
                    // which means it's not necessary to return a value
                    return v > 9000;
                },
                setter: function (v, key, attr) {
                    // `this` <=> `data`
                    // The return value will set to the multi-profile instance.
                    // And in the same time, we set `port` to `data`
                    return this.port = v;
                },
                getter: function(v, key, attr){
                    return this.port || v;
                }
            }
        },

        rcfile: {
            value: '~/.bashrc'
        }
    }
});
```

## Instance Methods

### profile.add(name)

Add a profile

### profile.all()

Get all profile names

### profile.current()

Get the name of the current profile

### profile.switchTo(name)

Switch to a profile

### profile.del(name)

Delete a profile by name

### profile.set(key, value)

Set a configuration. If key is not in the `schema`, nothing will be done.
<commit_msg>update README.md; related to #5;<commit_after># multi-profile [![NPM version](https://badge.fury.io/js/multi-profile.png)](http://badge.fury.io/js/multi-profile) [![Build Status](https://travis-ci.org/kaelzhang/node-multi-profile.png?branch=master)](https://travis-ci.org/kaelzhang/node-multi-profile) [![Dependency Status](https://gemnasium.com/kaelzhang/node-multi-profile.png)](https://gemnasium.com/kaelzhang/node-multi-profile)

Multi-profile is a module to manage global configurations for multiple profiles.

## Installation

```sh
npm install multi-profile --save
```

## Usage

```js
var multi_profile = require('multi-profile');
var data = {};
var profile = multi_profile({
    path: '~/.cortex',
    context: data,
    schema: {
        port: {
            value: 8888,
            type: {
                validator: function (v, key, attr) {
                    if(v <= 9000){
                        attr.error('`port` must greater than 9000');
                    }
                    // If you've already called `attr.error`, it will be considered a failure,
                    // which means it's not necessary to return a value
                    return v > 9000;
                },
                setter: function (v, key, attr) {
                    // `this` <=> `data`
                    // The return value will set to the multi-profile instance.
                    // And in the same time, we set `port` to `data`
                    return this.port = v;
                },
                getter: function(v, key, attr){
                    return this.port || v;
                }
            }
        },

        rcfile: {
            value: '~/.bashrc'
        }
    }

});

// .init() method must be called before any invocations of other methods.
profile.init();
```

## Instance Methods

### profile.add(name)

Add a profile

### profile.all()

Get all profile names

### profile.current()

Get the name of the current profile

### profile.switchTo(name)

Switch to a profile

### profile.del(name)

Delete a profile by name

### profile.set(key, value)

Set a configuration. If key is not in the `schema`, nothing will be done.

{'fraction_non_alphanumeric': 0.1340279422211698, 'fraction_numerical': 0.007814349988160076, 'mean_word_length': 1.8773841961852862, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 10, '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': '6971804', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1199, 'n_words': 344}