Socket
Socket
Sign inDemoInstall

contentful-resource-transform

Package Overview
Dependencies
7
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    contentful-resource-transform

Apply transforms to Contentful resources or collections thereof


Version published
Weekly downloads
11
increased by57.14%
Maintainers
2
Install size
498 kB
Created
Weekly downloads
 

Readme

Source

contentful-resource-transform

Apply transforms to Contentful resources or collections thereof.

Synopsis

Create a transform function by passing the function you want to apply to each resource to createTransform.

var assert = require('assert');
var createTransform = require('./');

var collapseToId = createTransform(function (resource) {
  // could also return a promise here
  return resource.sys.type + '!' + resource.sys.id;
});

collapseToId will accept any "Entry", "Asset", and "ContentType" resources it finds with the provided function:

collapseToId({ sys: { type: 'Entry', id: 'blah' } }).then(function (result) {
  assert.equal(result, 'Entry!blah');
}).done();

(note that we're only providing the bare minimum for our transform to work, resources returned by the Contentful API's have many more properties)

Transforming Arrays

If a resource is an "Array" collapseToId will traverse it's items and includes properties:

collapseToId({
  sys: { type: 'Array' },
  items: [
    {
      sys: { type: 'Entry', id: 'Whatever' }
    }
  ],
  includes: {
    ContentType: [
      {
        sys: { type: 'ContentType', id: 'Yeah' }
      }
    ]
  }
}).then(function (collapsed) {
  require('assert').deepEqual(collapsed, {
    sys: { type: 'Array' },
    items: [ 'Entry!Whatever' ],
    includes: {
      ContentType: [ 'ContentType!Yeah' ]
    }
  });
}).done();

License

MIT

FAQs

Last updated on 09 Jan 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc