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

missingproperties

v1.1.6

Published

Find missing properties with log identifier from json response and update it with default value

Downloads

12

Readme

MissingProperties

To install this package run command:

npm run missingproperties

Sample json input

const input = {
      articles: {
        page: {
          details: {
            description: 'This is description',
            totalChar: 199,
          },
        },
      },
      animals: [
        {
          name: 'Dogs',
          breeds: [
            { name: 'Doggy One', age: 10, active: true },
            { name: 'Doggy Two', age: 20, active: false },
            { age: 37, active: true, id: 123 },
          ],
        },
        {
          name: 'Bird',
          breeds: [
            { name: 'Bird One', age: 10, active: true },
            { name: 'Bird Two', age: 20, active: false },
            { age: 247, active: true },
          ],
        },
      ],
      friends: [
        { user: '', age: 36, active: true },
        { user: 'fred', age: 40, active: false },
        { age: 37, active: true },
      ],
    }

To identify the missing properties which is required to be present in response,

you can use run the below command:

getMissingDataInfoWithPatchedObject(response,[
  {path: 'animals[].breeds[].name',defaultValue:'INTELLIGENT ANIMAL',defaultValuePath:'animals[].breeds[].age',logKeyPath:'animals[].breeds[].location'},
  {path: 'articles.page.details.description',defaultValue:'INDIA',defaultValuePath:'articles.page.details.totalChar',logKeyPath:'articles.page.details.totalChar'},
])

Output will be:

    {
      "patchedObject": {
        "articles": {
          "page": {
            "details": {
              "totalChar": 199,
              "description": "INDIA 199 "
            }
          }
        },
        "animals": [
          {
            "name": "Dogs",
            "breeds": []
          },
          {
            "name": "Bird",
            "breeds": [
              {
                "age": 33,
                "location": "bulgaria",
                "name": "INTELLIGENT ANIMAL 33 "
              },
              {
                "name": "Bird One",
                "age": 11,
                "location": "india"
              },
              {
                "name": "Bird Two",
                "age": 22,
                "location": "japan"
              }
            ]
          }
        ],
        "friends": []
      },
      "missingData": {
        "animals[].breeds[].name": [
          {
            "missingPath": "animals[0].breeds"
          },
          {
            "missingPath": "animals[1].breeds[0].name",
            "missingValueIdentifier": "bulgaria"
          }
        ],
        "articles.page.details.description": [
          {
            "missingPath": "articles.page.details.description",
            "missingValueIdentifier": 199
          }
        ]
      }
    }

Method getMissingDataInfoWithPatchedObject provides the missing properties array with information of missing properties so it can be loggable and also provides the response with defaultValue.

It accepts two parameter ie.

  1. input (json response)

  2. array of object of required properties

    a. path: path of required property b. defaultValue: Replacable default value when the above required property is missing c. defaultValuePath: Replacable combined value from defaultValuePath and defaultValue when the path is missing d. logPropertyPath: Property path which will help to identify the missing property for logging utilities