<commit_before>/**
 * Accessor class for compiled message functions generated by [messageformat](https://www.npmjs.com/package/messageformat)
 *
 * ```js
 * import Messages from 'messageformat-messages'
 * ```
 *
 * @module messageformat-messages
 */

module.exports = Messages;

/**
 * @alias module:messageformat-messages
 *
 * @param {object} msgData A map of locale codes to their function objects
 * @param {string} [defaultLocale] If not defined, default and initial locale is the first entry of `locales`
 *
 * @example
 * ```js
 * // build.js
 * import fs from 'fs';
 * import MessageFormat from 'messageformat';
 *
 * const mf = new MessageFormat(['en', 'fi']);
 * const msgSet = {
 *   en: {
 *     a: 'A {TYPE} example.',
 *     b: 'This has {COUNT, plural, one{one user} other{# users}}.',
 *     c: {
 *       d: 'We have {P, number, percent} code coverage.'
 *     }
 *   },
 *   fi: {
 *     b: 'Tällä on {COUNT, plural, one{yksi käyttäjä} other{# käyttäjää}}.',
 *     e: 'Minä puhun vain suomea.'
 *   }
 * };
 * fs.writeFileSync('messages.js', String(mf.compile(msgSet)));
 * ```
 *
 * ```js
 * // runtime.js
 * import Messages from 'messageformat-messages';
 * import msgData from './messages';
 *
 * const messages = new Messages(msgData, 'en');
 *
 * messages.hasMessage('a')                // true
 * messages.hasObject('c')                 // true
 * messages.get('b', { COUNT: 3 })         // 'This has 3 users.'
 * messages.get(['c', 'd'], { P: 0.314 })  // 'We have 31% code coverage.'
 *
 * messages.get('e')                       // 'e'
 * messages.setFallback('en', ['foo', 'fi'])
 * messages.get('e')                       // 'Minä puhun vain suomea.'
 *
 * messages.locale = 'fi'
 * messages.hasMessage('a')                // false
 * messages.hasMessage('a', 'en')          // true
 * messages.hasMessage('a', null, true)    // true
 * messages.hasObject('c')                 // false
 * messages.get('b', { COUNT: 3 })         // 'Tällä on 3 käyttäjää.'
 * messages.get('c').d({ P: 0.628 })       // 'We have 63% code coverage.'
 * ```
 */
class Messages {
  constructor(msgData, defaultLocale) {
    this._data = {};
    this._fallback = {};
    Object.keys(msgData).forEach(lc => {
      if (lc !== 'toString') {
        this._data[lc] = msgData[lc];
        if (defaultLocale === undefined) defaultLocale = lc;
      }
    });
    this.locale = defaultLocale;
    this._defaultLocale = this._locale;
  }

  /**
   * List of available locales
   * @readonly
   * @memberof module:messageformat-messages
   * @instance
   * @member {string[]} availableLocales
   */<commit_msg>fix(messages): Clarified constructor, removed double export (#254)<commit_after>/**
 * Accessor class for compiled message functions generated by [messageformat](https://www.npmjs.com/package/messageformat)
 *
 * ```js
 * import Messages from 'messageformat-messages'
 * ```
 *
 * @module messageformat-messages
 */

/**
 * @alias module:messageformat-messages
 *
 * @param {object} msgData A map of locale codes to their function objects
 * @param {string} [defaultLocale] If not defined, default and initial locale is the first entry of `locales`
 *
 * @example
 * ```js
 * // build.js
 * import fs from 'fs';
 * import MessageFormat from 'messageformat';
 *
 * const mf = new MessageFormat(['en', 'fi']);
 * const msgSet = {
 *   en: {
 *     a: 'A {TYPE} example.',
 *     b: 'This has {COUNT, plural, one{one user} other{# users}}.',
 *     c: {
 *       d: 'We have {P, number, percent} code coverage.'
 *     }
 *   },
 *   fi: {
 *     b: 'Tällä on {COUNT, plural, one{yksi käyttäjä} other{# käyttäjää}}.',
 *     e: 'Minä puhun vain suomea.'
 *   }
 * };
 * fs.writeFileSync('messages.js', String(mf.compile(msgSet)));
 * ```
 *
 * ```js
 * // runtime.js
 * import Messages from 'messageformat-messages';
 * import msgData from './messages';
 *
 * const messages = new Messages(msgData, 'en');
 *
 * messages.hasMessage('a')                // true
 * messages.hasObject('c')                 // true
 * messages.get('b', { COUNT: 3 })         // 'This has 3 users.'
 * messages.get(['c', 'd'], { P: 0.314 })  // 'We have 31% code coverage.'
 *
 * messages.get('e')                       // 'e'
 * messages.setFallback('en', ['foo', 'fi'])
 * messages.get('e')                       // 'Minä puhun vain suomea.'
 *
 * messages.locale = 'fi'
 * messages.hasMessage('a')                // false
 * messages.hasMessage('a', 'en')          // true
 * messages.hasMessage('a', null, true)    // true
 * messages.hasObject('c')                 // false
 * messages.get('b', { COUNT: 3 })         // 'Tällä on 3 käyttäjää.'
 * messages.get('c').d({ P: 0.628 })       // 'We have 63% code coverage.'
 * ```
 */
class Messages {
  constructor(msgData, defaultLocale) {
    this._data = {};
    this._fallback = {};
    Object.keys(msgData).forEach(lc => {
      if (lc !== 'toString') {
        this._data[lc] = msgData[lc];
        if (defaultLocale === undefined) defaultLocale = lc;
      }
    });
    this.locale = defaultLocale;
    this._defaultLocale = this.locale;
  }

  /**
   * List of available locales
   * @readonly
   * @memberof module:messageformat-messages
   * @instance
   * @member {string[]} availableLocales
   */
{'fraction_non_alphanumeric': 0.1776591688905833, 'fraction_numerical': 0.006671749904689287, 'mean_word_length': 2.530955585464334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '3810223', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1657, 'n_words': 428}