Skip to content

Commit

Permalink
Add whitelist validation for units of measurement to TNumber (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewadare authored and zepumph committed Oct 18, 2018
1 parent 28ee435 commit cf39107
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions js/types/TNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,52 @@ define( function( require ) {
var phetioInherit = require( 'PHET_IO/phetioInherit' );
var TObject = require( 'PHET_IO/types/TObject' );

var validUnits = [
'amperes',
'becquerels',
'coulombs',
'degrees Celsius',
'farads',
'grams',
'gray',
'henrys',
'henries',
'hertz',
'joules',
'katals',
'kelvins',
'liters',
'liters/second',
'lumens',
'lux',
'meters',
'moles',
'moles/liter',
'nanometers',
'newtons',
'ohms',
'pascals',
'percent',
'radians',
'seconds',
'siemens',
'sieverts',
'steradians',
'tesla',
'unitless',
'volts',
'watts',
'webers'
];

function validate( units ) {
assert && assert( validUnits.indexOf( units ) >= 0,
units + ' is not recognized as a valid unit of measurement' );
}

var TNumber = function( units ) {
assert && assert( units, 'All TNumbers should specify units' );
validate( units );
return phetioInherit( TObject, 'TNumber', function( instance, phetioID ) {
TObject.call( this, instance, phetioID );
assertTypeOf( instance, 'number' );
Expand Down

0 comments on commit cf39107

Please sign in to comment.