Socket
Socket
Sign inDemoInstall

helper-license

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

helper-license - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

46

index.js
'use strict';
var mdu = require('markdown-utils');
var pluck = require('arr-pluck');
var merge = require('mixin-deep');
module.exports = function(config, options) {
options = options || {};
module.exports = function license_(locals) {
var o = typeof locals === 'object' ? locals : {};
// support Template, verb and assemble.
if (this && this.app && this.context) {
this.app.union('reflinks', ['verb', 'template', 'assemble']);
o = merge({}, this.options, this.app.cache.data, this.context, o);
if (!config || typeof config !== 'object') {
throw new TypeError('expected config to be an object');
}
if (!o.license && !o.licenses) {
throw new Error('helper-license expects a "license" or "licenses" property');
var license = config.license;
if (typeof license !== 'string') {
throw new TypeError('expected license to be a string');
}
if (typeof o.license === 'string') {
o.license = {type: o.license};
}
var prefix = options.prefix || 'Released under the ';
var suffix = ' license';
var res = prefix + license + suffix;
var licenses = Array.isArray(o.licenses) ? o.licenses : [o.license];
var res = 'Released under the ';
var len = licenses.length;
var urls = [];
if (o.linkify === true) {
licenses.forEach(function (license) {
if (license.type && license.url) {
urls.push(mdu.link(license.type, license.url));
}
});
if (options.linkify === true) {
var fp = options.filepath || './LICENSE';
res = prefix + '[' + license + suffix + '](' + fp + ')';
}
var s = len <= 1 ? '.' : 's.';
if (urls.length > 0) {
res += urls.join(', ') + ' license' + s;
} else {
res += pluck(licenses, 'type').join(', ') + ' license' + s;
if (res[res.length - 1] !== '.') {
res += '.';
}
return res;
};
{
"name": "helper-license",
"description": "Template helper for dynamically generating a basic, one-line license statement based on the given context, e.g. `Released under the MIT license`. Should work with any Handlebars, Lo-Dash, underscore, or any template engine that allows helper functions to be registered.",
"version": "0.2.1",
"description": "Template helper for adding a formatted license statement based on the license type in package.json.",
"version": "0.3.0",
"homepage": "https://github.com/helpers/helper-license",
"author": {
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
},
"repository": {
"type": "git",
"url": "git://github.com/helpers/helper-license.git"
},
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "helpers/helper-license",
"bugs": {
"url": "https://github.com/helpers/helper-license/issues"
},
"license": {
"type": "MIT",
"url": "https://github.com/helpers/helper-license/blob/master/LICENSE"
},
"license": "MIT",
"files": [

@@ -31,12 +22,20 @@ "index.js"

},
"dependencies": {
"arr-pluck": "^0.1.0",
"markdown-utils": "^0.6.0",
"mixin-deep": "^1.0.1"
"devDependencies": {
"mocha": "^2.3.3"
},
"devDependencies": {
"handlebars": "^2.0.0",
"lodash": "^3.7.0",
"should": "^4.2.1"
"keywords": [
"helper",
"license"
],
"verb": {
"related": {
"description": "",
"list": [
"helper-related",
"helper-reflinks",
"template-helpers",
"handlebars-helpers"
]
}
}
}

@@ -1,103 +0,85 @@

# helper-license [![NPM version](https://badge.fury.io/js/helper-license.svg)](http://badge.fury.io/js/helper-license) [![Build Status](https://travis-ci.org/helpers/helper-license.svg)](https://travis-ci.org/helpers/helper-license)
# helper-license [![NPM version](https://badge.fury.io/js/helper-license.svg)](http://badge.fury.io/js/helper-license) [![Build Status](https://travis-ci.org/helpers/helper-license.svg)](https://travis-ci.org/helpers/helper-license)
> Template helper for dynamically generating a basic, one-line license statement based on the given context, e.g. `Released under the MIT license`. Should work with any Handlebars, Lo-Dash, underscore, or any template engine that allows helper functions to be registered.
> Template helper for adding a formatted license statement based on the license type in package.json.
## Install
## Install with [npm](npmjs.org)
Install with [npm](https://www.npmjs.com/)
```bash
npm i helper-license --save
```sh
$ npm i helper-license --save
```
## Usage example
## Usage
Add a basic license statement to a document with [verb]:
```js
{%= license() %}
//=> Released under the MIT license
{%= license({linkify: true}) %}
//=> Released under the [MIT](https://github.com/jonschlinkert/helper-license/blob/master/LICENSE-MIT) license
var license = require('helper-license');
var pkg = require('./package');
license(pkg);
//=> 'Released under the MIT License.'
```
## Other engines/apps
The following example shows how to register the helper with [verb](https://github.com/verbose/verb), but it should work similarly with handlebars, lodash or any other template engine.
Add a basic license statement
```js
var pkg = require('./package.json');
var license = require('helper-license');
var verb = require('verb');
var app = verb();
// handlebars
Handlebars.compile('{{license this}}')(pkg);
// lo-dash
_.template('<%= license({licenses: licenses}) %>', )
// verb
verb.render('{%= license({licenses: licenses}) %}', pkg);
app.helper('license', function(type) {
// handle these settings however you want...
return license({type: type}, {linkify: true});
});
// all result in:
//=> Released under the MIT license
// USAGE:
// <%= license("MIT") %>
```
Linkify:
## Options
```js
_.template('<%= license({licenses: licenses, linkify: true}) %>', pkg);
//=> Released under the [MIT](https://github.com/jonschlinkert/helper-license/blob/master/LICENSE-MIT) license
```
**options.linkify**
## Registering the helper
Pass `linkify: true` to add a markdown link to the license file:
> This should work with any engine, here are a few examples to get you started
### [template]
```js
template.helper('license', require('helper-license'));
license(pkg, {linkify: true});
//=> 'Released under the [MIT License](./LICENSE).'
```
### [assemble]
**options.filepath**
```js
assemble.helper('license', require('helper-license'));
license(pkg, {linkify: true, filepath: 'foo'});
//=> 'Released under the [MIT License](foo).'
```
### [verb]
## Related projects
```js
verb.helper('license', require('helper-license'));
```
* [handlebars-helpers](https://www.npmjs.com/package/handlebars-helpers): 120+ Handlebars helpers in ~20 categories, for Assemble, YUI, Ghost or any Handlebars project. Includes… [more](https://www.npmjs.com/package/handlebars-helpers) | [homepage](https://github.com/assemble/handlebars-helpers)
* [helper-reflinks](https://www.npmjs.com/package/helper-reflinks): Template helper for generating a list of markdown formatted reference links to github repos for… [more](https://www.npmjs.com/package/helper-reflinks) | [homepage](https://github.com/helpers/helper-reflinks)
* [helper-related](https://www.npmjs.com/package/helper-related): Template helper for generating a list of links to the homepages of related GitHub/npm projects. | [homepage](https://github.com/helpers/helper-related)
* [template-helpers](https://www.npmjs.com/package/template-helpers): Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or… [more](https://www.npmjs.com/package/template-helpers) | [homepage](https://github.com/jonschlinkert/template-helpers)
### [handlebars]
## Running tests
```js
var handlebars = require('handlebars');
handlebars.registerHelper('license', require('helper-license'));
```
## Related projects
* [helper-copyright](https://github.com/helpers/helper-copyright): Template helper for adding a basic, one-line copyright statement, with… [more](https://github.com/helpers/helper-copyright)
* [helper-reflinks](https://github.com/helpers/helper-reflinks): Template helper for generating a list of markdown formatted reference… [more](https://github.com/helpers/helper-reflinks)
* [helper-related](https://github.com/helpers/helper-related): Template helper for generating a list of links to the… [more](https://github.com/helpers/helper-related)
* [template-helpers](https://github.com/jonschlinkert/template-helpers): Generic JavaScript helpers that can be used with any template… [more](https://github.com/jonschlinkert/template-helpers)
* [verb](https://github.com/assemble/verb): Verb makes it dead simple to generate markdown documentation, using… [more](https://github.com/assemble/verb)
## Running tests
Install dev dependencies:
```bash
npm i -d && npm test
```sh
$ npm i -d && npm test
```
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/helpers/helper-license/issues)
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/helpers/helper-license/issues/new).
## Author
**Jon Schlinkert**
[github/jonschlinkert](https://github.com/jonschlinkert)
[twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
## License
Copyright (c) 2015 Jon Schlinkert
Copyright © 2015 Jon Schlinkert
Released under the MIT license.

@@ -107,17 +89,4 @@

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on April 23, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 27, 2015._
<!-- reflinks -->
[template]: https://github.com/jonschlinkert/template
[verb]: https://github.com/assemble/verb
[assemble]: http://assemble.io
[handlebars]: http://www.handlebarsjs.com/
[lodash]: https://lodash.com/
<!-- reflinks generated by verb-reflinks plugin -->
[verb]: https://github.com/assemble/verb
[template]: https://github.com/jonschlinkert/template
[assemble]: http://assemble.io
<!-- reflinks -->
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc