<commit_before><!--

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Insert Header

> Insert a [license header][@stdlib/_tools/licenses/header] into each file in a provided file list.

<section class="usage">

## Usage

```javascript
var insertHeader = require( '@stdlib/_tools/licenses/insert-header-file-list' );
```

#### insertHeader( files, header, clbk )

Asynchronously inserts a [license header][@stdlib/_tools/licenses/header] into each file in a provided file list.

<!-- run-disable -->

```javascript
var join = require( 'path' ).join;

var files = [
    join( __dirname, 'examples', 'index.js' )
];

var header = '// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0';

insertHeader( files, header, done );

function done( error ) {
    if ( error ) {
        throw error;
    }
}
```

To insert [license headers][@stdlib/_tools/licenses/header] using an `object` whose keys are filename extensions and whose values are [license header][@stdlib/_tools/licenses/header] `strings`,

<!-- run-disable -->

```javascript
var join = require( 'path' ).join;

var files = [
    join( __dirname, 'README.md' ),
    join( __dirname, 'examples', 'index.js' )
];

var header = {
    // JavaScript files:
    'js': '// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0',

    // Julia files:
    'jl': '# This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0',

    // Markdown files:
    'md': '<!-- This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -->',

    // Everything else:
    'default': '/* This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 */'
};

insertHeader( files, header, done );

function done( error ) {
    if ( error ) {
        throw error;
    }
}
```

If a provided `header` object includes a `default` property, the value assigned to that property is inserted into **all** files having filename extensions **not** explicitly included in the object; otherwise, the function **ignores** any file **not** having a filename extension explicitly included in the object.

#### insertHeader.sync( files, header )

Synchronously inserts a [license header][@stdlib/_tools/licenses/header] into each file in a provided file list.

<!-- run-disable -->

```javascript
var join = require( 'path' ).join;

var files = [
    join( __dirname, 'examples', 'index.js' )
];

var header = '// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0';

var errs = insertHeader.sync( files, header );
// returns [...]
```<commit_msg>Fix sync example error handling<commit_after><!--

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Insert Header

> Insert a [license header][@stdlib/_tools/licenses/header] into each file in a provided file list.

<section class="usage">

## Usage

```javascript
var insertHeader = require( '@stdlib/_tools/licenses/insert-header-file-list' );
```

#### insertHeader( files, header, clbk )

Asynchronously inserts a [license header][@stdlib/_tools/licenses/header] into each file in a provided file list.

<!-- run-disable -->

```javascript
var join = require( 'path' ).join;

var files = [
    join( __dirname, 'examples', 'index.js' )
];

var header = '// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0';

insertHeader( files, header, done );

function done( error ) {
    if ( error ) {
        throw error;
    }
}
```

To insert [license headers][@stdlib/_tools/licenses/header] using an `object` whose keys are filename extensions and whose values are [license header][@stdlib/_tools/licenses/header] `strings`,

<!-- run-disable -->

```javascript
var join = require( 'path' ).join;

var files = [
    join( __dirname, 'README.md' ),
    join( __dirname, 'examples', 'index.js' )
];

var header = {
    // JavaScript files:
    'js': '// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0',

    // Julia files:
    'jl': '# This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0',

    // Markdown files:
    'md': '<!-- This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -->',

    // Everything else:
    'default': '/* This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 */'
};

insertHeader( files, header, done );

function done( error ) {
    if ( error ) {
        throw error;
    }
}
```

If a provided `header` object includes a `default` property, the value assigned to that property is inserted into **all** files having filename extensions **not** explicitly included in the object; otherwise, the function **ignores** any file **not** having a filename extension explicitly included in the object.

#### insertHeader.sync( files, header )

Synchronously inserts a [license header][@stdlib/_tools/licenses/header] into each file in a provided file list.

<!-- run-disable -->

```javascript
var join = require( 'path' ).join;

var files = [
    join( __dirname, 'examples', 'index.js' )
];

var header = '// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0';

var err = insertHeader.sync( files, header );
if ( err ) {
    throw err;
}
```
{'fraction_non_alphanumeric': 0.13708690330477355, 'fraction_numerical': 0.01040391676866585, 'mean_word_length': 3.5681341719077566, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 14, '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': '7251926', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1900, 'n_words': 727}