phetsims / query-string-machine

Query String Machine is a query string parser that supports type coercion, default values & validation. No dependencies.
MIT License
3 stars 3 forks source link

Remove lodash usage #40

Closed chrisklus closed 4 years ago

chrisklus commented 4 years ago

From https://github.com/phetsims/query-string-machine/issues/39#issuecomment-601901542.

/**
 * Determines if there is a warning for a specified key.
 * @param {string} key
 * @returns {boolean}
 * @public
 */
hasWarning: function( key ) {
  return _.some( this.warnings, warning => warning.key === key );
}

In https://github.com/phetsims/joist/issues/593, @pixelzoom and I used lodash for the hasWarning function, as @pixelzoom needed the function in NaturalSelectionQueryParameters.js. I'll implement a manual version instead.

chrisklus commented 4 years ago

Committed above, @pixelzoom please review.

pixelzoom commented 4 years ago

Why do you iterate over all warnings? This should return as soon as key is found. I.e.:

      hasWarning: function( key ) {
         let hasWarning = false;
         for ( let i = 0; i < this.warnings.length && !hasWarning; i++ ) {
           hasWarning = ( this.warnings[ i ].key === key );
         }
         return hasWarning;
      }
chrisklus commented 4 years ago

Thanks, fixed above. Working on my end, feel free to close if it looks good.

pixelzoom commented 4 years ago

👍 Testing in Natural Selection. Closing.