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

/**
 * Retrieves the license entry for a media file from license.json.
 * This file is used when loading media files (images, audio,...) via media plugins.
 *
 * A license entry for a media file is found in a license.json file that is in
 * the same directory as the media file. A license entry has the following fields:
 *
 * text - copyright statement or "Public Domain"
 * projectURL - the URL for the resource
 * license - the name of license, such as "Public Domain"
 * notes - additional helpful information about the resource, or ""
 * exception - [optional] description of why the file is being used despite the fact that it doesn't match PhET's licensing policy
 *
 * For an example, see any of the license.json files in a PhET simulation's images directory.
 *
 * @author <NAME>
 */
(function() {
  'use strict';

  /**
   * Retrieves the license entry for a media file from license.json.
   *
   * @param {string} absolutePath - the path for the media file
   * @returns {Object|null} the entry from the license.json file, null if there is no entry
   *
   * @private
   */
  function getLicenseEntry( absolutePath ) {

    var lastSlashIndex = absolutePath.lastIndexOf( '/' );
    var prefix = absolutePath.substring( 0, lastSlashIndex );
    var licenseFilename = prefix + '/license.json'; // license.json is a sibling of the media file
    var mediaFilename = absolutePath.substring( lastSlashIndex + 1 ); // field name in license.json

    // read license.json
    var fileContents = global.phet.chipper.fs.readFileSync( licenseFilename, 'utf8' );
    var json = null;
    try {
      json = JSON.parse( fileContents );
    }
    catch( err ) {
      if ( err instanceof SyntaxError ) {
        throw new SyntaxError( 'syntax error in '+ licenseFilename );
      }
      else {
        throw err;
      }
    }

    // get the media file's license entry
    var entry = json[ mediaFilename ];
    if ( !entry ) {
      return null; // Not annotated in file
    }
    return entry;
  }

  // browser require.js-compatible definition
  if ( typeof define !== 'undefined' ) {
    define( function() {
      return getLicenseEntry;
    } );
  }

  // Node.js-compatible definition
  if ( typeof module !== 'undefined' ) {
    module.exports = getLicenseEntry;
  }<commit_msg>doc, #449<commit_after>// Copyright 2015, University of Colorado Boulder

/**
 * Retrieves the license entry for a media file from license.json.
 * This file is used when loading media files (images, audio,...) via media plugins.
 *
 * A license entry for a media file is found in a license.json file that is in
 * the same directory as the media file. A license entry has the following fields:
 *
 * text - copyright statement or "Public Domain"
 * projectURL - the URL for the resource
 * license - the name of license, such as "Public Domain"
 * notes - additional helpful information about the resource, or ""
 * exception - [optional] description of why the file is being used despite the fact that it doesn't match PhET's licensing policy
 *
 * For an example, see any of the license.json files in a PhET simulation's images directory.
 *
 * @author <NAME>
 */
(function() {
  'use strict';

  /**
   * Retrieves the license entry for a media file from license.json.
   *
   * @param {string} absolutePath - the path for the media file
   * @returns {Object|null} the entry from the license.json file, null if there is no entry
   *
   * @private
   */
  function getLicenseEntry( absolutePath ) {

    var lastSlashIndex = absolutePath.lastIndexOf( '/' );
    var prefix = absolutePath.substring( 0, lastSlashIndex );
    var licenseFilename = prefix + '/license.json'; // license.json is a sibling of the media file
    var mediaFilename = absolutePath.substring( lastSlashIndex + 1 ); // field name in license.json

    // read license.json
    var fileContents = global.phet.chipper.fs.readFileSync( licenseFilename, 'utf8' );
    var json = null;
    try {
      json = JSON.parse( fileContents );
    }
    catch( err ) {
      if ( err instanceof SyntaxError ) {
        // default message is incomprehensible, see chipper#449
        throw new SyntaxError( 'syntax error in '+ licenseFilename );
      }
      else {
        throw err;
      }
    }

    // get the media file's license entry
    var entry = json[ mediaFilename ];
    if ( !entry ) {
      return null; // Not annotated in file
    }
    return entry;
  }

  // browser require.js-compatible definition
  if ( typeof define !== 'undefined' ) {
    define( function() {
      return getLicenseEntry;
    } );
  }

  // Node.js-compatible definition
  if ( typeof module !== 'undefined' ) {
    module.exports = getLicenseEntry;
  }
{'fraction_non_alphanumeric': 0.09529806884970612, 'fraction_numerical': 0.0041981528127623844, 'mean_word_length': 2.8458434221146085, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '2106674', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1283, 'n_words': 535}