contentful-resource-transform
Advanced tools
Comparing version 1.0.5 to 1.1.0
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" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10013
11
224
0
4
3
+ Addedcompose-promise@^1.0.0
+ Addedany-promise@0.1.0(transitive)
+ Addedcompose-promise@1.0.0(transitive)