-
Notifications
You must be signed in to change notification settings - Fork 859
Data Transformations
The transform
option is a powerful way to control the image data returned by Instagram before it is rendered by Instafeed.js. For example, you could use it to add extra fields to your images, adjust or format the values Instagram returns, etc.
The transform
option accepts a function. That function will be applied to each item in the set returned by Instagram. The return value of the function will replace the item in the set.
Here's a function which formats the timestamp
attribute to something friendlier:
var feed = new Instafeed({
transform: function(item) { //Transform receives each item as its argument
// Over-write the original timestamp
item.timestamp = new Date(item.timestamp).toLocaleString('en-AU', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
// return the modified item
return item;
}
// ...
});
Transform
is applied before filter
, sort
and limit
. This allows you to filter or sort based on your transformed items if you need to.
Instafeed v1 provided a filter
option which was often used as an 'unofficial' transform
. While filter
still exists, it's better to use transform
when you want to modify your item data.