Skip to content

Commit

Permalink
Export true ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
alecmev committed Mar 7, 2022
1 parent 5b4888e commit dcd91ff
Show file tree
Hide file tree
Showing 31 changed files with 134 additions and 159 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ out.json
*.actual.json
.vscode/
*.received.*
dist/
commonjs/*.js
esm/
*.tgz
*.lock
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,20 @@ Also, keep an eye on [three-dxf](https://github.com/gdsestimating/three-dxf), a
npm install dxf-parser
```

Browsers -- As of 0.1.3 standalone browserify version is in the dist/ folder. Copy it out of the install directory or just download it from the GitHub repo directly. We may evetually publish this to bower, but the build environment needs a little work first.
Browsers -- As of 0.1.3 standalone browserify version is in the commonjs/ folder. Copy it out of the install directory or just download it from the GitHub repo directly. We may evetually publish this to bower, but the build environment needs a little work first.

#### Usage

``` js
import parse, { DxfParser } from 'dxf-parser';
import DxfParser from 'dxf-parser';

// Grab fileText in node.js or browser
const fileText = ...;

const parser = new DxfParser();
try {
const dxf = parser.parseSync(fileText);
}catch(err) {
return console.error(err.stack);
}
```

or

```ts
// Grab fileText in node.js or browser
import parse from 'dxf-parser';

const fileText = ...;

try {
const dxf = parse(fileText);
}catch(err) {
const dxf = parser.parse(fileText);
} catch(err) {
return console.error(err.stack);
}
```
Expand Down
3 changes: 3 additions & 0 deletions commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
"name": "dxf-parser",
"version": "1.1.2",
"description": "Parse dxf files into a readable, logical js object.",
"main": "./dist/dxf-parser.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"main": "./commonjs/index.js",
"module": "./esm/index.js",
"exports": {
"import": "./esm/index.js",
"require": "./commonjs/index.js"
},
"types": "./esm/index.d.ts",
"scripts": {
"test": "mocha --require @babel/register test",
"dev": "tsc -w & webpack --mode development",
Expand Down Expand Up @@ -46,7 +51,8 @@
"reader"
],
"files": [
"dist",
"commonjs",
"esm",
"src"
]
}
2 changes: 1 addition & 1 deletion samples/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>Dxf-Parser - Browser Sample</title>

<script src="../../dist/dxf-parser.js"></script>
<script src="../../commonjs/index.js"></script>
</head>
<body>
<input id="file-field" type="file"/>
Expand Down
16 changes: 7 additions & 9 deletions samples/node/parse-stream.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
var DxfParser = require('../../dist/dxf-parser');
var fs = require('fs');
var path = require('path');
import DxfParser from '../../esm/index.js'
import fs from 'fs'
import path from 'path'

console.log(DxfParser);
const __dirname = path.dirname(new URL(import.meta.url).pathname)

var DXF_FILE_PATH = path.join(__dirname, '..', 'data', 'api-cw750-details.dxf');
var OUTPUT_FILE_NAME = "out.json";

var fileStream = fs.createReadStream(DXF_FILE_PATH, { encoding: 'utf8' });

var parser = new DxfParser();
parser.parseStream(fileStream, function(err, dxf) {
if(err) return console.error(err.stack);
fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxf, null, 3));
console.log('Done writing output to ' + OUTPUT_FILE_NAME);
});
const dxf = await parser.parseStream(fileStream);
fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxf, null, 3));
console.log('Done writing output to ' + OUTPUT_FILE_NAME);
8 changes: 5 additions & 3 deletions samples/node/parse-sync.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var DxfParser = require('../../dist/dxf-parser');
var fs = require('fs');
var path = require('path');
import DxfParser from '../../esm/index.js'
import fs from 'fs'
import path from 'path'

const __dirname = path.dirname(new URL(import.meta.url).pathname)

var DXF_FILE_PATH = path.join(__dirname, '..', 'data', 'api-cw750-details.dxf');
var OUTPUT_FILE_NAME = "out.json";
Expand Down
40 changes: 20 additions & 20 deletions src/DxfParser.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Readable } from 'stream';
import DxfArrayScanner, { IGroup } from './DxfArrayScanner';
import AUTO_CAD_COLOR_INDEX from './AutoCadColorIndex';

import Face from './entities/3dface';
import Arc from './entities/arc';
import AttDef from './entities/attdef';
import Circle from './entities/circle';
import Dimension from './entities/dimension';
import Ellipse from './entities/ellipse';
import Insert from './entities/insert';
import Line from './entities/line';
import LWPolyline from './entities/lwpolyline';
import MText from './entities/mtext';
import Point from './entities/point';
import Polyline from './entities/polyline';
import Solid from './entities/solid';
import Spline from './entities/spline';
import Text from './entities/text';
//import Vertex from './entities/';
import DxfArrayScanner, { IGroup } from './DxfArrayScanner.js';
import AUTO_CAD_COLOR_INDEX from './AutoCadColorIndex.js';

import Face from './entities/3dface.js';
import Arc from './entities/arc.js';
import AttDef from './entities/attdef.js';
import Circle from './entities/circle.js';
import Dimension from './entities/dimension.js';
import Ellipse from './entities/ellipse.js';
import Insert from './entities/insert.js';
import Line from './entities/line.js';
import LWPolyline from './entities/lwpolyline.js';
import MText from './entities/mtext.js';
import Point from './entities/point.js';
import Polyline from './entities/polyline.js';
import Solid from './entities/solid.js';
import Spline from './entities/spline.js';
import Text from './entities/text.js';
//import Vertex from './entities/.js';

import log from 'loglevel';
import IGeometry, { EntityName, IEntity, IPoint } from './entities/geomtry';
import IGeometry, { EntityName, IEntity, IPoint } from './entities/geomtry.js';

//log.setLevel('trace');
//log.setLevel('debug');
Expand Down
6 changes: 3 additions & 3 deletions src/ParseHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AUTO_CAD_COLOR_INDEX from './AutoCadColorIndex';
import DxfArrayScanner, { IGroup } from './DxfArrayScanner';
import { IEntity, IPoint } from './entities/geomtry';
import AUTO_CAD_COLOR_INDEX from './AutoCadColorIndex.js';
import DxfArrayScanner, { IGroup } from './DxfArrayScanner.js';
import { IEntity, IPoint } from './entities/geomtry.js';

/**
* Returns the truecolor value of the given AutoCad color index value
Expand Down
8 changes: 3 additions & 5 deletions src/entities/3dface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'

import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface I3DfaceEntity extends IEntity {
shape: boolean;
Expand Down
8 changes: 3 additions & 5 deletions src/entities/arc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'

import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface IArcEntity extends IEntity {
center: IPoint;
Expand Down
7 changes: 3 additions & 4 deletions src/entities/attdef.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface IAttdefEntity extends IEntity {
scale: number;
Expand Down
7 changes: 3 additions & 4 deletions src/entities/circle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface ICircleEntity extends IEntity {
center: IPoint;
Expand Down
7 changes: 3 additions & 4 deletions src/entities/dimension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface IDimensionEntity extends IEntity{
block: string;
Expand Down
7 changes: 3 additions & 4 deletions src/entities/ellipse.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface IEllipseEntity extends IEntity {
center: IPoint;
Expand Down
2 changes: 1 addition & 1 deletion src/entities/geomtry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DxfArrayScanner, { IGroup } from "../DxfArrayScanner";
import DxfArrayScanner, { IGroup } from "../DxfArrayScanner.js";

export interface IPoint {
x: number;
Expand Down
6 changes: 3 additions & 3 deletions src/entities/insert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface IInsertEntity extends IEntity {
name: string;
Expand Down
7 changes: 3 additions & 4 deletions src/entities/line.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface ILineEntity extends IEntity{
vertices: IPoint[];
Expand Down
6 changes: 3 additions & 3 deletions src/entities/lwpolyline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface IVertex extends IPoint{
startWidth: number;
Expand Down
7 changes: 3 additions & 4 deletions src/entities/mtext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface IMtextEntity extends IEntity {
text: string;
Expand Down
7 changes: 3 additions & 4 deletions src/entities/point.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface IPointEntity extends IEntity{
position: IPoint;
Expand Down
9 changes: 4 additions & 5 deletions src/entities/polyline.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

import * as helpers from '../ParseHelpers'
import VertexParser, { IVertexEntity } from './vertex';
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers.js';
import VertexParser, { IVertexEntity } from './vertex.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';

export interface IPolylineEntity extends IEntity {
vertices: IVertexEntity[];
Expand Down
7 changes: 3 additions & 4 deletions src/entities/solid.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface ISolidEntity extends IEntity {
points: IPoint[];
Expand Down
7 changes: 3 additions & 4 deletions src/entities/spline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface ISplineEntity extends IEntity {
controlPoints?: IPoint[];
Expand Down
7 changes: 3 additions & 4 deletions src/entities/text.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'
import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface ITextEntity extends IEntity {
startPoint: IPoint;
Expand Down
8 changes: 3 additions & 5 deletions src/entities/vertex.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import DxfArrayScanner, { IGroup } from '../DxfArrayScanner';
import * as helpers from '../ParseHelpers'

import IGeometry, { IEntity, IPoint } from './geomtry';
import DxfArrayScanner, { IGroup } from '../DxfArrayScanner.js';
import * as helpers from '../ParseHelpers.js';
import IGeometry, { IEntity, IPoint } from './geomtry.js';

export interface IVertexEntity extends IEntity, IPoint{
bulge: number;
Expand Down
Loading

0 comments on commit dcd91ff

Please sign in to comment.