src/phonetics/nysiis.js
function nysiis(type, name) {
  if (typeof name !== 'string')
    throw Error('talisman/phonetics/nysiis: the given name is not a string.');

  // Preparing the string
  name = deburr(name)
    .toUpperCase()
    .trim()
    .replace(/[^A-Z]/g, '');

  // Getting the proper patterns
  const patterns = PATTERNS[type];

  // Applying the first substitutions
  for (let i = 0, l = patterns.first.length; i < l; i++) {
    const [match, replacement] = patterns.first[i];

    name = name.replace(match, replacement);
  }

  // Storing the first letter
  const firstLetter = name.charAt(0);

  // Eating the first letter if applying the original algorithm
  if (type === 'original')
    name = name.slice(1);

  // Applying the second substitutions
  for (let i = 0, l = patterns.second.length; i < l; i++) {
    const [match, replacement] = patterns.second[i];

    name = name.replace(match, replacement);
  }

  // Returning the squeezed code
  return firstLetter + squeeze(name);
}
function nysiis(type, name) {
  if (typeof name !== 'string')
    throw Error('talisman/phonetics/nysiis: the given name is not a string.');

  // Preparing the string
  name = deburr(name)
    .toUpperCase()
    .trim()
    .replace(/[^A-Z]/g, '');

  // Getting the proper patterns
  const patterns = PATTERNS[type];

  // Applying the first substitutions
  for (let i = 0, l = patterns.first.length; i < l; i++) {
    const [match, replacement] = patterns.first[i];

    name = name.replace(match, replacement);
  }

  // Storing the first letter
  const firstLetter = name.charAt(0);

  // Eating the first letter if applying the original algorithm
  if (type === 'original')
    name = name.slice(1);

  // Applying the second substitutions
  for (let i = 0, l = patterns.second.length; i < l; i++) {
    const [match, replacement] = patterns.second[i];

    name = name.replace(match, replacement);
  }

  // Returning the squeezed code
  return firstLetter + squeeze(name);
}
function nysiis ( type , name ) { if ( typeof name !== 'string' ) throw Error ( 'talisman/phonetics/nysiis: the given name is not a string.' ) ; // Preparing the string name = deburr ( name ) . toUpperCase ( ) . trim ( ) . replace ( / [^A-Z] / g , '' ) ; // Getting the proper patterns const patterns = PATTERNS [ type ] ; // Applying the first substitutions for ( let i = 0 , l = patterns . first . length ; i < l ; i ++ ) { const [ match , replacement ] = patterns . first [ i ] ; name = name . replace ( match , replacement ) ; } // Storing the first letter const firstLetter = name . charAt ( 0 ) ; // Eating the first letter if applying the original algorithm if ( type === 'original' ) name = name . slice ( 1 ) ; // Applying the second substitutions for ( let i = 0 , l = patterns . second . length ; i < l ; i ++ ) { const [ match , replacement ] = patterns . second [ i ] ; name = name . replace ( match , replacement ) ; } // Returning the squeezed code return firstLetter + squeeze ( name ) ; }
Function taking a single name and computing its NYSIIS code.

@param  {string}  name - The name to process.
@return {string}       - The NYSIIS code.

@throws {Error} The function expects the name to be a string.
Function taking a single name and computing its NYSIIS code .