UNPKG

sugar-language

Version:

Language module for the Sugar Javascript utility library.

26 lines (23 loc) 690 B
'use strict'; var widthConversionTable = require('../var/widthConversionTable'); function convertCharacterWidth(str, mode, reg, type) { var table = widthConversionTable[type]; mode = (mode || '').replace(/all/, '').replace(/(\w)lphabet|umbers?|atakana|paces?|unctuation/g, '$1'); return str.replace(reg, function(c) { var entry = table[c], to; if (entry) { if (mode === '' && entry.all) { return entry.all; } else { for (var i = 0, len = mode.length; i < len; i++) { to = entry[mode.charAt(i)]; if (to) { return to; } } } } return c; }); } module.exports = convertCharacterWidth;