library/converter.js
function fontConvert(content, to, from) {
  if (!content) {
    if (!globalOptions.isSilentMode()) console.warn('Content must be specified on knayi.fontConvert.');
    return '';
  }

  if (content === '' || !mmCharacterRange.test(content))
    return content;

  if (!to) {
    if (!globalOptions.isSilentMode()) console.error('Convert target font must be specified on knayi.fontConvert.');
    return content;
  }

  content = content.trim().replace(/\u200B/g, '');
  to = fontTypes[to];
  from = fontTypes[from];

  if (!to) {
    if (!globalOptions.isSilentMode()) console.error('Convert library dosen\'t have this fontType.')
    return content;
  } else if (!from) {
    from = fontDetect(content);
  }

  if (to === from) {
    return content;
  }

  var debug_logs = {
    to: to, from: from,
    matched_patterns: [],
    steps: []
  }

  content = spellingFix(content, from);
  var refLib = library.convert[from][to];

  for (var i = 0; i < refLib.oneTime.length; i++) {
    var rule1 = refLib.oneTime[i];
    // debugging
    if (this.debug && rule1[0].test(content)) {
      debug_logs.matched_patterns.push(rule1);
      debug_logs.steps.push(content);
    }
    content = content.replace(rule1[0], rule1[1]);
  }

  for (var j = 0; j < refLib.asLongAsMatch.length; j++) {
    var rule2 = refLib.asLongAsMatch[j];
    // debugging
    if (this.debug && rule2[0].test(content)) {
      debug_logs.matched_patterns.push(rule2);
      debug_logs.steps.push(content);
    }
    while (rule2[0].test(content)) {
      content = content.replace(rule2[0], rule2[1]);
    }
  }

  if (this.debug) {
    // final
    debug_logs.steps.push(content);
    return debug_logs;
  }

  return content;
}
function fontConvert(content, to, from) {
  if (!content) {
    if (!globalOptions.isSilentMode()) console.warn('Content must be specified on knayi.fontConvert.');
    return '';
  }

  if (content === '' || !mmCharacterRange.test(content))
    return content;

  if (!to) {
    if (!globalOptions.isSilentMode()) console.error('Convert target font must be specified on knayi.fontConvert.');
    return content;
  }

  content = content.trim().replace(/\u200B/g, '');
  to = fontTypes[to];
  from = fontTypes[from];

  if (!to) {
    if (!globalOptions.isSilentMode()) console.error('Convert library dosen\'t have this fontType.')
    return content;
  } else if (!from) {
    from = fontDetect(content);
  }

  if (to === from) {
    return content;
  }

  var debug_logs = {
    to: to, from: from,
    matched_patterns: [],
    steps: []
  }

  content = spellingFix(content, from);
  var refLib = library.convert[from][to];

  for (var i = 0; i < refLib.oneTime.length; i++) {
    var rule1 = refLib.oneTime[i];
    // debugging
    if (this.debug && rule1[0].test(content)) {
      debug_logs.matched_patterns.push(rule1);
      debug_logs.steps.push(content);
    }
    content = content.replace(rule1[0], rule1[1]);
  }

  for (var j = 0; j < refLib.asLongAsMatch.length; j++) {
    var rule2 = refLib.asLongAsMatch[j];
    // debugging
    if (this.debug && rule2[0].test(content)) {
      debug_logs.matched_patterns.push(rule2);
      debug_logs.steps.push(content);
    }
    while (rule2[0].test(content)) {
      content = content.replace(rule2[0], rule2[1]);
    }
  }

  if (this.debug) {
    // final
    debug_logs.steps.push(content);
    return debug_logs;
  }

  return content;
}
function fontConvert ( content , to , from ) { if ( ! content ) { if ( ! globalOptions . isSilentMode ( ) ) console . warn ( 'Content must be specified on knayi.fontConvert.' ) ; return '' ; } if ( content === '' || ! mmCharacterRange . test ( content ) ) return content ; if ( ! to ) { if ( ! globalOptions . isSilentMode ( ) ) console . error ( 'Convert target font must be specified on knayi.fontConvert.' ) ; return content ; } content = content . trim ( ) . replace ( / \u200B / g , '' ) ; to = fontTypes [ to ] ; from = fontTypes [ from ] ; if ( ! to ) { if ( ! globalOptions . isSilentMode ( ) ) console . error ( 'Convert library dosen\'t have this fontType.' ) return content ; } else if ( ! from ) { from = fontDetect ( content ) ; } if ( to === from ) { return content ; } var debug_logs = { to : to , from : from , matched_patterns : [ ] , steps : [ ] } content = spellingFix ( content , from ) ; var refLib = library . convert [ from ] [ to ] ; for ( var i = 0 ; i < refLib . oneTime . length ; i ++ ) { var rule1 = refLib . oneTime [ i ] ; // debugging if ( this . debug && rule1 [ 0 ] . test ( content ) ) { debug_logs . matched_patterns . push ( rule1 ) ; debug_logs . steps . push ( content ) ; } content = content . replace ( rule1 [ 0 ] , rule1 [ 1 ] ) ; } for ( var j = 0 ; j < refLib . asLongAsMatch . length ; j ++ ) { var rule2 = refLib . asLongAsMatch [ j ] ; // debugging if ( this . debug && rule2 [ 0 ] . test ( content ) ) { debug_logs . matched_patterns . push ( rule2 ) ; debug_logs . steps . push ( content ) ; } while ( rule2 [ 0 ] . test ( content ) ) { content = content . replace ( rule2 [ 0 ] , rule2 [ 1 ] ) ; } } if ( this . debug ) { // final debug_logs . steps . push ( content ) ; return debug_logs ; } return content ; }
Font Converter agent
@param content Text that you want to convert
@param to Type of font to convert. Default: "unicode";
@param from Type of font of content text
@return converted text
Font Converter agent