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

step-to-json

v3.0.0

Published

A simple command line tool that extracts the system structure of a STEP (ISO 10303-44) file and outputs it as .json

Downloads

24

Readme

STEP-to-JSON

A parser for STEP-files that can be used in node.js as well as in frontend development. STEP-to-JSON parses STEP-files (IS0 10303-44) into a JSON structure. It extracts product definitions, relations and creates the assembly tree of all components.

How to install

STEP-to-JSON can be used in both Back- and Frontend projects. To use it in your own project, simply install via NPM:

npm install step-to-json --save

It also features a CLI tool if you're just interested in parsing STEP-files manually. To use the CLI-tool, you currently have to clone / download this repository and execute the following steps:

$ git clone https://github.com/aljoshakoecher/STEP-to-JSON
$ cd <the folder you cloned to>
$ npm install
$ node step-to-json.js -f "<your STEP-file>.stp"

How to use

The most simple way to convert your STEP file's assembly structure into JSON is by using the parser's parse()-function. After instaling the parser you import the it into your project and create an instance of it. Make sure to pass an Athe path to your STEP-file to the constructor. Then you can just call parse() as shown below:

Node.js Example

// Add to your imports
const StepToJsonParser = require('step-to-json').StepToJsonParser;

// To get your STEP-file's assembly structure as JSON:
const filePath = "this should be a valid path to your STEP-file"
const stepFile = fs.readFileSync(filePath);
const parser = new StepToJsonParser(stepFile);

const assemblyStructure = parser.parse();

Frontend Example (e.g. Angular)

Using the parser in a frontend application is a bit more tricky since interacting with the filesystem is not as easy as it is in Node.js. In the following example you can see how to parse a file that you grab from an input with type="file":

Let's assume this is your html:

<!-- parsing-component.component.html -->
<input type="file" (change)="onFileChange($event)">

You can then use the parser as follows:

// parsing-component.component.ts
import {StepToJsonParser} from 'step-to-json';

// ...
// is called as soon as a file is selected with the input
onFileChange(fileChangeEvent) {
    const inputReader = new FileReader();

    // setup onload handler that is executed as soon as file is completely loaded
    inputReader.onload = (event:any)=>{
        const fileContent = event.target.result
        const parser = new StepToJsonParser(fileContent);       // Instantiate parser with file
        console.log(parser.parse());                            // Log parser output
    }

    // start reading the selected file
    inputReader.readAsText(fileChangeEvent.target.files[0]);
}

API-Documentation

Functionality of the StepToJsonParser class

parse(visitorFunction = undefined, sub = new Subject())

Main parse function that parses the current STEP file and outputs its contents as a JSON tree. Accepts a visitor function, that is called for every product element. The visitor function always gets the current element with the following attributes passed as an argument:

{
    id: any;        // ID string
    name: any;      // Name string
    contains: []    // Array of sub components
}

The visitor function can be used to manipulate the id or name of products or in general to hook into the parsing process. In addition, an rxjs subject can be passed to track the progress. On each new element, the subject emits the number of elements that were parsed.

parseWithUuid(sub = new Subject())

The function parseWithUuid() is basically one example of the more general parse() function shown above. It uses a default visitor function that creates a UUID ID for every element. Just like with parse(), you can pass a subject to get notified of the current parsing state. If you don't want to get UUID IDs and want to customize the generated objects, check out the parse() function above.