gd-url-gen v0.0.20
Welcome
About this project
This project enables you to create Cloudinary URLs for your images and videos. Using this SDK, you can apply advanced transformations to your images and videos.
This SDK can also be used with popular frontend frameworks.
Help & Examples
Installation
npm install @cloudinary/url-gen
Simple usage
// Import the Cloudinary class
import {Cloudinary} from '@cloudinary/url-gen';
// Create your instance
const cld = new Cloudinary({
cloud: {
cloudName: 'demo'
},
url: {
secure: true // force https, set to false to force http
}
});
// Let's create a new image
const myImage = cld.image('sample');
import {Resize} from '@cloudinary/url-gen/actions/resize';
myImage.resize(Resize.scale().width(100).height(100));
// When we're done, we can apply all our changes and create a URL.
const myURL = myImage.toURL();
console.log(myURL);
// https://res.cloudinary.com/demo/image/upload/c_scale,w_100,h_100/sample
More examples and documentation
Additional links
Transpilation
@cloudinary/url-gen is shipped as untranspiled ES6 code. @cloudinary/url-gen is optimized around bundle size, as such we do not transpile our distributed modules, we leave the decision of what browsers to support, and what transpilations to apply, to you, the user.
Testing with Jest
As mentioned above, we're shipping @cloudinary/url-gen with ES6 code, as this provides great tree-shaking potential. it also requires a few adjustments when testing.
In jest.config, you'll need to add these lines to allow babel to transpile our code.
{
"transform": {
"node_modules/@cloudinary/url-gen": "babel-jest"
},
"transformIgnorePatterns": ["/node_modules/(?!@cloudinary/url-gen)"]
}
Make sure to install babel-jest:
npm install babel-jest
You'll also need to ensure you have a babel.config.js file (and not a .babelrc), and that it's configured properly to transpile code,
As an example:
module.exports = {
"presets": [
"@babel/preset-env"
]
};
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago