UNPKG

precis-js

Version:

A JavaScript implementation of RFC 7564 (The PRECIS Framework).

55 lines (47 loc) 1.91 kB
// Generated by CoffeeScript 1.10.0 (function() { var PrecisEnforcer, precis, ucs2; precis = require('./constants'); ucs2 = require('punycode').ucs2; module.exports = PrecisEnforcer = (function() { function PrecisEnforcer(preparer, propertyReader, widthMapper, normalizer, directionalityValidator) { this.preparer = preparer; this.propertyReader = propertyReader; this.widthMapper = widthMapper; this.normalizer = normalizer; this.directionalityValidator = directionalityValidator; } PrecisEnforcer.prototype.enforce = function(profile, string) { var codepoints; codepoints = this.preparer.prepare(profile, string); if (typeof profile.mapWidth === 'function') { profile.mapWidth(codepoints, this); } else if (profile.widthMapping === precis.WIDTH_MAPPING.EAW) { this.widthMapper.map(codepoints); } if (typeof profile.map === 'function') { profile.map(codepoints, this); } if (typeof profile.mapCase === 'function') { profile.mapCase(codepoints, this); } else if (profile.caseMapping === precis.CASE_MAPPING.LOWERCASE) { codepoints = ucs2.decode(ucs2.encode(codepoints).toLowerCase()); } if (typeof profile.normalize === 'function') { profile.normalize(codepoints, this); } else { codepoints = this.normalizer.normalize(profile.normalization, codepoints); } if (typeof profile.validateDirectionality === 'function') { profile.validateDirectionality(codepoints, this); } else if (profile.directionality === precis.DIRECTIONALITY.BIDI) { this.directionalityValidator.validate(codepoints); } if (typeof profile.validate === 'function') { profile.validate(codepoints, this); } return ucs2.encode(codepoints); }; return PrecisEnforcer; })(); }).call(this);