<commit_before>/**
 * Copyright IBM Corp. 2018, 2018
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

'use strict';

const CarbonIcons = require('@carbon/icons');
const {
  formatAttributes,
  getAttributes,
  toString,
} = require('@carbon/icon-helpers');
const { SafeString } = require('handlebars');

function iconHelper(name, { hash = {} } = {}) {
  const icon = CarbonIcons[name];
  if (!icon) {
    throw new Error(`Unable to find the icon: \`${name}\``);
  }
  const content = icon.content.map(toString);
  const attrs = {
    ...icon.attrs,
    ...hash,
  };
  return new SafeString(
    `<svg ${formatAttributes(getAttributes(attrs))}>${content.join('')}</svg>`
  );
}

module.exports = exports = function register({ handlebars }) {
  return handlebars.registerHelper('carbon-icon', iconHelper);
};
exports.iconHelper = iconHelper;<commit_msg>feat(icon-handlebars): allow object and hash attributes in same use (#261)<commit_after>/**
 * Copyright IBM Corp. 2018, 2018
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

'use strict';

const CarbonIcons = require('@carbon/icons');
const {
  formatAttributes,
  getAttributes,
  toString,
} = require('@carbon/icon-helpers');
const { SafeString } = require('handlebars');

function iconHelper(name, attributes = {}, options = {}) {
  const icon = CarbonIcons[name];
  if (!icon) {
    throw new Error(`Unable to find the icon: \`${name}\``);
  }
  const content = icon.content.map(toString);
  const attrs = {
    ...icon.attrs,
    ...Object.assign({}, attributes.hash || attributes, options.hash),
  };
  return new SafeString(
    `<svg ${formatAttributes(getAttributes(attrs))}>${content.join('')}</svg>`
  );
}

module.exports = exports = function register({ handlebars }) {
  return handlebars.registerHelper('carbon-icon', iconHelper);
};
exports.iconHelper = iconHelper;
{'fraction_non_alphanumeric': 0.1570862239841427, 'fraction_numerical': 0.011397423191278493, 'mean_word_length': 4.163682864450128, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4905429', 'n_tokens_mistral': 627, 'n_tokens_neox': 599, 'n_words': 170}