Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.1.3 to 0.2.0

LICENSE

85

index.js
'use strict';
var mdu = require('markdown-utils');
var _ = require('lodash');
var pluck = require('arr-pluck');
var merge = require('mixin-deep');
/**
* Add a basic license statement
*
* ```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
* ```
*
* @return {String} Complete license statement.
*/
module.exports = function license_(locals) {
var o = typeof locals === 'object' ? locals : {};
module.exports = function(locals) {
var context = {};
// compatibility with template, verb and assemble.
// support Template, verb and assemble.
if (this && this.app && this.context) {
context = _.merge({}, this.options, this.app.cache.data, this.context);
this.app.union('reflinks', ['verb', 'template', 'assemble']);
o = merge({}, this.options, this.context, o);
}
var o = _.merge({}, context, locals);
if (!o.license && !o.licenses) {
throw new Error('helper-license expects a "license" or "licenses" property');
}
if (typeof o.license === 'string') {
o.license = {type: o.license};
}
var licenses = Array.isArray(o.licenses) ? o.licenses : [o.license];
var res = 'Released under the ';
var len = licenses.length;
var urls = [];
try {
if (o.licenses) {
if (o.linkify === true) {
o.licenses.forEach(function (license) {
if (license.type && license.url) {
urls.push(mdu.link(license.type, license.url));
}
});
if (o.linkify === true) {
licenses.forEach(function (license) {
if (license.type && license.url) {
urls.push(mdu.link(license.type, license.url));
}
});
}
if (urls.length > 0) {
res += urls.join(', ') + ' license' + (o.licenses.length <= 1 ? '' : 's');
} else {
res += _.pluck(o.licenses, 'type').join(', ') + ' license' + (o.licenses.length <= 1 ? '' : 's');
}
} else if (o.license) {
var license;
if (typeof o.license === 'object') {
if (o.linkify === true && o.license.type && o.license.url) {
license = mdu.link(o.license.type, o.license.url);
} else {
license = o.license.type;
}
}
if (typeof o.license === 'string') {
license = o.license;
}
res += license + (o.suffix || ' license');
}
} catch (err) {
err.origin = __filename;
console.warn('No "license" or "licenses" properties found.', err);
var s = len <= 1 ? '.' : 's.';
if (urls.length > 0) {
res += urls.join(', ') + ' license' + s;
} else {
res += pluck(licenses, 'type').join(', ') + ' license' + s;
}
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.1.3",
"version": "0.2.0",
"homepage": "https://github.com/helpers/helper-license",

@@ -17,7 +17,8 @@ "author": {

},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/helpers/helper-license/blob/master/LICENSE-MIT"
}
"license": {
"type": "MIT",
"url": "https://github.com/helpers/helper-license/blob/master/LICENSE"
},
"files": [
"index.js"
],

@@ -29,12 +30,14 @@ "main": "index.js",

"scripts": {
"test": "mocha -R spec"
"test": "mocha"
},
"dependencies": {
"lodash": "^2.4.1",
"markdown-utils": "^0.1.0"
"arr-pluck": "^0.1.0",
"markdown-utils": "^0.6.0",
"mixin-deep": "^1.0.1"
},
"devDependencies": {
"handlebars": "^2.0.0",
"lodash": "^3.7.0",
"should": "^4.2.1"
}
}

@@ -1,2 +0,2 @@

# helper-license [![NPM version](https://badge.fury.io/js/helper-license.svg)](http://badge.fury.io/js/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)

@@ -6,4 +6,3 @@ > 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.

## Install
### Install with [npm](npmjs.org)
## Install with [npm](npmjs.org)

@@ -14,21 +13,50 @@ ```bash

## Usage example
## Run tests
Add a basic license statement to a document with [verb]:
```bash
npm test
```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
```
## Other engines/apps
## Register the helper
Add a basic license statement
> This should work with any engine, here are a few examples
```js
var pkg = require('./package.json');
### [template](https://github.com/jonschlinkert/template)
// handlebars
Handlebars.compile('{{license this}}')(pkg);
// lo-dash
_.template('<%= license({licenses: licenses}) %>', )
// verb
verb.render('{%= license({licenses: licenses}) %}', pkg);
// all result in:
//=> Released under the MIT license
```
Linkify:
```js
_.template('<%= license({licenses: licenses, linkify: true}) %>', pkg);
//=> Released under the [MIT](https://github.com/jonschlinkert/helper-license/blob/master/LICENSE-MIT) license
```
## Registering the helper
> This should work with any engine, here are a few examples to get you started
### [template]
```js
template.helper('license', require('helper-license'));
```
### [assemble](https://github.com/assemble/assemble)
### [assemble]

@@ -39,3 +67,3 @@ ```js

### [verb](https://github.com/jonschlinkert/verb)
### [verb]

@@ -46,3 +74,3 @@ ```js

### [handlebars](https://github.com/wycats/handlebars.js/)
### [handlebars]

@@ -54,28 +82,16 @@ ```js

## Example usage
## 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)
Add a basic license statement
## Running tests
Install dev dependencies:
```js
var pkg = require('./package.json');
// handlebars
Handlebars.compile('{{license this}}')(pkg);
// lo-dash
_.template('<%= license({licenses: licenses}) %>', )
// verb
verb.render('{%= license({licenses: licenses}) %}', pkg);
// all result in:
//=> Released under the MIT license
```bash
npm i -d && npm test
```
Linkify:
```js
_.template('<%= license({licenses: licenses, linkify: true}) %>', pkg);
//=> Released under the [MIT](https://github.com/jonschlinkert/helper-license/blob/master/LICENSE-MIT) license
```
## Contributing

@@ -85,10 +101,9 @@ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/helpers/helper-license/issues)

## Author
**Jon Schlinkert**
+ [github/helpers](https://github.com/helpers)
+ [twitter/helpers](http://twitter.com/helpers)
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
## License
Copyright (c) 2014 Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license

@@ -98,2 +113,10 @@

_This file was generated by [verb](https://github.com/jonschlinkert/verb) on November 11, 2014._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on April 23, 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/
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