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

load-portfolio-performance-xml

v1.0.3

Published

An unofficial Javascript/Typescript loader for the XML files of the Portfolio Performance application.

Downloads

1

Readme

load-portfolio-performance-xml

Contents

An unofficial Javascript/Typescript loader for the XML files of the Portfolio Performance application.

Developed and tested with version 56 of the application's file format.

Can be used on the client side (browser environments) or on the server side (node.js).

Usage

At this time, the library implements only a generic data model of nodes, but no specific type definitions for the PP data model.

For a specification of the available fields, please refer to the data model directory in the Portfolio Performance repository.

import { readFileSync } from "fs"
import { loadPortfolioPerformanceXml } from "."

try {
  const xml = readFileSync("data/portfolio-performance.xml")
  const data = loadPortfolioPerformanceXml(xml) // accepts `string | Buffer`

  console.log("File Version: " + data.client?.[0]?.version?.[0]?.["#text"] || "n/a")
  // File Version: 56

  console.log("Accounts: " + data.client?.[0]?.accounts?.[0]?.account?.length || 0)
  // Accounts: 3

  console.log("Securities: " + data.client?.[0]?.securities?.[0]?.security?.length || 0)
  // Securities: 12

  console.log("Example Security Name: " + data.client?.[0]?.securities?.[0]?.security?.[0].name?.[0]["#text"] || "n/a")
  // Example Security Name: Deka DAX
} catch (err) {
  console.error("oh oh", err)
}

Implementation Details

Portfolio Performance is a Java application. Its data model uses native object references in a directed graph. Such data models typically require deduplication during serialization and reference resolution during deserialization to avoid data corruption.

Portfolio Performance uses the XStream library for this purpose. XStream implements an algorithm that only renders the first occurance of an object as a fully populated XML node; all subsequent occurences are rendered as empty XML tags with a single reference attribute that holds a stringified, relative path to the fully populated node, such as "../../../../../../../../../../../../../../../../../../../../../../../../../../../securities/security". If more nodes with the same tag name should be encountered during serialization, the original node is converted to an array of nodes, and the original node at this position becomes the first entry of the array. References to array entries may contain an index; if the target of a path segment is an array and the path segment contains no index, it is resolved as pointing to the first array entry. If present, index values in XStream generally start at 1 and not at 0 as in Javascript.

This library delegates the XML processing in the first step of its parser process to the battle-proven fast-xml-parser library, with a configuration that seems to work well for Portfolio Performance files. Afterwards, we resolve all references in an XStream-compliant manner. This second step is hand-crafted, as there seems to be no Javascript port of the XStream library or its reference resolution algorithm at this time.

The returned data structure is intentionally rather generic (consisting of nested Node and NodeArray instances) because the availability of nodes can vary in different PP file format versions.

Copyright / License

Copyright (c) 2022 Daniel Kastenholz.

All rights reserved.

Licensed under the terms of the AGPL-3.0 only.

History

| Version | Changes | | ------- | --------------------------------- | | 1.0.0 | Initial version | | 1.0.1 | Bugfix: deep-clone in resolve() | | 1.0.2 | Bugfix: reference resolution | | 1.0.3 | README update |