From e4003b4dd2e256b83e1e9138c74480eb7b65d40c Mon Sep 17 00:00:00 2001 From: GreLI Date: Sat, 20 Aug 2016 20:39:55 +0300 Subject: [PATCH] Crossplatform work. Fixes #538 --- .travis.yml | 3 ++- Makefile | 4 ++-- lib/svgo/js2svg.js | 21 +++++++++++---------- package.json | 3 ++- plugins/cleanupAttrs.js | 4 ++-- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9b9811b4..c685eca7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ language: node_js node_js: - - 0.10 - 0.12 + - 4 + - 6 branches: only: diff --git a/Makefile b/Makefile index 650288bd..c11daab9 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ test: - @NODE_ENV=test ./node_modules/.bin/mocha + @npm run test lib-cov: @./node_modules/.bin/istanbul instrument --output lib-cov --no-compact --variable global.__coverage__ lib @@ -16,6 +16,6 @@ coveralls: lib-cov travis: jshint test coveralls jshint: - @jshint --show-non-errors . + @npm run jshint .PHONY: test diff --git a/lib/svgo/js2svg.js b/lib/svgo/js2svg.js index 040d5e6e..913d7ba2 100644 --- a/lib/svgo/js2svg.js +++ b/lib/svgo/js2svg.js @@ -1,6 +1,7 @@ 'use strict'; -var EXTEND = require('whet.extend'), +var EOL = require('os').EOL, + EXTEND = require('whet.extend'), textElem = require('../../plugins/_collections.js').elemsGroups.textContent.concat('title'); var defaults = { @@ -69,14 +70,14 @@ function JS2SVG(config) { } if (this.config.pretty) { - this.config.doctypeEnd += '\n'; - this.config.procInstEnd += '\n'; - this.config.commentEnd += '\n'; - this.config.cdataEnd += '\n'; - this.config.tagShortEnd += '\n'; - this.config.tagOpenEnd += '\n'; - this.config.tagCloseEnd += '\n'; - this.config.textEnd += '\n'; + this.config.doctypeEnd += EOL; + this.config.procInstEnd += EOL; + this.config.commentEnd += EOL; + this.config.cdataEnd += EOL; + this.config.tagShortEnd += EOL; + this.config.tagOpenEnd += EOL; + this.config.tagCloseEnd += EOL; + this.config.textEnd += EOL; } this.indentLevel = 0; @@ -282,7 +283,7 @@ JS2SVG.prototype.createElem = function(data) { if (this.textContext == data) { this.textContext = null; - if (this.config.pretty) dataEnd = '\n'; + if (this.config.pretty) dataEnd = EOL; } return openIndent + diff --git a/package.json b/package.json index ac1dbe8e..3368c838 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ "example": "./examples" }, "scripts": { - "test": "make test" + "test": "set NODE_ENV=test && mocha", + "jshint": "jshint --show-non-errors ." }, "dependencies": { "sax": "~1.2.1", diff --git a/plugins/cleanupAttrs.js b/plugins/cleanupAttrs.js index a9e732f6..47e77ac7 100644 --- a/plugins/cleanupAttrs.js +++ b/plugins/cleanupAttrs.js @@ -12,8 +12,8 @@ exports.params = { spaces: true }; -var regNewlinesNeedSpace = /(\S)\n(\S)/g, - regNewlines = /\n/g, +var regNewlinesNeedSpace = /(\S)\r?\n(\S)/g, + regNewlines = /\r?\n/g, regSpaces = /\s{2,}/g; /**