<commit_before>var compiler = require('ember-template-compiler');
var through = require('through2');
var gutil = require('gulp-util');
var merge = require('merge');
var path = require('path');
var async = require('async');

const PLUGIN_NAME = 'gulp-ember-templates';

var defaultOptions = {
  type: 'browser',
  moduleName: 'templates',
  compiler: null,
  precompile: true,
  isHTMLBars: false
};

var formats = {
  browser: function (compilerOutput, fileName, options) {
    var engine = !!options.isHTMLBars ? 'HTMLBars' : 'Handlebars';
    var funct = options.precompile ? 'template' : 'compile';
    var prefix = 'Ember.TEMPLATES["' + fileName + '"] = Ember.' + engine + '.' + funct + '(';
    var suffix = ');';

    return prefix + compilerOutput.toString() + suffix;
  },
  amd: function (compilerOutput, fileName, options) {
    var moduleName = '';

    if (options.moduleName) {
      moduleName = options.moduleName;

      if (moduleName[moduleName.length - 1] !== '/') {
        moduleName += '/';
      }
    }

    var prefix = 'define(["ember"], function (Ember) {\n';
    var suffix = ' });';

    var compilerOutput = formats.browser(compilerOutput, moduleName + fileName, options);

    return prefix + compilerOutput.toString() + suffix;
  },
  cjs: function (compilerOutput, fileName, options) {
    var prefix = 'module.exports = ';

    var compilerOutput = formats.browser(compilerOutput, fileName, options);

    return prefix + compilerOutput.toString();
  },
  es6: function (compilerOutput, fileName, options) {
    var prefix = 'export default function () { return ';
    var suffix = ' };'

    var compilerOutput = formats.browser(compilerOutput, fileName, options);

    return prefix + compilerOutput.toString() + suffix;
  }
};

function transformName (name, options, done) {
  var transformedName = name.startsWith('component/') ? name : name.split('/').slice(-1)[0].toString();

  if (options.name) {
    switch (typeof options.name)
    {
      case 'string':
        transformedName = options.name;
        break;

      case 'object':
        transformedName = name.replace(options.name.replace, options.name.with);
        break;

      case 'function':
        options.name(name, function (err, newName) {
           if (err) return done(err);

           transformedName = newName;
        });
        break;<commit_msg>changed startsWith to indexOf due is strange issue<commit_after>var compiler = require('ember-template-compiler');
var through = require('through2');
var gutil = require('gulp-util');
var merge = require('merge');
var path = require('path');
var async = require('async');

const PLUGIN_NAME = 'gulp-ember-templates';

var defaultOptions = {
  type: 'browser',
  moduleName: 'templates',
  compiler: null,
  precompile: true,
  isHTMLBars: false
};

var formats = {
  browser: function (compilerOutput, fileName, options) {
    var engine = !!options.isHTMLBars ? 'HTMLBars' : 'Handlebars';
    var funct = options.precompile ? 'template' : 'compile';
    var prefix = 'Ember.TEMPLATES["' + fileName + '"] = Ember.' + engine + '.' + funct + '(';
    var suffix = ');';

    return prefix + compilerOutput.toString() + suffix;
  },
  amd: function (compilerOutput, fileName, options) {
    var moduleName = '';

    if (options.moduleName) {
      moduleName = options.moduleName;

      if (moduleName[moduleName.length - 1] !== '/') {
        moduleName += '/';
      }
    }

    var prefix = 'define(["ember"], function (Ember) {\n';
    var suffix = ' });';

    var compilerOutput = formats.browser(compilerOutput, moduleName + fileName, options);

    return prefix + compilerOutput.toString() + suffix;
  },
  cjs: function (compilerOutput, fileName, options) {
    var prefix = 'module.exports = ';

    var compilerOutput = formats.browser(compilerOutput, fileName, options);

    return prefix + compilerOutput.toString();
  },
  es6: function (compilerOutput, fileName, options) {
    var prefix = 'export default function () { return ';
    var suffix = ' };'

    var compilerOutput = formats.browser(compilerOutput, fileName, options);

    return prefix + compilerOutput.toString() + suffix;
  }
};

function transformName (name, options, done) {
  var transformedName = name.indexOf('component/') === 0 
    ? name
    : name.split('/').slice(-1)[0].toString();
  
  if (options.name) {
    switch (typeof options.name)
    {
      case 'string':
        transformedName = options.name;
        break;

      case 'object':
        transformedName = name.replace(options.name.replace, options.name.with);
        break;

      case 'function':
        options.name(name, function (err, newName) {
           if (err) return done(err);

           transformedName = newName;
        });
        break;
{'fraction_non_alphanumeric': 0.14584641138313453, 'fraction_numerical': 0.002301736765013601, 'mean_word_length': 3.226348364279399, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3118587', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1376, 'n_words': 353}