From a99cb87186e68d38db7628aa4ea2731576dd8aee Mon Sep 17 00:00:00 2001 From: zepumph Date: Tue, 12 Feb 2019 16:14:33 -0900 Subject: [PATCH] factor out distanceFromOtherObjectPattern, https://github.com/phetsims/gravity-force-lab-basics/issues/88 --- js/util/StringUtils.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/util/StringUtils.js b/js/util/StringUtils.js index d95555e5..150c72eb 100644 --- a/js/util/StringUtils.js +++ b/js/util/StringUtils.js @@ -314,6 +314,17 @@ define( function( require ) { position -= searchString.length; var lastIndex = subjectString.indexOf( searchString, position ); return lastIndex !== -1 && lastIndex === position; + }, + + /** + * Assert that a template var is in a string. Useful for translated strings with a template var pattern like + * "Hello {{meanName}}" --> "Hello goofball". See StringUtils.fillIn() for base usages of template var pattern. + * + * @param {string} string + * @param {string} key + */ + assertContainsKey( string, key ) { + assert && assert( string.indexOf( `{{${key}}}` ) >= 0, 'key not' ); } };