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

ocds_helper

v2.2.3

Published

read ocds files and get stats, values and some practical functions

Downloads

12

Readme

ocds-helper v2

This plugin allows access to the properties of an OCDS file (json). It can read:

  • releases,
  • records,
  • release packages,
  • and record packages.

In the case of a release package, it accesses the first one in the array. For the record packages, it can only read the first compiledRelease (for now).

In addition to allowing access to the properties of an ocds, it also allows filtering them. It also generate a series of properties that indicate:

  • the status of the contracting process (planning, tender, award, contract, implementation);
  • the days that have elapsed from the publication date
  • some red flags (if it has a supplier, if it has items, the budget difference between the award and the contract, the number of days to apply to the tender, if it is a competitive process)

It also has a method to access the amounts at each stage of the process.

How to use it

import the plugin:

const readOCDS = require("ocds_helper");

pass the json to the plugin so that it returns an object of type ocds_helper

const helper = readOCDS(someOCDS)

to access the full release, it is through the "data" property

console.log(helper.data);

expected output:

{planning..., tender..., awards..., ...}

to get any value inside the standard file, write a string with the property tree separated by a dot. if the property is inside an array, the helper returns te value for each element of the array (like the description in awards) or the value if it's from a single node. If the function don't find any value, it returns null

example 1: get a property within a collection of objects

helper.getData("awards.description")

expected output:

["description 1", "description 2"]

example 2: get a nested property outside of an array

helper.getData("planning.budget.amount")

expected output:

{amount: 123, currency : "MXN"}

example 3: get a property that is not defined

helper.getData("planning.budget.amount.bananas")

expected output:

null

get the amounts

To obtain the amount of a contracting process in its current state (contract, award, etc ...), the "amount" property can be consulted.

This will return an object with the source of the amount, and an array of amounts, where each element represents a currency. If all the elements to be added are in the same currency, this array will only contain one element.

example

console.log(helper.amount);

expected output:

{
  "source": "contract",
  "data": [
    {
      "currency": "COP",
      "amount": 12326533
    }
  ]
}

If you want the amount of another stage, you have to use the "getStateAmount" method, and pass the name of the state from which you want to obtain the information. The possible states are inside helper.constants.states and are as follows:

  • PLANNING
  • TENDER
  • AWARD
  • CONTRACT
  • IMPLEMENTATION

example

helper.getStateAmount(helper.constants.states.PLANNING)

expected output:

{
  "source": "planning",
  "data": [
    {
      "currency": "COP",
      "amount": 12326533
    }
  ]
}

precalculated properties

type: the ocsd file type

helper.type

expected output:

"release"

daysDiff: the days that have passed since the publication of the ocds

helper.daysDiff

expected output:

1046

state: the state of the contracting process

helper.type

expected output:

"contract"

red flags

To calculate the red flags, you need to call the methods inside "indices".

hasSupplier: if it has a supplier

helper.indices.hasSupplier()

expected output:

true

hasItems: if it has items

helper.indices.hasItems()

expected output:

false

awardContractDiff: the budget difference between the award and the contract

helper.indices.awardContractDiff()

expected output:

0

tenderPeriodDays: the number of days to apply to the tender

helper.indices.awardContractDiff()

expected output:

0

isCompetitive: if it is a competitive process

helper.indices.isCompetitive()

expected output:

true

filter the properties

It is possible to filter the elements of an array if they meet a condition. If the elements of the array are also arrays, you must pass an object with the following properties:

{
  type : 'contains',
  field : 'the-name-of-the-property-to-validate',
  value : 'the-value-to-find-inside-the-field'
}

example: get the suppliers inside the parties array.

First, it must target the "parties" array, and then, search every party inside the roles array for the value "supplier"

helper.getData("parties", {type : "contains", field : "roles", value : "supplier"}) 

expected output:

[
  {
    "name": "El Mundo es Tuyo, S.A. de C.V.",
    "id": "MX-RFC-MET8908305M9",
    "identifier": {
      "scheme": "MX-RFC",
      "id": "MET8908305M9",
      "legalName": "El Mundo es Tuyo, S.A. de C.V.",
      "juridicalPersonhood": "legalPerson"
    },
    "address": {
      "streetAddress": "Diagonal San Antonio 1216",
      "locality": "Benito Juarez",
      "region": "Ciudad de México",
      "postalCode": "03020",
      "countryName": "México"
    },
    "contactPoint": {
      "name": "Marco Antonio Cárdenas López",
      "email": "[email protected]",
      "telephone": "56396464",
      "faxNumber": "56398192",
      "url": "http://www.elmundoestuyo.com.mx/",
      "givenName": "Marco Antonio Cárdenas López"
    },
    "roles": [
      "supplier",
      "tenderer",
      "payee",
      "invitedSupplier"
    ]
  }
]