1.0.0 • Published 8 years ago

generate-userscript-header v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

About

This module generates a userscript header string to append to your scripts.

Usage

First install: npm install generate-userscript-header

Then you can use it:

var generateUserscriptHeader = require('generate-userscript-header');

var userscript = {
	'name': 'ACME Userscript Maker',
	'namespace': 'http://example.com/',
	'author': '{{{pkg.author}}}',
	'homepage': '{{{pkg.homepage}}}',
	'grant': 'none',
	'include': [
		'http://google.com/*',
		'https://google.com/*'
	]
};

var context = {
	pkg: {
		author: 'John Doe',
		homepage: 'http://example.com/johndoe'
	}
};

var header = generateUserscriptHeader(userscript, context);

console.log(header);

Output:

// ==UserScript==
// @name ACME Userscript Maker
// @namespace http://example.com/
// @author John Doe
// @homepage http://example.com/johndoe
// @grant none
// @include http://google.com/*
// @include https://google.com/*
// ==/UserScript==

API

This module exports a single method that outputs a userscript metadata block as a string given the data to convert. Data is parsed with mustache and replaced with the data of a certain context.

Syntax

var generate = require('generate-userscript-header');
generate(userscript, context)

Parameters

NameTypeDescription
userscriptobjectThe object containing the userscript data.
contextobjectThe data used to parse values with mustache. Use {{{yourKey}}} in the data to parse.

Return

TypeDescription
stringThe finalized metadata block.