Socket
Socket
Sign inDemoInstall

svg-sprite

Package Overview
Dependencies
214
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.6 to 1.3.7

README.md

49

bin/svg-sprite.js

@@ -27,7 +27,7 @@ #!/usr/bin/env node

config = {},
JSONConfig = {mode: {}},
JSONConfig = { mode: {} },
map = {},
yargs = require('yargs')
.usage('Create one or multiple sprites of the given SVG files, optionally along with some stylesheet resources.\nUsage: $0 [options] files')
.version('version', 'Show version number', JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', 'package.json'), {encoding: 'utf8'})).version)
.version('version', 'Show version number', JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', 'package.json'), { encoding: 'utf8' })).version)
.help('help', 'Display this help information')

@@ -206,3 +206,3 @@ .wrap(null)

if (config.svg.rootAttributes) {
if (config.svg.rootAttributes && typeof config.svg.rootAttributes === 'string') {
try {

@@ -218,21 +218,23 @@ var JSONAttributesContent = fs.readFileSync(path.resolve(config.svg.rootAttributes));

// Expand transformation options
var transform = ('' + config.shape.transform).trim();
config.shape.transform = [];
(transform.length ? transform.split(',').map(function (trans) {
return ('' + trans).trim();
}) : []).forEach(function (transform) {
if (transform.length) {
if (('shape-transform-' + transform) in argv) {
try {
var transformConfigFile = argv['shape-transform-' + transform],
transformConfigJSON = fs.readFileSync(path.resolve(transformConfigFile), {encoding: 'utf8'}),
transformConfig = transformConfigJSON.trim() ? JSON.parse(transformConfigJSON) : {};
this.push(_.zipObject([transform], [transformConfig]));
} catch (e) {
if (typeof config.shape.transform === 'string') {
var transform = ('' + config.shape.transform).trim();
config.shape.transform = [];
(transform.length ? transform.split(',').map(function (trans) {
return ('' + trans).trim();
}) : []).forEach(function (transform) {
if (transform.length) {
if (('shape-transform-' + transform) in argv) {
try {
var transformConfigFile = argv['shape-transform-' + transform],
transformConfigJSON = fs.readFileSync(path.resolve(transformConfigFile), { encoding: 'utf8' }),
transformConfig = transformConfigJSON.trim() ? JSON.parse(transformConfigJSON) : {};
this.push(_.zipObject([transform], [transformConfig]));
} catch (e) {
}
} else {
this.push(transform);
}
} else {
this.push(transform);
}
}
}, config.shape.transform);
}, config.shape.transform);
}

@@ -292,2 +294,3 @@ // Run through all sprite modes

}, []).forEach(function (file) {
var basename = file;
file = path.resolve(file);

@@ -297,4 +300,8 @@ var stat = fs.lstatSync(file);

file = fs.readlinkSync(file);
basename = path.basename(file);
} else {
var basepos = basename.lastIndexOf('./');
basename = (basepos >= 0) ? basename.substr(basepos + 2) : path.basename(file);
}
spriter.add(file, path.basename(file), fs.readFileSync(file));
spriter.add(file, basename, fs.readFileSync(file));
});

@@ -301,0 +308,0 @@

@@ -0,1 +1,12 @@

## 1.3.7 Bugfix release (2017-06-01)
**This is going to be the final release in the 1.x line (except someone encounters some severe issues).**
* Updated dependencies
* Fixed invalid markup in `<defs>` example html ([#229](https://github.com/jkphl/svg-sprite/issues/229))
* Fallback for failing CPU detection ([#217](https://github.com/jkphl/svg-sprite/pull/217))
* Fixed broken SVGO configuration in CLI ([#216](https://github.com/jkphl/svg-sprite/pull/216), [#199](https://github.com/jkphl/svg-sprite/issues/199))
* Added glob base directory option to CLI ([#220](https://github.com/jkphl/svg-sprite/issues/220))
* Fixed broken `rootAttributes` option in CLI ([#228](https://github.com/jkphl/svg-sprite/issues/228))
## 1.3.6 Bugfix release (2016-08-29)

@@ -2,0 +13,0 @@ * Updated dependencies

@@ -201,2 +201,18 @@ svg-sprite [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] [![Development Dependency Status][devdepstat-image]][devdepstat-url]

### Advanced globbing
Some shells don't support the double-star character `**` for matching files in an arbitrary directory depth, so you should wrap your glob expression in single quotes when using it in your pattern. This will prevent your shell from trying to resolve it and rather delegate globbing to Node instead (which does support the `**` character).
```bash
$ svg-sprite --config config.json 'assets/**/*.svg'
```
The CLI typically uses only the basename of files for constructing the shape IDs in your sprite. That is, if an SVG source file is found at the path `assets/path/to/source.svg`, the shape inside the sprite will have the ID `source`. If you want to set a "base directory" from where ID traversal should start, simply add a symbolic link to that very same directory (`"./"`) in your pattern:
```bash
$ svg-sprite --config config.json 'assets/./**/*.svg'
```
The spriter will then use `path/to/source` for ID creation, resulting in the shape ID `path--to--source` (assuming you don't override the default shape ID generator function). Please be aware that the described feature won't work if the matched SVG files are symbolic links themselves.
### Inlined shape dimensions

@@ -203,0 +219,0 @@

@@ -239,10 +239,10 @@ svg-sprite [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] [![Development Dependency Status][devdepstat-image]][devdepstat-url]

------------------------ | --------------- | ------------- | ------------------------------------------ |
`xmlDeclaration` | Boolean∣String | `true` | Output an XML declaration at the very beginning of each compiled sprite. If you provide a non-empty string here, it will be used one-to-one as declaration (e.g. `<?xml version="1.0" encoding="utf-8"?>`). If you set this to `TRUE`, *svg-sprite* will look at the registered shapes for an XML declaration and use the first one it can find. |
`doctypeDeclaration` | Boolean∣String | `true` | Include a `<DOCTYPE>` declaration in each compiled sprite. If you provide a non-empty string here, it will be used one-to-one as declaration (e.g. `<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">`). If you set this to `TRUE`, *svg-sprite* will look at the registered shapes for a DOCTYPE declaration and use the first one it can find. |
`namespaceIDs` | Boolean | `true` | In order to avoid ID clashes, the default behavior is to namespace all IDs in the source SVGs before compiling them into a sprite. Each ID is prepended with a unique string. In some situations, it might be desirable to disable ID namespacing, e.g. when you want to script the resulting sprite. Just set `svg.namespaceIDs` to `FALSE` then and be aware that you might also want to disable SVGO's ID minification (`shape.transform.svgo.plugins: [{cleanupIDs: false}]`). |
`namespaceClassnames` | Boolean | `true` | In order to avoid CSS class name ambiguities, the default behavior is to namespace CSS class names in the source SVGs before compiling them into a sprite. Each class name is prepended with a unique string. Disable this option to keep the class names untouched. |
`dimensionAttributes` | Boolean | `true` | If truthy, `width` and `height` attributes will be set on the sprite's `<svg>` element (where applicable). |
`rootAttributes` | Object | | Shorthand for applying custom attributes to the outermost `<svg>` element. Please be aware that certain attributes (e.g. `viewBox`) will be calculated dynamically and override custom `rootAttributes` in any case. |
`precision` | Integer | | Floating point precision for CSS positioning values (defaults to `-1` meaning highest possible precision). |
`transform` | Function∣Array | | Callback (or list of callbacks) that will be applied to the resulting SVG sprites as global [post-processing transformation](#svg-sprite-customization). |
`svg.xmlDeclaration` | Boolean∣String | `true` | Output an XML declaration at the very beginning of each compiled sprite. If you provide a non-empty string here, it will be used one-to-one as declaration (e.g. `<?xml version="1.0" encoding="utf-8"?>`). If you set this to `TRUE`, *svg-sprite* will look at the registered shapes for an XML declaration and use the first one it can find. |
`svg.doctypeDeclaration` | Boolean∣String | `true` | Include a `<DOCTYPE>` declaration in each compiled sprite. If you provide a non-empty string here, it will be used one-to-one as declaration (e.g. `<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">`). If you set this to `TRUE`, *svg-sprite* will look at the registered shapes for a DOCTYPE declaration and use the first one it can find. |
`svg.namespaceIDs` | Boolean | `true` | In order to avoid ID clashes, the default behavior is to namespace all IDs in the source SVGs before compiling them into a sprite. Each ID is prepended with a unique string. In some situations, it might be desirable to disable ID namespacing, e.g. when you want to script the resulting sprite. Just set `svg.namespaceIDs` to `FALSE` then and be aware that you might also want to disable SVGO's ID minification (`shape.transform.svgo.plugins: [{cleanupIDs: false}]`). |
`svg.namespaceClassnames` | Boolean | `true` | In order to avoid CSS class name ambiguities, the default behavior is to namespace CSS class names in the source SVGs before compiling them into a sprite. Each class name is prepended with a unique string. Disable this option to keep the class names untouched. |
`svg.dimensionAttributes` | Boolean | `true` | If truthy, `width` and `height` attributes will be set on the sprite's `<svg>` element (where applicable). |
`svg.rootAttributes` | Object | | Shorthand for applying custom attributes to the outermost `<svg>` element. Please be aware that certain attributes (e.g. `viewBox`) will be calculated dynamically and override custom `rootAttributes` in any case. |
`svg.precision` | Integer | | Floating point precision for CSS positioning values (defaults to `-1` meaning highest possible precision). |
`svg.transform` | Function∣Array | | Callback (or list of callbacks) that will be applied to the resulting SVG sprites as global [post-processing transformation](#svg-sprite-customization). |

@@ -249,0 +249,0 @@

@@ -13,15 +13,15 @@ 'use strict';

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 pluck = require('lodash.pluck');
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');
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 pluck = require('lodash.pluck');
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');

@@ -31,12 +31,19 @@ /**

*
* @param {Object} config Configuration
* @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 = [];
this.config = new CONFIG(config);
this._queue = new QUEUE(this);
this._shapes = [];
this._shapeTransformers = { svgo: SVGO };
this._compileQueue = [];
this._shapesDest = [];
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);

@@ -75,39 +82,39 @@

*
* @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
* @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) {
SVGSpriter.prototype.add = function (file, name, svg) {
// If no vinyl file object has been given
if (!this._isVinylFile(file)) {
file = _.trim(file);
file = _.trim(file);
// 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);
error = util.format('SVGSpriter.add: "%s" is not a valid relative file name', name);
// Else
// Else
} else {
name = _.trimStart(_.trim(name), path.sep + '.') || path.basename(file);
svg = _.trim(svg);
name = _.trimStart(_.trim(name), path.sep + '.') || path.basename(file);
svg = _.trim(svg);
// Argument validation
var error = null;
var error = null;
if (arguments.length < 3) {
error = 'SVGSpriter.add: You must provide 3 arguments';
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);
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);
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';
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);
error = util.format('SVGSpriter.add: "%s" is not the local part of "%s"', name, file);
}

@@ -118,5 +125,5 @@ }

if (error) {
var e = new Error(error);
e.name = 'ArgumentError';
e.errno = 1419945903;
var e = new Error(error);
e.name = 'ArgumentError';
e.errno = 1419945903;
this.error(error, e);

@@ -127,10 +134,10 @@ throw e;

// Instanciate a vinyl file
file = new File({
base : file.substring(0, file.length - name.length),
path : file,
contents : new Buffer(svg)
file = new File({
base: file.substring(0, file.length - name.length),
path: file,
contents: new Buffer(svg)
});
}
file.base = path.resolve(file.base);
file.base = path.resolve(file.base);

@@ -148,7 +155,9 @@ // Add the shape to the internal processing queue

*
* @param {Mixed} file Arbitrary parameter
* @return {Boolean} Parameter is a vinyl file object
* @param {Mixed} file Arbitrary parameter
* @return {Boolean} Parameter is a vinyl file object
*/
SVGSpriter.prototype._isVinylFile = function(file) {
return _.isObject(file) && ((file instanceof File) || ((file.constructor.name === 'File') && (['path', 'contents', 'relative'].filter(function(property){ return property in this; }, file).length === 3)));
SVGSpriter.prototype._isVinylFile = function (file) {
return _.isObject(file) && ((file instanceof File) || ((file.constructor.name === 'File') && (['path', 'contents', 'relative'].filter(function (property) {
return property in this;
}, file).length === 3)));
};

@@ -159,32 +168,32 @@

*
* @param {SVGShape} shape Shape
* @param {Function} cb Callback
* @param {SVGShape} shape Shape
* @param {Function} cb Callback
*/
SVGSpriter.prototype._transformShape = function(shape, cb) {
var tasks = [],
that = this,
createTransformTask = function(transform){
SVGSpriter.prototype._transformShape = function (shape, cb) {
var tasks = [],
that = this,
createTransformTask = function (transform) {
// If it's a custom transformer
if (_.isFunction(transform[1])) {
return function() {
transform[1](shape, that, arguments[arguments.length - 1]);
};
// If it's a custom transformer
if (_.isFunction(transform[1])) {
return function () {
transform[1](shape, that, arguments[arguments.length - 1]);
};
// Else if it's a registered transformer
} else if ((transform[0] in that._shapeTransformers) && _.isObject(transform[1])) {
return function() {
that._shapeTransformers[transform[0]](shape, transform[1], that, arguments[arguments.length - 1]);
};
// Else if it's a registered transformer
} else if ((transform[0] in that._shapeTransformers) && _.isObject(transform[1])) {
return function () {
that._shapeTransformers[transform[0]](shape, transform[1], that, arguments[arguments.length - 1]);
};
// Else: Break
} else {
return null;
}
// Else: Break
} else {
return null;
}
};
};
// Run through all configured transforms
for (var t = 0, task; t < this.config.shape.transform.length; ++t) {
task = createTransformTask(this.config.shape.transform[t]);
task = createTransformTask(this.config.shape.transform[t]);

@@ -196,3 +205,3 @@ if (task) {

async.waterfall(tasks, function(error){
async.waterfall(tasks, function (error) {
cb(error);

@@ -205,9 +214,11 @@ });

*
* @param {Object} config Configuration
* @param {Function} cb Callback
* @param {Object} config Configuration
* @param {Function} cb Callback
*/
SVGSpriter.prototype.compile = function() {
var args = _.toArray(arguments),
config = _.isPlainObject(args[0]) ? this.config.filter(args.shift()) : _.clone(this.config.mode, true),
cb = _.isFunction(args[0]) ? args.shift() : function(error){ throw error; };
SVGSpriter.prototype.compile = function () {
var args = _.toArray(arguments),
config = _.isPlainObject(args[0]) ? this.config.filter(args.shift()) : _.clone(this.config.mode, true),
cb = _.isFunction(args[0]) ? args.shift() : function (error) {
throw error;
};

@@ -222,16 +233,16 @@ // Schedule a compilation run

*/
SVGSpriter.prototype._compile = function() {
SVGSpriter.prototype._compile = function () {
// If the shape queue is not currently active
if (!this._queue.active && this._compileQueue.length) {
var that = this;
var args = this._compileQueue.shift();
var that = this;
var args = this._compileQueue.shift();
// If this is a modeless run
if (args[0] === {}) {
var files = {};
var files = {};
// Add intermediate SVG files
if (that.config.shape.dest) {
files.shapes = that._getShapeFiles(that.config.shape.dest);
files.shapes = that._getShapeFiles(that.config.shape.dest);
that.verbose('Returning %d intermediate SVG files', files.shapes.length);

@@ -243,5 +254,7 @@ }

// Else
// Else
} else {
var masterShapes = _.reject(this._shapes, function(shape) { return !!shape.master; }).length;
var masterShapes = _.reject(this._shapes, function (shape) {
return !!shape.master;
}).length;
this.info('Compiling %d shapes ...', masterShapes);

@@ -256,17 +269,19 @@

// Sort shapes by ID
this._shapes = this._shapes.sort(this.config.shape.sort);
this._shapes = this._shapes.sort(this.config.shape.sort);
// Set the shape namespaces on all master shapes
_.reject(this._shapes, function(shape) { return !!shape.master; }).map(function(shape, index){
_.reject(this._shapes, function (shape) {
return !!shape.master;
}).map(function (shape, index) {
shape.setNamespace(this._indexNamespace(index));
}, this);
this._layout(args[0], function(error, files, data) {
this._layout(args[0], function (error, files, data) {
// Add intermediate SVG files
if (that.config.shape.dest) {
files.shapes = that._getShapeFiles(that.config.shape.dest);
files.shapes = that._getShapeFiles(that.config.shape.dest);
that.verbose('Returning %d intermediate SVG files', files.shapes.length);
}
that.info('Finished %s sprite compilation', _.keys(data).map(function(mode){
that.info('Finished %s sprite compilation', _.keys(data).map(function (mode) {
return '«' + mode + '»';

@@ -287,10 +302,10 @@ }).join(' + '));

*
* @param {Number} index Shape index
* @return {String} Namespace prefix
* @param {Number} index Shape index
* @return {String} Namespace prefix
*/
SVGSpriter.prototype._indexNamespace = function(index) {
SVGSpriter.prototype._indexNamespace = function (index) {
for (var ns = '', n = 0, c; n < this._namespacePow.length; ++n) {
c = Math.floor(index / this._namespacePow[n]);
ns += String.fromCharCode(97 + c);
index -= c * this._namespacePow[n];
c = Math.floor(index / this._namespacePow[n]);
ns += String.fromCharCode(97 + c);
index -= c * this._namespacePow[n];
}

@@ -303,14 +318,14 @@ return ns;

*
* @param {Object} config Layout configuration
* @param {Function} cb Callback
* @param {Object} config Layout configuration
* @param {Function} cb Callback
*/
SVGSpriter.prototype._layout = function(config, cb) {
var tasks = [],
files = {},
layout = new LAYOUTER(this, config),
createLayoutTask = function(k, m){
return function(_cb){
layout.layout(files, k, m, _cb);
SVGSpriter.prototype._layout = function (config, cb) {
var tasks = [],
files = {},
layout = new LAYOUTER(this, config),
createLayoutTask = function (k, m) {
return function (_cb) {
layout.layout(files, k, m, _cb);
};
};
};

@@ -321,3 +336,3 @@ for (var mode in config) {

async.parallelLimit(tasks, os.cpus().length * 2, function(error, data){
async.parallelLimit(tasks, os.cpus().length * 2, function (error, data) {
cb(error, files, _.zipObject(pluck(data, 'key'), data));

@@ -330,6 +345,6 @@ });

*
* @param {String} dest Destination directory
* @param {Function} cb Callback
* @param {String} dest Destination directory
* @param {Function} cb Callback
*/
SVGSpriter.prototype.getShapes = function(dest, cb) {
SVGSpriter.prototype.getShapes = function (dest, cb) {
this._shapesDest.push([dest, cb]);

@@ -342,7 +357,7 @@ this._getShapes();

*/
SVGSpriter.prototype._getShapes = function() {
SVGSpriter.prototype._getShapes = function () {
// If the shape queue is not currently active
if (!this._queue.active) {
while(this._shapesDest.length) {
while (this._shapesDest.length) {
var args = this._shapesDest.shift();

@@ -357,11 +372,11 @@ args[1](null, this._getShapeFiles(args[0]));

*
* @param {String} dest Destination directory
* @return {Array} Shape file list
* @param {String} dest Destination directory
* @return {Array} Shape file list
*/
SVGSpriter.prototype._getShapeFiles = function(dest) {
return this._shapes.map(function(shape) {
SVGSpriter.prototype._getShapeFiles = function (dest) {
return this._shapes.map(function (shape) {
return new File({
base : this.config.dest,
path : path.join(dest, shape.id + '.svg'),
contents : new Buffer(shape.getSVG(false))
base: this.config.dest,
path: path.join(dest, shape.id + '.svg'),
contents: new Buffer(shape.getSVG(false))
});

@@ -374,20 +389,20 @@ }, this);

*
* @param {Object} files Files
* @param {Object} files Files
*/
SVGSpriter.prototype._logStats = function(files) {
var sizes = {},
exts = {};
SVGSpriter.prototype._logStats = function (files) {
var sizes = {},
exts = {};
for (var mode in files) {
for (var resource in files[mode]) {
var file = files[mode][resource].relative,
ext = path.extname(files[mode][resource].path).toUpperCase();
exts[ext] = (exts[ext] || 0) + 1;
sizes[file] = pretty(files[mode][resource].contents.length);
var file = files[mode][resource].relative,
ext = path.extname(files[mode][resource].path).toUpperCase();
exts[ext] = (exts[ext] || 0) + 1;
sizes[file] = pretty(files[mode][resource].contents.length);
}
}
this.info('Created ' + _.toPairs(exts).map(function(ext){
return ext[1] + ' x ' + ext[0].substr(1);
}).join(', '));
this.info('Created ' + _.toPairs(exts).map(function (ext) {
return ext[1] + ' x ' + ext[0].substr(1);
}).join(', '));
Object.keys(sizes).sort().forEach(function(file){
Object.keys(sizes).sort().forEach(function (file) {
this.verbose('Created %s: %s', file, sizes[file]);

@@ -400,3 +415,3 @@ }, this);

*/
SVGSpriter.prototype.info = function() {
SVGSpriter.prototype.info = function () {
this.config.log.info.apply(this.config.log, arguments);

@@ -408,3 +423,3 @@ };

*/
SVGSpriter.prototype.verbose = function() {
SVGSpriter.prototype.verbose = function () {
this.config.log.verbose.apply(this.config.log, arguments);

@@ -416,3 +431,3 @@ };

*/
SVGSpriter.prototype.debug = function() {
SVGSpriter.prototype.debug = function () {
this.config.log.debug.apply(this.config.log, arguments);

@@ -424,3 +439,3 @@ };

*/
SVGSpriter.prototype.error = function() {
SVGSpriter.prototype.error = function () {
this.config.log.error.apply(this.config.log, arguments);

@@ -432,7 +447,7 @@ };

*
* @param {Object} config Configuration
* @return {SVGSpriter} SVGSpriter instance
* @param {Object} config Configuration
* @return {SVGSpriter} SVGSpriter instance
*/
module.exports = function(config) {
module.exports = function (config) {
return new SVGSpriter(config || {});
};

@@ -13,2 +13,4 @@ 'use strict';

var dateFormat = require('dateformat');
var _ = require('lodash'),

@@ -98,5 +100,2 @@ path = require('path'),

if (_.isString(this.log)) {
var twoDigits = function(i) {
return ('0' + i).slice(-2);
};
this.log = new winston.Logger({

@@ -110,3 +109,3 @@ transports : [new (winston.transports.Console)({

var now = new Date();
return now.getFullYear() + '-' + twoDigits(now.getMonth()) + '-' + twoDigits(now.getDate()) + ' ' + twoDigits(now.getHours()) + ':' + twoDigits(now.getMinutes()) + ':' + twoDigits(now.getSeconds());
return dateFormat(now, 'yyyy-mm-dd HH:MM:ss');
}

@@ -113,0 +112,0 @@ })]

@@ -182,3 +182,3 @@ 'use strict';

async.parallelLimit(tasks, os.cpus().length * 2, cb);
async.parallelLimit(tasks, this._spriter._limit, cb);
};

@@ -185,0 +185,0 @@

@@ -27,3 +27,2 @@ 'use strict';

this._files = [];
this._limit = os.cpus().length * 2;
this.active = 0;

@@ -60,3 +59,3 @@

SVGSpriterQueue.prototype.process = function() {
if (this._files.length && (this.active < this._limit)) {
if (this._files.length && (this.active < this._spriter._limit)) {
++this.active;

@@ -63,0 +62,0 @@ var file = this._files.shift();

@@ -507,4 +507,4 @@ 'use strict';

if (this.viewBox !== false) {
this.width = this.viewBox[2];
this.height = this.viewBox[3];
this.width = this._round(this.viewBox[2]);
this.height = this._round(this.viewBox[3]);
}

@@ -520,4 +520,4 @@

var dimensions = JSON.parse(stdout.toString().trim());
that.width = dimensions.width;
that.height = dimensions.height;
that.width = that._round(dimensions.width);
that.height = that._round(dimensions.height);
cb(null);

@@ -759,3 +759,3 @@ } else if (stderr.length > 0) {

if (substIds !== null) {
str = str.replace(/url\s*\(\s*["']?([^\)]+)["']?\s*\)/g, function(match, id){
str = str.replace(/url\s*\(\s*["']?([^\s"'\)]+)["']?\s*\)/g, function(match, id){
return 'url(' + ((id in substIds) ? ('#' + substIds[id]) : id) + ')';

@@ -762,0 +762,0 @@ });

{
"name": "svg-sprite",
"version": "1.3.6",
"author": "Joschi Kuphal <joschi@kuphal.net> (https://jkphl.is)",
"description": "SVG sprites & stacks galore — A low-level Node.js module that takes a bunch of SVG files, optimizes them and bakes them into SVG sprites of several types along with suitable stylesheet resources (e.g. CSS, Sass, LESS, Stylus, etc.)",
"homepage": "https://github.com/jkphl/svg-sprite",
"repository": {
"type": "git",
"url": "https://github.com/jkphl/svg-sprite.git"
},
"bugs": {
"url": "https://github.com/jkphl/svg-sprite/issues"
},
"license": "MIT",
"engines": {
"node": ">= 4.0"
},
"main": "lib/svg-sprite.js",
"bin": {
"svg-sprite": "./bin/svg-sprite.js"
},
"directories": {
"test": "test"
},
"files": [
"bin",
"docs",
"lib",
"tmpl",
"CHANGELOG.md"
],
"scripts": {
"test": "istanbul test _mocha --report html -- test/*.js --reporter spec",
"lint": "jshint bin && jshint lib && jshint test",
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"dependencies": {
"mkdirp": "^0.5.1",
"async": "^2.0.1",
"lodash": "^4.15.0",
"lodash.pluck": "^3.1.2",
"glob": "^7.0.6",
"xmldom": "0.1.22",
"xpath": "^0.0.23",
"vinyl": "^1.2.0",
"svgo": "0.7.0",
"cssom": "^0.3.1",
"css-selector-parser": "^1.1.0",
"phantomjs-prebuilt": "^2.1.12",
"cssmin": "^0.4.3",
"mustache": "^2.2.1",
"js-yaml": "^3.6.1",
"yargs": "^5.0.0",
"winston": "^2.2.0",
"prettysize": "^0.0.3"
},
"devDependencies": {
"mocha": "",
"coveralls": "*",
"mocha-lcov-reporter": "*",
"istanbul": "*",
"should": "",
"rimraf": "",
"vinyl-fs": "^2.4.3",
"svg2png": "jkphl/svg2png",
"image-diff": "^1.6.3",
"node-sass": "^3.8.0",
"less": "^2.7.1",
"stylus": "^0.54.5",
"jshint": "^2.9.3",
"pn": "^1.0.0"
},
"keywords": [
"icon",
"icons",
"svg",
"png",
"sprite",
"spritesheet",
"stack",
"generator",
"css",
"sass",
"less",
"stylus",
"stylesheet",
"inline",
"html",
"vector",
"rwd",
"retina",
"mustache",
"gulpfriendly"
]
"name": "svg-sprite",
"version": "1.3.7",
"author": "Joschi Kuphal <joschi@kuphal.net> (https://jkphl.is)",
"description": "SVG sprites & stacks galore — A low-level Node.js module that takes a bunch of SVG files, optimizes them and bakes them into SVG sprites of several types along with suitable stylesheet resources (e.g. CSS, Sass, LESS, Stylus, etc.)",
"homepage": "https://github.com/jkphl/svg-sprite",
"repository": {
"type": "git",
"url": "https://github.com/jkphl/svg-sprite.git"
},
"bugs": {
"url": "https://github.com/jkphl/svg-sprite/issues"
},
"license": "MIT",
"engines": {
"node": ">= 4.0"
},
"main": "lib/svg-sprite.js",
"bin": {
"svg-sprite": "./bin/svg-sprite.js"
},
"directories": {
"test": "test"
},
"files": [
"bin",
"docs",
"lib",
"tmpl",
"CHANGELOG.md"
],
"scripts": {
"test": "istanbul test _mocha --report html -- test/*.js --reporter spec",
"lint": "jshint bin && jshint lib && jshint test",
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"dependencies": {
"async": "^2.4.1",
"css-selector-parser": "^1.3.0",
"cssmin": "^0.4.3",
"cssom": "^0.3.2",
"dateformat": "^2.0.0",
"glob": "^7.1.2",
"js-yaml": "^3.8.4",
"lodash": "^4.17.4",
"lodash.pluck": "^3.1.2",
"mkdirp": "^0.5.1",
"mustache": "^2.3.0",
"phantomjs-prebuilt": "^2.1.14",
"prettysize": "^0.1.0",
"svgo": "^0.7.2",
"vinyl": "^2.0.2",
"winston": "^2.3.1",
"xmldom": "0.1.27",
"xpath": "^0.0.24",
"yargs": "^8.0.1"
},
"devDependencies": {
"mocha": "",
"coveralls": "*",
"mocha-lcov-reporter": "*",
"istanbul": "*",
"should": "",
"rimraf": "",
"vinyl-fs": "^2.4.4",
"svg2png": "jkphl/svg2png",
"image-diff": "^1.6.3",
"node-sass": "^4.5.3",
"less": "^2.7.2",
"stylus": "^0.54.5",
"jshint": "^2.9.4",
"pn": "^1.0.0"
},
"keywords": [
"icon",
"icons",
"svg",
"png",
"sprite",
"spritesheet",
"stack",
"generator",
"css",
"sass",
"less",
"stylus",
"stylesheet",
"inline",
"html",
"vector",
"rwd",
"retina",
"mustache",
"gulpfriendly"
]
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc