gerber-to-svg
Advanced tools
Comparing version 1.0.0 to 1.1.0
58
API.md
@@ -10,2 +10,28 @@ # gerber-to-svg API | ||
<!-- TOC depthFrom:2 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 --> | ||
- [input](#input) | ||
- [streaming API](#streaming-api) | ||
- [callback API](#callback-api) | ||
- [static methods](#static-methods) | ||
- [clone](#clone) | ||
- [render](#render) | ||
- [events](#events) | ||
- [output](#output) | ||
- [options](#options) | ||
- [id option](#id-option) | ||
- [class option](#class-option) | ||
- [color option](#color-option) | ||
- [pretty option](#pretty-option) | ||
- [parsing and plotting options](#parsing-and-plotting-options) | ||
- [public properties](#public-properties) | ||
- [parser and plotter](#parser-and-plotter) | ||
- [defs](#defs) | ||
- [layer](#layer) | ||
- [viewBox](#viewbox) | ||
- [width and height](#width-and-height) | ||
- [units](#units) | ||
<!-- /TOC --> | ||
## input | ||
@@ -67,2 +93,34 @@ | ||
## static methods | ||
The factory function also includes several static methods for working with the converter objects. | ||
### clone | ||
Clones the public properties of a converter (expect for `parser` and `plotter`) to a simple object for storage and/or caching. | ||
`gerberToSvg.clone(converter)` | ||
``` javascript | ||
var gerberToSvg = require('gerber-to-svg') | ||
var converter = gerberToSvg(input, options, function(error, result) { | ||
var converterClone = gerberToSvg.clone(converter) | ||
storeSomehow(converterClone) | ||
}) | ||
``` | ||
### render | ||
Returns the SVG string from a completed converter or a clone of a completed converter. | ||
`gerberToSvg.render(converter, [id], [className], [color])` | ||
``` javascript | ||
var gerberToSvg = require('gerber-to-svg') | ||
var converter = getConverterCloneSomehow() | ||
var id = 'my-cool-id' | ||
var svgString = gerberToSvg.render(converter, id) | ||
``` | ||
## events | ||
@@ -69,0 +127,0 @@ |
@@ -5,2 +5,3 @@ // gerber to svg transform stream | ||
var isString = require('lodash.isstring') | ||
var pick = require('lodash.pick') | ||
var gerberParser = require('gerber-parser') | ||
@@ -10,2 +11,3 @@ var gerberPlotter = require('gerber-plotter') | ||
var PlotterToSvg = require('./plotter-to-svg') | ||
var render = require('./_render') | ||
@@ -50,3 +52,3 @@ var parseOptions = function(options) { | ||
var gerberToSvg = function(gerber, options, done) { | ||
module.exports = function gerberConverterFactory(gerber, options, done) { | ||
var opts = parseOptions(options) | ||
@@ -81,5 +83,2 @@ var callbackMode = (done != null) | ||
if (gerber.pipe) { | ||
gerber.once('error', function handleStreamError(e) { | ||
converter.emit('error', e) | ||
}) | ||
gerber.setEncoding('utf8') | ||
@@ -125,2 +124,6 @@ gerber.pipe(parser) | ||
module.exports = gerberToSvg | ||
module.exports.render = render | ||
module.exports.clone = function cloneConverter(converter) { | ||
return pick(converter, ['defs', 'layer', 'viewBox', 'width', 'height', 'units']) | ||
} |
@@ -14,2 +14,4 @@ // transform stream to take plotter objects and convert them to an SVG string | ||
var util = require('./_util') | ||
var render = require('./_render') | ||
var shift = util.shift | ||
@@ -85,41 +87,7 @@ var xmlNode = util.xmlNode | ||
PlotterToSvg.prototype._flush = function(done) { | ||
var result = xmlNode('svg', false, { | ||
id: this._id, | ||
class: this._className, | ||
xmlns: 'http://www.w3.org/2000/svg', | ||
version: 1.1, | ||
'xmlns:xlink': 'http://www.w3.org/1999/xlink', | ||
'stroke-linecap': 'round', | ||
'stroke-linejoin': 'round', | ||
'stroke-width': 0, | ||
'fill-rule': 'evenodd', | ||
color: this._color, | ||
width: this.width + this.units, | ||
height: this.height + this.units, | ||
viewBox: this.viewBox.join(' ') | ||
}) | ||
// shut off step repeat finish any in-progress clear layer and/or repeat | ||
this._handleNewRepeat([]) | ||
// add the defs | ||
if (this.defs) { | ||
result += '<defs>' + this.defs + '</defs>' | ||
} | ||
this.push(render(this, this._id, this._className, this._color)) | ||
// add the layer | ||
if (this.layer) { | ||
var yTranslate = this.viewBox[3] + 2 * this.viewBox[1] | ||
var transform = 'translate(0,' + yTranslate + ') scale(1,-1)' | ||
result += xmlNode('g', false, { | ||
transform: transform, | ||
fill: 'currentColor', | ||
stroke: 'currentColor' | ||
}) | ||
result += this.layer + '</g>' | ||
} | ||
result += '</svg>' | ||
this.push(result) | ||
done() | ||
@@ -126,0 +94,0 @@ } |
{ | ||
"name": "gerber-to-svg", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Gerber and NC drill file to SVG converter", | ||
@@ -54,3 +54,3 @@ "main": "lib/gerber-to-svg.js", | ||
"hapi": "^13.3.0", | ||
"inert": "^3.2.0", | ||
"inert": "^4.0.0", | ||
"istanbul": "^0.4.0", | ||
@@ -79,2 +79,3 @@ "lodash.assign": "^4.0.8", | ||
"lodash.map": "^4.3.0", | ||
"lodash.pick": "^4.2.0", | ||
"lodash.reduce": "^4.3.0", | ||
@@ -81,0 +82,0 @@ "minimist": "^1.1.0", |
@@ -29,3 +29,8 @@ // visual test server | ||
var renderGerber = function(gerberFile, done) { | ||
gerberToSvg(fs.createReadStream(gerberFile), path.basename(gerberFile), done) | ||
var renderOptions = { | ||
id: path.basename(gerberFile), | ||
optimizePaths: true | ||
} | ||
gerberToSvg(fs.createReadStream(gerberFile), renderOptions, done) | ||
} | ||
@@ -32,0 +37,0 @@ |
@@ -14,2 +14,4 @@ // test suite for gerber-to-svg | ||
var render = require('../lib/_render') | ||
var parserStub = sinon.stub() | ||
@@ -93,3 +95,3 @@ var plotterStub = sinon.stub() | ||
it('should pipe a stream input into the parser and listen for errors', function() { | ||
var input = {pipe: sinon.spy(), setEncoding: sinon.spy(), once: sinon.spy()} | ||
var input = {pipe: sinon.spy(), setEncoding: sinon.spy()} | ||
gerberToSvg(input, 'test-id') | ||
@@ -101,3 +103,2 @@ | ||
expect(input.setEncoding).to.have.been.calledWith('utf8') | ||
expect(input.once).to.have.been.calledWith('error') | ||
}) | ||
@@ -225,2 +226,42 @@ | ||
it('should expose the render function used by the converter', function() { | ||
var fakeConverter = { | ||
defs: 'the', | ||
layer: 'other', | ||
viewBox: [0, 1, 2, 3], | ||
width: 'I', | ||
height: 'must', | ||
units: 'have' | ||
} | ||
var expected = render(fakeConverter) | ||
expect(gerberToSvg.render(fakeConverter)).to.equal(expected) | ||
}) | ||
it('shoud have a clone method that clones the public properties of a converter', function() { | ||
var converter = { | ||
parser: 'hello', | ||
plotter: 'from', | ||
defs: 'the', | ||
layer: 'other', | ||
viewBox: 'side', | ||
width: 'I', | ||
height: 'must', | ||
units: 'have', | ||
_foo: 'called', | ||
_bar: 'a', | ||
_baz: 'thousand', | ||
_qux: 'times' | ||
} | ||
expect(gerberToSvg.clone(converter)).to.eql({ | ||
defs: 'the', | ||
layer: 'other', | ||
viewBox: 'side', | ||
width: 'I', | ||
height: 'must', | ||
units: 'have' | ||
}) | ||
}) | ||
describe('parser and plotter options', function() { | ||
@@ -227,0 +268,0 @@ it('should pass parser options to the parser', function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
195653
160
1491
0
14
+ Addedlodash.pick@^4.2.0
+ Addedlodash.pick@4.4.0(transitive)