Skip to content

MichaelThomas0721/strapiCleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

strapiCleaner

Used to remove the data and attributes property from strapi queries and responses.

To use import the library and use the .response(query) to clean a strapi response and .query(query) to clean a strapi query before sending the query.

The response function will return an object that is the same as the object you passed except without the data and attributes properties.

The query function will return a string that is the same as the query you passed except with data and attributes properties added. If you use the query function DO NOT include any data or attribute properties or the query will be invalid and strapi will return an error. The query passed should be exactly the same as a regular strapi query just without the data and attributes properties.

Installation

npm i strapi-cleaner

Usage

import strapiCleaner from "strapi-cleaner";

const query = `
    {
        team {
            name
            location {
                city
                country
            }
        }
    }
`;

const strapiQuery = strapi - cleaner.query(query);

/* returns :
{
        team {data {attributes {
            name
            location {data {attributes {
                city
                country
            }}}
        }}}
    }
*/

const reponse = {
    "data": [
        {
            "attributes": {
                "name": "kraken",
                "location": {
                    "data": {
                        "attributes": {
                            "city": "Seattle",
                            "country": "US"
                        }
                    }
                }
            }
        }
    ]
}
// returns { name: 'kraken', location: { city: 'Seattle', country: 'US' } }

Contributing

If you would like to see this package improved or if there are any bugs feel free to message me!

License

MIT

About

Used to remove the data and attributes property from strapi queries and responses.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published