2013-06-01 00:57:28 +02:00
|
|
|
var assert = require('assert');
|
2013-05-31 08:26:11 +02:00
|
|
|
|
|
|
|
// from normalize-package-data/lib/fixer.js
|
|
|
|
module.exports.validate_name = function(name) {
|
|
|
|
if (
|
|
|
|
name.charAt(0) === "." ||
|
|
|
|
name.match(/[\/@\s\+%:]/) ||
|
|
|
|
name !== encodeURIComponent(name) ||
|
|
|
|
name.toLowerCase() === "node_modules" ||
|
|
|
|
name.toLowerCase() === "favicon.ico"
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-01 00:57:28 +02:00
|
|
|
function is_object(obj) {
|
|
|
|
return typeof(obj) === 'object' && !Array.isArray(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.validate_metadata = function(object, name) {
|
|
|
|
assert(is_object(object));
|
|
|
|
assert.equal(object._id, name);
|
|
|
|
assert.equal(object.name, name);
|
|
|
|
|
|
|
|
if (!is_object(object['dist-tags'])) {
|
|
|
|
object['dist-tags'] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_object(object['versions'])) {
|
|
|
|
object['versions'] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|