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

contentful-resource-transform

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-resource-transform - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

test/unit/append-and-prepend-test.js

63

index.js

@@ -5,5 +5,6 @@ 'use strict';

var Promise = require('bluebird');
var Bluebird = require('bluebird');
var map = require('map-sync');
var xtend = require('xtend');
var compose = require('compose-promise');

@@ -13,10 +14,16 @@ module.exports = createTransform;

function createTransform (converters) {
if (typeof converters === 'function') {
converters = {
Entry: converters,
Asset: converters,
ContentType: converters
};
}
converters = normalizeConverters(converters);
transform.prepend = function (otherConverters) {
return createTransform(
composeConverters(converters, normalizeConverters(otherConverters))
);
};
transform.append = function (otherConverters) {
return createTransform(
composeConverters(normalizeConverters(otherConverters), converters)
);
};
return transform;

@@ -27,3 +34,3 @@

if (resource.sys.type === 'Array') {
return Promise.join(
return Bluebird.join(
convertResources(resource.items),

@@ -39,9 +46,9 @@ convertIncludes(resource.includes)

if (resource.sys.type in converters) {
return Promise.resolve(converters[resource.sys.type].apply(null, arguments));
return Bluebird.resolve(converters[resource.sys.type].apply(null, arguments));
} else {
return Promise.resolve(resource);
return Bluebird.resolve(resource);
}
function convertResources (array) {
return Promise.map(array, function (item) {
return Bluebird.map(array, function (item) {
return transform.apply(null, [item].concat(extraArgs));

@@ -53,5 +60,5 @@ });

if (!includes) {
return Promise.resolve();
return Bluebird.resolve();
} else {
return Promise.props(map(resource.includes, convertResources));
return Bluebird.props(map(resource.includes, convertResources));
}

@@ -61,1 +68,29 @@ }

}
function normalizeConverters (converters) {
if (typeof converters === 'function') {
return {
Entry: converters,
Asset: converters,
ContentType: converters
};
} else {
return converters;
}
}
function composeConverters (f, g) {
var combined = {};
for (var type in f) {
combined[type] = g[type] ? compose(f[type], g[type]) : f[type];
}
for (var type in g) {
if (!combined[type]) {
combined[type] = g[type];
}
}
return combined;
}
{
"name": "contentful-resource-transform",
"version": "1.0.5",
"version": "1.1.0",
"description": "Apply transforms to Contentful resources or collections thereof",

@@ -15,2 +15,3 @@ "main": "index.js",

"buster": "~0.7.13",
"call-method": "^1.0.1",
"markdown-code-blocks": "0.0.1"

@@ -26,2 +27,3 @@ },

"bluebird": "^2.2.2",
"compose-promise": "^1.0.0",
"map-sync": "^0.1.1",

@@ -28,0 +30,0 @@ "xtend": "^4.0.0"

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