npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@moseskarunia/dxf

v4.7.2

Published

DXF parser for node/browser

Downloads

2

Readme

Build Status

dxf

DXF parser for node/browser.

Uses several ES6 features in the source code (import, classes, let, const, arrows) but is packaged using babel so you can use it in legacy JS environments.

Version 2.0 is a complete rewrite from the first attempt to write it in a SAX style, which wasn't really appropriate for a document with nested references (e.g inserts referencing blocks, nested inserts).

Version 3.0 converted the codebase to use standard JS, ES6 imports, stopped using Gulp, and updated & removed some dependencies.

Version 4.x is in progress and the aim is to use native SVG elements where possible, e.g. <circle />, <ellipse /> etc. 4.0 introduces the <circle /> element.

At this point in time, the important geometric entities are supported, but notably:

  • MTEXT
  • DIMENSION
  • STYLE
  • HATCH

and some others are parsed, but are not supported for SVG rendering (see section below on SVG rendering)

Getting started

There is an ES5 and ES6 example in the examples/ directory that show how to use the library. There are exposed functions for advanced users, but for the majority of users you can use the Helper object to get the data you're interested in (or convert to SVG):

const helper = new Helper(<DXF String>)

// The 1-to-1 object representation of the DXF
console.log('parsed:', helper.parsed)

// Denormalised blocks inserted with transforms applied
console.log('denormalised:', helper.denormalised)

// Create an SVG
console.log('svg:', helper.toSVG())

// Create polylines (e.g. to render in WebGL)
console.log('polylines:', helper.toPolylines())

Running the Examples

Node ES5. Will write an SVG to examples/example.es5.svg:

$ node examples/example.es5.js

Node ES6. Will write an SVG to examples/example.es6.svg:

$ npx babel-node examples/example.es6.js

Browser. Compile to a browser bundle and open the example webpage:

$ npm run compile
$ open examples/dxf.html

SVG

Geometric elements are supported, but dimensions, text, hatches and styles (except for line colors) are not.

Native SVG elements are used as far as possible for curved entities (<circle />, <ellipse/> etc.), except for the SPLINE entity, which is interpolated.

Here's an example you will find in the functional test output:

svg example image

Interpolation

The library supports outputting DXFs as interpolated polylines for custom rendering (e.g. WebGL) or other applications, by using:

> helper.toPolylines()

Command line

There is a command-line utility (courtesy of @Joge97) for converting DXF files to SVG:

$ npm i -g dxf
$ dxf-to-svg

  Usage: dxf-to-svg [options] <dxfFile> [svgFile]

  Converts a dxf file to a svg file.

  Options:

    -V, --version  output the version number
    -v --verbose   Verbose output
    -h, --help     output usage information

Tests

Running

$ npm test

will execute the unit tests.

$ npm run test:functional will run the functional tests in a browser. Please open toSVG.html when the file listing loads in the browser (or open http://localhost:8030/toSVG.html#/).

Contributors

  • Liam Mitchell https://github.com/LiamKarlMitchell
  • Artur Zochniak https://github.com/arjamizo
  • Andy Werner https://github.com/Gallore
  • Ivan Baktsheev https://github.com/apla
  • Jeff Chen https://github.com/jeffontheground
  • Markko Paas https://github.com/markkopaas
  • Kim Lokøy https://github.com/klokoy
  • Erik Söhnel https://github.com/hoeck
  • Teja https://github.com/hungerpirat
  • Jakob Pallhuber https://github.com/Joge97
  • Eric Mansfield https://github.com/ericman314
  • Kristofer https://github.com/kriffe