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.
 
 
 
 

20 lines
544 B

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