mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-13 03:35:52 +01:00
38 lines
769 B
JavaScript
38 lines
769 B
JavaScript
var assert = require('assert');
|
|
|
|
// 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;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|