License Header

Create a license header provided a license SPDX identifier and file type.

Usage

var licenseHeader = require( '@stdlib/_tools/licenses/header' );

licenseHeader( license, type[, options] )

Returns a license header provided a license SPDX identifier and file type.

var h = licenseHeader( 'Apache-2.0', 'Julia' );
#
# @license Apache-2.0
#
# Copyright (c) {{YEAR}} {{COPYRIGHT_OWNER}}.
#
# 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.

The function supports the following options:

  • year: copyright year.
  • copyright: copyright owner.

To set the copyright line, set the relevant options.

var opts = {
    'year': 2018,
    'copyright': 'Jane Doe'
};

var h = licenseHeader( 'Apache-2.0', 'Julia', opts );
#
# @license Apache-2.0
#
# Copyright (c) 2018 Jane Doe.
#
# 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.

If provided an unsupported file type, the function returns null.

var h = licenseHeader( 'Apache-2.0', 'beepboopbop' );
// returns null

Notes

  • The function supports the following SPDX license identifiers:

    • Apache-2.0

Examples

var licenseHeader = require( '@stdlib/_tools/licenses/header' );

var opts = {
    'year': 2018,
    'copyright': 'The Stdlib Authors'
};

var h = licenseHeader( 'Apache-2.0', 'Fortran', opts );
!>
! @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.
!<

CLI

Usage

Usage: license-header [options] [--license <license> --type <file_type>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --license spdx        License SPDX identifier.
         --type type           File type.
         --year year           Copyright year.
         --copyright owner     Copyright owner.

Examples

$ license-header --license=Apache-2.0 --type=js --year=2018 --copyright='The Stdlib Authors'
/**
* @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.
*/