Gathering detailed insights and metrics for cloudinary-tiny-js
Gathering detailed insights and metrics for cloudinary-tiny-js
Gathering detailed insights and metrics for cloudinary-tiny-js
Gathering detailed insights and metrics for cloudinary-tiny-js
npm install cloudinary-tiny-js
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
30 Stars
45 Commits
4 Forks
7 Watching
9 Branches
3 Contributors
Updated on 13 Oct 2023
TypeScript (98.88%)
JavaScript (1.12%)
Cumulative downloads
Total Downloads
Last day
11.7%
182
Compared to previous day
Last week
0.1%
796
Compared to previous week
Last month
4.1%
3,380
Compared to previous month
Last year
-16.3%
40,342
Compared to previous year
Cloudinary is a cloud service that offers a solution to a web application's entire image
management pipeline. For client-side image management Cloudinary provides the cloudinary-core
library for conveniently
compiling transform options to asset URLs. The problem is that it's a massive library often used to simply convert an
object of properties to a string.
cloudinary-tiny-js
provides the same commonly used image transformation features at a fraction of the size and without
any dependencies.
Video transformations are not currently supported nor are some advanced configuration options. It may also fall short on some advanced image transformations. If you need this functionality, please submit PRs with references to the relevant Cloudinary documentation.
The default export is a configuration function returning another function for building Cloudinary
URLs. Configuration option names follow the documentation on
Transforming media assets using dynamic URLs
and Private CDNs and CNAMEs
. Only the cloudName
is required. Defaults are shown below.
1import cloudinary from 'cloudinary-tiny-js' 2 3const cl = cloudinary({ 4 /** The name of your Cloudinary account, a unique public identifier for URL building and API access. */ 5 cloudName: 'demo', 6 /** 7 * The type of asset to deliver, `image` by default. Valid values: `image`, `raw`, or `video`. 8 * Only the `image` type currently supports transforms. 9 */ 10 assetType: 'image', 11 /** 12 * The storage or delivery type. Default: upload. For details on all possible types, see the 13 * Cloudinary docs on delivery types. 14 */ 15 deliveryType: 'upload', 16 /** Use https instead of http */ 17 secure: true, 18 /** Override the subdomain when using a private CDN distribution. */ 19 cdnSubdomain: 'res', 20 /** A fully customisable CNAME. */ 21 cname: 'res.cloudinary.com', 22 /** Transforms applied to all images, any transforms passed later will extend these defaults. */ 23 imageTransformDefaults: { quality: 'auto' /* Any valid transforms, see below */ }, 24}) 25 26const imageUrl = cl('sample.png', { width: 150 }) 27expect(imageUrl).toBe('https://res.cloudinary.com/demo/image/upload/q_auto,w_150/sample.png')
All image transformations documented in the Transformation URL API reference are supported except for arithmetic operators, conditionals and variables.
To create a resource URL, call the function returned by the configuration function with a public ID and optional image transformation options:
1const basicUrl = cl('sample.png') 2expect(basicUrl).toBe('https://res.cloudinary.com/demo/image/upload/v1/sample.png') 3 4const resizedUrl = cl('sample.png', { width: 150, height: 100 }) 5expect(resizedUrl).toBe('https://res.cloudinary.com/demo/image/upload/w_150,h_100/v1/sample.png')
Other options that can be provided alongside transform options are:
1const url = cl('http://example.com/sample.dat', { 2 /** 3 * Specify a single or multiple transformations to apply. The options of a single transform can also 4 * be included directly on this parent object. Note that the default transforms are only applied 5 * when a single transform is provided and not for an array of transforms. 6 */ 7 transformations: undefined, 8 /** 9 * Override the `assetType` provided in the configuration. 10 */ 11 assetType: 'raw', 12 /** 13 * Override the `deliveryType` provided in the configuration. 14 */ 15 deliveryType: 'fetch', 16 /** 17 * You can add the version to your delivery URL to bypass the cached version on the CDN and 18 * force delivery of the latest resource. As an alternative to using versions, you can set the 19 * `invalidate` parameter to true while uploading a new image in order to invalidate the 20 * previous image throughout the CDN. 21 */ 22 version: 742, 23}) 24expect(url).toBe('http://res.cloudinary.com/demo/raw/fetch/v742/http://example.com/sample.dat')
To perform multiple transformations an array of transform objects can be passed; the array can be passed directly as the
second parameter or on the transformations
property along with other options.
This will generate the URL of the first example in the Image transformation reference:
1const transformations = [ 2 { width: 220, height: 140, crop: 'fill' }, 3 { overlay: 'brown_sheep', width: 220, height: 140, x: 220, crop: 'fill' }, 4 { overlay: 'horses', width: 220, height: 140, x: -110, y: 140, crop: 'fill' }, 5 { overlay: 'white_chicken', width: 220, height: 140, x: 110, y: 70, crop: 'fill' }, 6 { overlay: 'butterfly.png', height: 200, x: -10, angle: 10 }, 7 { width: 400, height: 260, radius: 20, crop: 'crop' }, 8 { overlay: 'text:Parisienne_35_bold:Memories%20from%20our%20trip', color: '#990C47', y: 155 }, 9 { effect: 'shadow' }, 10] 11 12const url = cl('yellow_tulip.jpg', transformations) 13 14// Or with other options 15const url = cl('yellow_tulip.jpg', { 16 version: 423, 17 transformations, 18})
The imageTransformDefaults
property provides a convenient way to include certain transform options in all image
transforms. For example, specifying auto format, quality and width for all images can be achieved by passing:
1const cl = cloudinary({ 2 cloudName: 'demo', 3 imageTransformDefaults: { 4 format: 'auto', 5 quality: 'auto', 6 width: 'auto', 7 }, 8}) 9 10const imageUrl = cl('sample.png', { aspectRatio: '16:9' }) 11expect(imageUrl).toBe('https://res.cloudina.../f_auto,q_auto,w_auto,ar_16:9/v1/sample.png')
Override any default value by passing a replacement value or remove it from the URL by passing undefined
:
1const cl = cloudinary({ 2 cloudName: 'demo', 3 imageTransformDefaults: { 4 format: 'auto', 5 quality: 'auto', 6 width: 'auto', 7 }, 8}) 9 10const imageUrl = cl('sample.png', { aspectRatio: '16:9', width: 150, quality: undefined }) 11expect(imageUrl).toBe('https://res.cloudina.../f_auto,ar_16:9,w_150/v1/sample.png')
Typings should help to provide valid parameter values in most cases, but errors will also be thrown on invalid parameter values in development, for example:
1cl('sample.jpg', { radius: 'round' }) 2// Throws: 3// Cloudinary Image :: radius should be a number, 'max' or have the form x[:y[:z[:u]]], received: 'round'
Some exceptions are the effect
, overlay
and underlay
values which are not validated.
When building for production ensure process.env.NODE_ENV === 'production'
so the validation logic can be removed from
the bundle during minification.
The most important configuration and image transformation features of Cloudinary should be supported, but if anything is missing please submit issues or PRs with references to the relevant Cloudinary documentation.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/28 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
21 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More