All files / src extractSkinTone.js

100% Statements 5/5
100% Branches 4/4
100% Functions 1/1
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21              16x   16x 5x     11x         11x    
/**
 * @copyright   2017, Miles Johnson
 * @license     https://opensource.org/licenses/MIT
 * @flow
 */
 
export default function extractSkinTone(name: string): ?number {
  const type = name.match(/TYPE-(\d)/);
 
  if (!type) {
    return null;
  }
 
  const tone = parseFloat(type[1]);
 
  // EmojiOne data is 1, 2, 3, 4, 5, while unicode data is 1-2, 3, 4, 5, 6.
  // This is because type 1 and 2 on the Fitzpatrick scale are a combined tone.
  // https://en.wikipedia.org/wiki/Fitzpatrick_scale
  return (tone > 1) ? (tone - 1) : tone;
}