Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

contentful-resource-transform

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-resource-transform

Apply transforms to Contentful resources or collections thereof

  • 1.0.2
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

contentful-resource-transform

Apply transforms to Contentful resources or collections thereof.

Synopsis

Create a transform function by passing the function we 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

Package last updated on 18 Jul 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc