node/deps/npm/node_modules/npm-user-validate/npm-user-validate.js

44 lines
830 B
JavaScript
Raw Normal View History

2013-05-15 05:37:59 +08:00
exports.email = email
exports.pw = pw
exports.username = username
2013-06-19 00:42:42 +08:00
var requirements = exports.requirements = {
username: {
lowerCase: 'Username must be lowercase',
urlSafe: 'Username may not contain non-url-safe chars',
dot: 'Username may not start with "."'
},
2014-06-06 06:18:15 +08:00
password: {},
2013-06-19 00:42:42 +08:00
email: {
valid: 'Email must be an email address'
}
};
2013-05-15 05:37:59 +08:00
function username (un) {
if (un !== un.toLowerCase()) {
2013-06-19 00:42:42 +08:00
return new Error(requirements.username.lowerCase)
2013-05-15 05:37:59 +08:00
}
if (un !== encodeURIComponent(un)) {
2013-06-19 00:42:42 +08:00
return new Error(requirements.username.urlSafe)
2013-05-15 05:37:59 +08:00
}
if (un.charAt(0) === '.') {
2013-06-19 00:42:42 +08:00
return new Error(requirements.username.dot)
2013-05-15 05:37:59 +08:00
}
return null
}
function email (em) {
if (!em.match(/^.+@.+\..+$/)) {
2013-06-19 00:42:42 +08:00
return new Error(requirements.email.valid)
2013-05-15 05:37:59 +08:00
}
return null
}
function pw (pw) {
return null
2013-06-19 00:42:42 +08:00
}