<commit_before>'use strict';

const through = require('through2');
const PluginError = require('gulp-util').PluginError;
const gutil = require('gulp-util');
const sqip = require('sqip');
const PLUGIN_NAME = 'gulp-sqip';

module.exports = () => {
    /**
     * @this {Transform}
     */

    const placeholders = [];

    const transform = function(file, encoding, callback) {
        if (file.isNull()) return callback(null, file);
        if (file.isStream()) this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported!'));
        if (file.isBuffer()) {
            const svg = sqip({
                filename: file.history[0],
                numberOfPrimitives: 22
            });
            svg.path = getFilenameFromPath(file.history[0]) + '.svg';
            placeholders.push(svg);
            callback();
        }
    };

    const endStreem = function(callback) {
        placeholders.forEach(svg => {
            this.push(new gutil.File({
                path: svg.path,
                contents: new Buffer(String(svg.final_svg))
            }));
        });
        callback();
    };

    const getFilenameFromPath = (path) => {
        return path.replace(/^.*[\\\/]/, '').replace(/\.[^/.]+$/, "");
    };

    return through.obj(transform, endStreem);
};<commit_msg>add optional parameter for drawing (numberOfPrimitives)<commit_after>'use strict';

const through = require('through2');
const PluginError = require('gulp-util').PluginError;
const gutil = require('gulp-util');
const sqip = require('sqip');
const PLUGIN_NAME = 'gulp-sqip';

module.exports = (options) => {
    /**
     * @this {Transform}
     */

    const placeholders = [];

    const transform = function(file, encoding, callback) {
        if (file.isNull()) return callback(null, file);
        if (file.isStream()) this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported!'));
        if (file.isBuffer()) {
            const svg = sqip({
                filename: file.history[0],
                numberOfPrimitives: (options !== undefined && typeof options.numberOfPrimitives === 'number') ? options.numberOfPrimitives : 22
            });
            svg.path = getFilenameFromPath(file.history[0]) + '.svg';
            placeholders.push(svg);
            callback();
        }
    };

    const endStreem = function(callback) {
        placeholders.forEach(svg => {
            this.push(new gutil.File({
                path: svg.path,
                contents: new Buffer(String(svg.final_svg))
            }));
        });
        callback();
    };

    const getFilenameFromPath = (path) => {
        return path.replace(/^.*[\\\/]/, '').replace(/\.[^/.]+$/, "");
    };

    return through.obj(transform, endStreem);
};
{'fraction_non_alphanumeric': 0.16363636363636364, 'fraction_numerical': 0.0036363636363636364, 'mean_word_length': 2.263345195729537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5333512', 'n_tokens_mistral': 820, 'n_tokens_neox': 787, 'n_words': 162}