<commit_before>'use strict';

/**
 * svg-sprite is a Node.js module for creating SVG sprites
 *
 * @see https://github.com/jkphl/svg-sprite
 *
 * @author <NAME> <<EMAIL>> (https://github.com/jkphl)
 * @copyright © 2018 <NAME>
 * @license MIT https://raw.github.com/jkphl/svg-sprite/master/LICENSE.txt
 */

var CONFIG = require('./svg-sprite/config');
var QUEUE = require('./svg-sprite/queue');
var SVGO = require('./svg-sprite/transform/svgo');
var LAYOUTER = require('./svg-sprite/layouter');
var _ = require('lodash');
var path = require('path');
var File = require('vinyl');
var events = require('events');
var async = require('async');
var os = require('os');
var pretty = require('prettysize');
var util = require('util');

/**
 * SVGSpriter class
 *
 * @param {Object} config                Configuration
 */
function SVGSpriter(config) {
    this.config = new CONFIG(config);
    this._queue = new QUEUE(this);
    this._shapes = [];
    this._shapeTransformers = { svgo: SVGO };
    this._compileQueue = [];
    this._shapesDest = [];

    // Detect the number of CPUs
    if (typeof os.cpus() === 'undefined') {
        this._limit = 2;
        this.info('Can\'t detect number of CPUs, falling back to 2');
    } else {
        this._limit = os.cpus().length * 2;
    }

    events.EventEmitter.call(this);

    this._queue.on('empty', this._compile.bind(this));
    this._queue.on('empty', this._getShapes.bind(this));
    this.on('compiled', this._compile.bind(this));

    this.info('Created spriter instance');
}

/**
 * Prototype
 *
 * @type {Object}
 */
SVGSpriter.prototype = Object.create(events.EventEmitter.prototype);

/**
 * SVG shapes making up the sprites
 *
 * @type {Array}
 */
SVGSpriter.prototype._shapes = [];

/**
 * Namespace powers
 *
 * @type {Array}
 */
SVGSpriter.prototype._namespacePow = [];

/**
 * Add an SVG shape to the sprites
 *
 * @param {File|String} file            Vinyl file object or absolute file path
 * @param {String} name                    Name part of the file path
 * @param {String} svg                    SVG content
 * @return {SVGSpriter}                    Self reference
 * @throws {Error}                        In case an invalid file should be added
 */
SVGSpriter.prototype.add = function (file, name, svg) {

    // If no vinyl file object has been given
    if (!this._isVinylFile(file)) {
        file = _.trim(file);
        var error = null;

        // If the name part of the file path is absolute
        if (name && path.isAbsolute(name)) {
            error = util.format('SVGSpriter.add: "%s" is not a valid relative file name', name);

            // Else
        } else {
            name = _.trimStart(_.trim(name), path.sep + '.') || path.basename(file);
            svg = _.trim(svg);

            // Argument validation
            if (arguments.length < 3) {
                error = 'SVGSpriter.add: You must provide 3 arguments';
            }
            if (!file.length) {
                error = util.format('SVGSpriter.add: "%s" is not a valid absolute file name', file);
            }
            if (!name.length) {
                error = util.format('SVGSpriter.add: "%s" is not a valid relative file name', name);
            }
            if (!svg.length) {
                error = 'SVGSpriter.add: You must provide SVG contents';
            }
            if (file.substr(-name.length) !== name) {
                error = util.format('SVGSpriter.add: "%s" is not the local part of "%s"', name, file);
            }
        }

        // In case of an error: Throw it!
        if (error) {
            var e = new Error(error);
            e.name = 'ArgumentError';
            e.errno = 1419945903;
            this.error(error, e);
            throw e;
        }<commit_msg>Replace `_.trim` with native (#408)<commit_after>'use strict';

/**
 * svg-sprite is a Node.js module for creating SVG sprites
 *
 * @see https://github.com/jkphl/svg-sprite
 *
 * @author <NAME> <<EMAIL>> (https://github.com/jkphl)
 * @copyright © 2018 <NAME>
 * @license MIT https://raw.github.com/jkphl/svg-sprite/master/LICENSE.txt
 */

var CONFIG = require('./svg-sprite/config');
var QUEUE = require('./svg-sprite/queue');
var SVGO = require('./svg-sprite/transform/svgo');
var LAYOUTER = require('./svg-sprite/layouter');
var _ = require('lodash');
var path = require('path');
var File = require('vinyl');
var events = require('events');
var async = require('async');
var os = require('os');
var pretty = require('prettysize');
var util = require('util');

/**
 * SVGSpriter class
 *
 * @param {Object} config                Configuration
 */
function SVGSpriter(config) {
    this.config = new CONFIG(config);
    this._queue = new QUEUE(this);
    this._shapes = [];
    this._shapeTransformers = { svgo: SVGO };
    this._compileQueue = [];
    this._shapesDest = [];

    // Detect the number of CPUs
    if (typeof os.cpus() === 'undefined') {
        this._limit = 2;
        this.info('Can\'t detect number of CPUs, falling back to 2');
    } else {
        this._limit = os.cpus().length * 2;
    }

    events.EventEmitter.call(this);

    this._queue.on('empty', this._compile.bind(this));
    this._queue.on('empty', this._getShapes.bind(this));
    this.on('compiled', this._compile.bind(this));

    this.info('Created spriter instance');
}

/**
 * Prototype
 *
 * @type {Object}
 */
SVGSpriter.prototype = Object.create(events.EventEmitter.prototype);

/**
 * SVG shapes making up the sprites
 *
 * @type {Array}
 */
SVGSpriter.prototype._shapes = [];

/**
 * Namespace powers
 *
 * @type {Array}
 */
SVGSpriter.prototype._namespacePow = [];

/**
 * Add an SVG shape to the sprites
 *
 * @param {File|String} file            Vinyl file object or absolute file path
 * @param {String} name                    Name part of the file path
 * @param {String} svg                    SVG content
 * @return {SVGSpriter}                    Self reference
 * @throws {Error}                        In case an invalid file should be added
 */
SVGSpriter.prototype.add = function (file, name, svg) {

    // If no vinyl file object has been given
    if (!this._isVinylFile(file)) {
        file = file.trim();
        var error = null;

        // If the name part of the file path is absolute
        if (name && path.isAbsolute(name)) {
            error = util.format('SVGSpriter.add: "%s" is not a valid relative file name', name);

            // Else
        } else {
            name = _.trimStart(name.trim(), path.sep + '.') || path.basename(file);
            svg = svg.trim();

            // Argument validation
            if (arguments.length < 3) {
                error = 'SVGSpriter.add: You must provide 3 arguments';
            }
            if (!file.length) {
                error = util.format('SVGSpriter.add: "%s" is not a valid absolute file name', file);
            }
            if (!name.length) {
                error = util.format('SVGSpriter.add: "%s" is not a valid relative file name', name);
            }
            if (!svg.length) {
                error = 'SVGSpriter.add: You must provide SVG contents';
            }
            if (file.substr(-name.length) !== name) {
                error = util.format('SVGSpriter.add: "%s" is not the local part of "%s"', name, file);
            }
        }

        // In case of an error: Throw it!
        if (error) {
            var e = new Error(error);
            e.name = 'ArgumentError';
            e.errno = 1419945903;
            this.error(error, e);
            throw e;
        }
{'fraction_non_alphanumeric': 0.14650271056459077, 'fraction_numerical': 0.005421129181541716, 'mean_word_length': 2.146422628951747, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 6, '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': '4579746', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2255, 'n_words': 628}