@nuskin/bynder-dat
This library hosts a collection of wrapper functions for bynder's DAT API. The library also builds in both cjs and esm formats.
ESM for better treeshaking support. CJS for node/backend apps.
Installing
Usng npm:
npm add @nuskin/bynder-dat
Usng yarn:
yarn add @nuskin/bynder-dat
Example usage
CommonJS
const { useFormat, transformFill } = require('@nuskin/bynder-dat');
const url = useFormat('http://foo.baz.bar', 'webp');
console.log(url);
const url = transformFill('http://foo.baz.bar', { height: 100, width: 100 });
console.log(url);
const url = transformFill(useFormat('http://foo.baz.bar', 'webp'), { height: 100, width: 100 });
console.log(url);
const url = useFormat(transformFill('http://foo.baz.bar', { height: 100, width: 100 }), 'webp');
console.log(url);
ESM
import { useFormat, transformFill } from '@nuskin/bynder-dat';
Real world use cases
optimize
Using webp already reduces file size by alot
import { useFormat } from '@nuskin/bynder-dat';
const { transformBaseUrl } = bynderImageObject.derivatives;
const webpImage = useFormat(transformBaseUrl, 'webp');
optimize + tailor fit images
You know the dimensions of the image you need to render.
import { useFormat, transformFill } from '@nuskin/bynder-dat';
const { transformBaseUrl } = bynderImageObject.derivatives;
const webpThumbnailImage = transformFill(useFormat(transformBaseUrl, 'webp'), { height: 100, width: 100 });
optimize + responsive using image srcset attribute
You know the dimensions of the image you need to render.
import { useFormat, transformFill } from '@nuskin/bynder-dat';
const sourcesetMap = [
{ width: 320, height: 200 },
{ width: 800, height: 400 }
];
const { transformBaseUrl } = bynderImageObject.derivatives;
const imageSourceSet = sourcesetMap
.map((dimensions) => `${transformFill(useFormat(transformBaseUrl, 'webp'), dimensions)} ${dimensions.width}w`)
.join(',');
Resources
License
MIT