Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@statebox/pnpro.js

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@statebox/pnpro.js

Convert PNPRO to JSON or statebox specific representations of Petri nets

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

PNPRO.js

Simple JS library to work with .pnpro files.

  • Parse the file
  • Convert to NLL
  • Convert to NBPT

These files contain multiple "pages", to select a single net and convert it, run:

let pnproNet = parse(xml).nets["page title"]
let nll = to_nll(pnproNet)
let nbpt = to_nbpt(pnproNet)

API Details

Assuming you have the contents of a PNPRO file as a string called pnproProject, here is an overview of the functions exported by this library.

Peek into the project file and pick "pages" (nets) out of it:

  • parse(pnproProject)

Convert a net into some target:

  • to_nll(pnproNet) : NLL
  • to_nbpt(pnproNet) : NBPT

More complete example

For Node:

let PNPRO = require('@statebox/pnpro.js')
let R = require('ramda')

// load a file as a string
let xmlStr = fs.readFileSync('file.pnpro', {encoding:'utf8'})

let project = PNPRO.parse(xmlStr)

let nlls = R.map(PNPRO.to_nll, project.nets) // {name => nll}
let nbpts = R.map(PNPRO.to_nll, project.nets) // {name => nbpt}

Parsed JSON Format

The two main keys are:

  • .title ~ project title
  • .nets ~ dictionary of {title => net}

Here is the full output of parse(..):

{
    "title": "Project Title",
    "nets": {
        "page title": {
            "title": "page title",
            "net": {
                "marking": {
                    "placeLabel": 1
                },
                "transitions": [
                    {
                        "label": "buy",
                        "x": 32.55,
                        "y": 11,
                        "pre": {
                            "Fresh": 1
                        },
                        "post": {
                            "Sold": 1
                        }
                    }
                ],
                "places": [
                    {
                        "label": "Fresh",
                        "x": 42,
                        "y": 22
                    }
                ]
            }
         }
    }
}

Background

We have various repo's that deal with PNRO

  • https://github.com/statebox/gspn-parser
  • https://github.com/statebox/purescript-pnpro-parser
  • https://github.com/statebox/js-pnpro-parser

And now also https://github.com/statebox/pnpro.js

But Why?

There are some issues with the current approaches, mainly related to the library used to parse the XML.

  • js-pnpro-parser uses the browser provided DOMParser()
  • if js-pnro-parser is used from Node, xmldom is used
  • gspn-parser uses cheerio which cannot be bundled well for the browser (due to cyclic dependencies)

Instead I propose we use this 100% JS + regex based one:

We need a simple library that works from node or the browser and doesn't have any complicated (native) dependencies and can be bundled properly.

It's just an XML parser anyway!

Keywords

FAQs

Package last updated on 09 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc