metalsmith-validate
A Metalsmith plugin that allows you to easily validate file metadata, checking existence, type, and regex pattern.
Last updated 4 years ago by mikestopcontinues .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install metalsmith-validate 
SYNC missed versions from official npm registry.

metalsmith-validate

A Metalsmith plugin that allows you to validate file metadata. You can check existence, type, and regex pattern. Neat.

Features

  • works on files matching pattern
  • can specify default for when key unspecified
  • can test for existence or for lack thereof
  • can validate against type or array of types using check-types
  • can match against pattern as RegExp, string, or callback(value) returning boolean

Installation

$ npm install metalsmith-validate

Usage

Validate all files

Pass hash of file metadata keys and rules.

var validate = require('metalsmith-validate');

metalsmith.use(validate({
  title: {
  	exists: true,
  	type: 'String'
  },
  date: {
  	exists: true,
  	pattern: /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/
  },
  tag: {
  	default: 'news'
  },
  draft: {
  	exists: false
  }
}));

Validate pattern-matching files

Pass array of hashes with file-matching pattern and metadata validation hash:

var validate = require('metalsmith-validate');

metalsmith.use(validate([
	{
		pattern: 'post/*',
		metadata: {
			title: true, // shorthand for title: { exists: true }
			date: true,
			invalid: false
		}
	},
	{
		// pattern defaults to '**/*'
		metadata: {
			template: {
				default: function (file, data) {
					return file + '.jade';
				},
				pattern: function (value) {
					return value.match(/\.jade$/);
				}
			}
		}
	}
));

Notice, both default and pattern accept callbacks.

CLI Usage

All of the same options apply, just add them to the "plugins" key in your metalsmith.json configuration:

{
  "plugins": {
    "metalsmith-validate": [
      {
        "pattern": "page/*",
        "metadata": {
        	"title": {
        		"exists": true,
        		"type": "String"
        	}
        }
      }
    ]
  }
}

License

MIT

Current Tags

  • 0.1.4                                ...           latest (4 years ago)

4 Versions

  • 0.1.4                                ...           4 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |