Musical keyboard component written in React.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

16 lines
449 B

  1. const NATURAL_KEYS = [0, 2, 4, 5, 7, 9, 11]
  2. export default (k: number): boolean => {
  3. const type = typeof (k as unknown)
  4. if (type as string !== 'number') {
  5. throw TypeError(`Invalid value type passed to isNaturalKey, expected 'number', got ${type}.`)
  6. }
  7. if (isNaN(k)) {
  8. throw RangeError('Value passed is NaN.')
  9. }
  10. if (k < 0) {
  11. throw RangeError('Value must be positive.')
  12. }
  13. return NATURAL_KEYS.includes(Math.floor(k) % 12)
  14. }