<commit_before>// Copyright 2019, University of Colorado Boulder

/**
 * Throws an assertion error if assertions are enabled and the value is invalid, otherwise returns the value.
 *
 * @author <NAME> (PhET Interactive Simulations)
 * @author <NAME> (PhET Interactive Simulations)
 */
define( require => {
  'use strict';

  // modules
  const axon = require( 'AXON/axon' );
  const ValidatorDef = require( 'AXON/ValidatorDef' );

  /**
   * If assertions are enabled, assert out if the value does not adhere to the validator. No-op without assertions.
   * @param {Object|null} value
   * @param {ValidatorDef} validator
   * @returns {Object|null} - returns the input value for chaining
   * @public
   */
  const validate = ( value, validator ) => {

    if ( assert ) {

      // Throws an error if not valid
      ValidatorDef.isValueValid( value, validator, { assertions: true } );
    }
    return value;
  };

  return axon.register( 'validate', validate );
} );<commit_msg>assert out if templated var is unfilled in PDOM, https://github.com/phetsims/scenery/issues/964<commit_after>// Copyright 2019, University of Colorado Boulder

/**
 * Throws an assertion error if assertions are enabled and the value is invalid, otherwise returns the value.
 *
 * @author <NAME> (PhET Interactive Simulations)
 * @author <NAME> (PhET Interactive Simulations)
 */
define( require => {
  'use strict';

  // modules
  const axon = require( 'AXON/axon' );
  const ValidatorDef = require( 'AXON/ValidatorDef' );

  /**
   * If assertions are enabled, assert out if the value does not adhere to the validator. No-op without assertions.
   * @param {*} value
   * @param {ValidatorDef} validator
   * @returns {*} - returns the input value for chaining
   * @public
   */
  const validate = ( value, validator ) => {

    if ( assert ) {

      // Throws an error if not valid
      ValidatorDef.isValueValid( value, validator, { assertions: true } );
    }
    return value;
  };

  /**
   * validate that the input is a string without any unfilled template variables, like `{{myVar}}`.
   * @param {*} value to be validated
   * @returns {*} - returns the input value for chaining
   */
  validate.stringWithoutTemplateVars = value => {
    return validate( value, {
      valueType: 'string',
      isValidValue: v => !/\{\{\w*\}\}/.test( v )
    } );
  };

  return axon.register( 'validate', validate );
} );
{'fraction_non_alphanumeric': 0.12224532224532225, 'fraction_numerical': 0.004573804573804574, 'mean_word_length': 3.155440414507772, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2587605', 'n_tokens_mistral': 735, 'n_tokens_neox': 688, 'n_words': 250}