all files / music-notation/accidentals/ parse.js

100% Statements 6/6
100% Branches 6/6
100% Functions 1/1
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16                  19× 17× 17×    
'use strict'
 
var R = /^(#{1,}|b{1,}|x{1,}|)$/
 
/**
 * Given an accidentals string returns its alteration number
 *
 * @param {String} accidentals - the accidentals string
 * @param {boolean} skipValidation - true to skip validation
 */
module.exports = function (str, skip) {
  if (!skip && !R.exec(str)) return null
  var alt = str.replace(/x/g, '##').length
  return str[0] === '#' ? alt : -alt
}