This package extract data from Prismic Query Results using a JSON like GraphQL style
npm install prismic-scout --save
or
yarn add prismic-scout
restriveFromData(
Object <api>,
Object <options>
)
const PrismicScout = require('prismic-scout');
...
/*
* Get Prismic api now we can use `api` variable
*/
...
const Scout = new PrismicScout(api);
For array of documents
restriveFromData(
Array <results>,
Object <fileds>,
Object <options>
)
/*
* Inside a Prismic `query` then function
*/
Scout.retriveFromData(results, {
"title": {
"_type": "text"
},
"description": {
"_type": "html"
},
"image": {
"url": {}
}
})
For single of document
restriveFromData(
Object <doc>,
Object <fileds>,
Object <options>
)
/*
* Inside a Prismic `getByID` then function
*/
Scout.retriveSingle(doc, {
"title": {
"_type": "text"
},
"description": {
"_type": "richtext"
},
"image": {
"url": {}
}
})
Extract from document data field and append 'id','uid' and 'lang';
Append id value to object (without id Scout cannot retrive nested document)
Append uid value to object
Append lang value to object
/* Set global options */
const Scout = new PrismicScout(api, {uid: false, lang: false});
/* Set single options (merged with global options) */
Scout.retriveFromData(results, {
"title": {
"_type": 'html'
}
},{
lang: true // { uid: false, lang: true }
});
This project is under MIT license, 2017, ⓒ Antonio Dal Sie. Read more in LICENSE.