Skip to content

Commit

Permalink
merge plugins/roundNumericValues and plugins/removeDefaultPx into one…
Browse files Browse the repository at this point in the history
… plugins/cleanupNumericValues
  • Loading branch information
deepsweet committed Nov 29, 2012
1 parent 67daff2 commit 140daae
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 44 deletions.
7 changes: 2 additions & 5 deletions .svgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,13 @@ plugins:
active: true
type: perItem

- name: removeDefaultPx
active: true
type: perItem

- name: roundNumericValues
- name: cleanupNumericValues
active: true
type: perItem
params:
floatPrecision: 3
leadingZero: true
defaultPx: true

- name: removeUnknownsAndDefaults
active: true
Expand Down
17 changes: 12 additions & 5 deletions plugins/roundNumericValues.js → plugins/cleanupNumericValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ var regNumericValues = /^([\-+]?\d*\.?\d+)(px|pt|pc|mm|cm|m|in|ft|em|ex|%)?$/,
removeLeadingZero = require('../lib/svgo/tools').removeLeadingZero;

/**
* Round numeric values to the fixed precision.
* Round numeric values to the fixed precision,
* remove default 'px' units.
*
* @param {Object} item current iteration item
* @param {Object} params plugin params
* @return {Boolean} if false, item will be filtered out
*
* @author Kir Belevich
*/
exports.roundNumericValues = function(item, params) {
exports.cleanupNumericValues = function(item, params) {

if (item.isElem()) {

Expand All @@ -23,15 +24,21 @@ exports.roundNumericValues = function(item, params) {

// if attribute value matches regNumericValues
if (match) {
// then round it to the fixed precision
var num = +(+match[1]).toFixed(params.floatPrecision) + (match[2] || '');
// round it to the fixed precision
var num = +(+match[1]).toFixed(params.floatPrecision),
units = match[2] || '';

// and remove leading zero
if (params.leadingZero) {
num = removeLeadingZero(num);
}

attr.value = num;
// remove default 'px' units
if (params.defaultPx && units === 'px') {
units = '';
}

attr.value = num + units;
}
});

Expand Down
27 changes: 0 additions & 27 deletions plugins/removeDefaultPx.js

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions test/plugins/removeDefaultPx.01.orig.svg

This file was deleted.

3 changes: 0 additions & 3 deletions test/plugins/removeDefaultPx.01.should.svg

This file was deleted.

0 comments on commit 140daae

Please sign in to comment.