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

symfony-js-form-parser

v1.0.6

Published

Symfony form errors javascript parser

Downloads

85

Readme

Symfony form error response javascript parser

This library provides a simple solution for analyzing symfony form error responses. Thanks to this you can easily display errors in the form, etc.

Instalation

$ npm install symfony-js-form-parser

Example

With this library you can easily convert this type of json:

{
  "code": 400,
  "message": "Validation Failed",
  "errors": {
    "children": {
      "comment": {},
      "customer": {
        "errors": [
          "This value is not valid."
        ]
      },
      "return_address": {
        "children": {
          "postal_code": {},
          "street": {},
          "town": {},
          "type": {},
          "name": {},
          "first_name": {},
          "last_name": {},
          "email": {},
          "phone_number": {},
          "customer": {},
          "country": {}
        }
      },
      "order_items": {
        "errors": [
          "This value is not valid."
        ]
      },
      "status": {},
      "parcels": {}
    }
  }
}

to this:

{
  "errors": [],
  "code": 400,
  "message": "Validation Failed",
  "nodes": {
    "comment": [],
    "customer": ["This value is not valid."],
    "return_address.postal_code": [],
    "return_address.street": [],
    "return_address.town": [],
    "return_address.type": [],
    "return_address.name": [],
    "return_address.first_name": [],
    "return_address.last_name": [],
    "return_address.email": [],
    "return_address.phone_number": [],
    "return_address.customer": [],
    "return_address.country": [],
    "return_address": [],
    "order_items": ["This value is not valid."],
    "status": [],
    "parcels": []
  }
}

or this:

{
  "code": 400,
  "message": "Validation Failed",
  "error": null,
  "nodes": {
    "comment": null,
    "customer": "This value is not valid.",
    "return_address.postal_code": null,
    "return_address.street": null,
    "return_address.town": null,
    "return_address.type": null,
    "return_address.name": null,
    "return_address.first_name": null,
    "return_address.last_name": null,
    "return_address.email": null,
    "return_address.phone_number": null,
    "return_address.customer": null,
    "return_address.country": null,
    "return_address": null,
    "order_items": "This value is not valid.",
    "status": null,
    "parcels": null
  }
}

Usage

import {ErrorResponse} from 'symfony-js-form-parser'

let simpleResponse = {
    "code": 400,
    "message": "Validation Failed",
    "errors": {
        "children": {
            "comment": {},
            "customer": {
                "errors": [
                    "This value is not valid."
                ]
            },
            "return_address": {
                "children": {
                    "postal_code": {},
                    "street": {},
                    "town": {},
                    "type": {},
                    "name": {},
                    "first_name": {},
                    "last_name": {},
                    "email": {},
                    "phone_number": {},
                    "customer": {},
                    "country": {}
                }
            },
            "order_items": {
                "errors": [
                    "This value is not valid."
                ]
            },
            "status": {},
            "parcels": {}
        }
    }
}

let errorResponse = new ErrorResponse(simpleResponse);
console.log(errorResponse.toFlattenObject())
/*
{
  "errors": [],
  "code": 400,
  "message": "Validation Failed",
  "nodes": {
    "comment": [],
    "customer": ["This value is not valid."],
    "return_address.postal_code": [],
    "return_address.street": [],
    "return_address.town": [],
    "return_address.type": [],
    "return_address.name": [],
    "return_address.first_name": [],
    "return_address.last_name": [],
    "return_address.email": [],
    "return_address.phone_number": [],
    "return_address.customer": [],
    "return_address.country": [],
    "return_address": [],
    "order_items": ["This value is not valid."],
    "status": [],
    "parcels": []
  }
}
*/

console.log(errorResponse.toSimpleFlattenObject())
/*
{
  "code": 400,
  "message": "Validation Failed",
  "error": null,
  "nodes": {
    "comment": null,
    "customer": "This value is not valid.",
    "return_address.postal_code": null,
    "return_address.street": null,
    "return_address.town": null,
    "return_address.type": null,
    "return_address.name": null,
    "return_address.first_name": null,
    "return_address.last_name": null,
    "return_address.email": null,
    "return_address.phone_number": null,
    "return_address.customer": null,
    "return_address.country": null,
    "return_address": null,
    "order_items": "This value is not valid.",
    "status": null,
    "parcels": null
  }
}
*/

Tests

All you need to do to run the tests is run:

$ npm test