precis-js
Version:
A JavaScript implementation of RFC 7564 (The PRECIS Framework).
74 lines (60 loc) • 1.89 kB
JavaScript
// Generated by CoffeeScript 1.10.0
(function() {
var EmptyStringError, NicknameProfile, precis;
EmptyStringError = require('../error/EmptyStringError');
precis = require('../constants');
module.exports = NicknameProfile = (function() {
function NicknameProfile() {}
NicknameProfile.prototype.stringClass = precis.STRING_CLASS.FREEFORM;
NicknameProfile.prototype.widthMapping = precis.WIDTH_MAPPING.NONE;
NicknameProfile.prototype.caseMapping = precis.CASE_MAPPING.LOWERCASE;
NicknameProfile.prototype.normalization = precis.NORMALIZATION.KC;
NicknameProfile.prototype.directionality = precis.DIRECTIONALITY.NONE;
NicknameProfile.prototype.map = function(codepoints, enforcer) {
var i, last, state;
i = codepoints.length - 1;
last = i;
state = 0;
while (i >= 0) {
if (enforcer.propertyReader.isNonAsciiSpace(codepoints[i])) {
codepoints[i] = 0x20;
}
switch (state) {
case 0:
if (codepoints[i] === 0x20) {
codepoints.splice(i, 1);
} else {
last = i;
state = 1;
}
break;
case 1:
if (codepoints[i] === 0x20) {
state = 2;
} else {
last = i;
}
break;
case 2:
if (codepoints[i] !== 0x20) {
if (last > i + 2) {
codepoints.splice(i + 1, last - i - 2);
}
last = i;
state = 1;
}
}
--i;
}
if (last > 0) {
return codepoints.splice(0, last);
}
};
NicknameProfile.prototype.validate = function(codepoints) {
if (codepoints.length < 1) {
throw new EmptyStringError();
}
};
return NicknameProfile;
})();
}).call(this);