Skip to content

Cloudinary's base javascript library, including URL generation.

License

Notifications You must be signed in to change notification settings

GrahamDigital/js-url-gen

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"
  ]
};

About

Cloudinary's base javascript library, including URL generation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 56.7%
  • TypeScript 29.8%
  • JavaScript 12.4%
  • Other 1.1%