Skip to content

Commit 132655e

Browse files
author
Maya Shavin
committed
update docs for url builder
1 parent c111413 commit 132655e

File tree

11 files changed

+89
-31
lines changed

11 files changed

+89
-31
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"pretest:ci": "yarn pretest",
1919
"test:ci": "lerna run test:ci --stream",
2020
"prettier": "yarn prettier --write .",
21-
"build:demo": "npm --prefix packages/demo run build",
2221
"changelog": "node scripts/changelog.js"
2322
},
2423
"author": "Maya Shavin <dpnminh@gmail.com>",

packages/url/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
# `cloudinary-build-url`
22

3+
![Cloudinary URL Builder](https://res.cloudinary.com/mayashavin/image/upload/v1605534519/logos/logo-light.png)
4+
35
> The lighter URL builder API for Cloudinary with all features in TypeScript.
46
57
By default, `f_auto` (auto format per browser) and `q_auto` (auto quality per device) are enabled. And all the urls are generated as secured HTTPS format, unless user states otherwise.
68

9+
[📖 Documentation]()
10+
11+
## Installation
12+
13+
```bash
14+
yarn add cloudinary-build-url
15+
```
16+
17+
or
18+
19+
```bash
20+
npm i cloudinary-build-url
21+
```
22+
723
## Usage
824

925
### Build a delivery url for image

packages/url/__tests__/transformers.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ describe('Modifiers', () => {
1313
}
1414

1515
expect(transform(options)).toEqual([
16-
'c_scale,w_500,h_500',
17-
'ar_16:9',
16+
'c_scale,w_500,h_500,ar_16:9',
1817
])
1918
})
2019

@@ -38,8 +37,7 @@ describe('Modifiers', () => {
3837
}
3938

4039
expect(transform(options)).toEqual([
41-
'c_scale,w_500,h_500',
42-
'ar_16:9',
40+
'c_scale,w_500,h_500,ar_16:9',
4341
['br_12','e_grayscale'],
4442
['bo_1px_dashed_#fff', 'e_pixelate']
4543
])

packages/url/__tests__/url.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ describe('Url', () => {
127127
resize: {
128128
width: 500,
129129
type: 'scale',
130+
aspectRatio: '16:9',
130131
height: 500,
131132
},
132-
aspectRatio: '16:9',
133-
})).toBe('https://res.cloudinary.com/demo/image/upload/c_scale,w_500,h_500,q_auto,ar_16:9,f_auto/v1/example')
133+
})).toBe('https://res.cloudinary.com/demo/image/upload/c_scale,w_500,h_500,ar_16:9,q_auto,f_auto/v1/example')
134134
})
135135

136136
it('should return fetch delivery url', () => {
@@ -143,9 +143,9 @@ describe('Url', () => {
143143
width: 500,
144144
type: 'scale',
145145
height: 500,
146+
aspectRatio: '16:9',
146147
},
147-
aspectRatio: '16:9',
148-
})).toBe('https://res.cloudinary.com/demo/image/fetch/c_scale,w_500,h_500,q_auto,ar_16:9,f_auto/v1/example')
148+
})).toBe('https://res.cloudinary.com/demo/image/fetch/c_scale,w_500,h_500,ar_16:9,q_auto,f_auto/v1/example')
149149
})
150150

151151
it('should return fetch deliver url with target format', () => {
@@ -157,10 +157,10 @@ describe('Url', () => {
157157
width: 500,
158158
type: 'scale',
159159
height: 500,
160+
aspectRatio: '16:9',
160161
},
161-
aspectRatio: '16:9',
162162
format: 'png'
163-
})).toBe('https://res.cloudinary.com/demo/image/fetch/c_scale,w_500,h_500,q_auto,ar_16:9,f_png/example')
163+
})).toBe('https://res.cloudinary.com/demo/image/fetch/c_scale,w_500,h_500,ar_16:9,q_auto,f_png/example')
164164
})
165165

166166
it('should return fetch deliver url with chained transformations', () => {
@@ -171,12 +171,12 @@ describe('Url', () => {
171171
width: 500,
172172
type: 'scale',
173173
height: 500,
174+
aspectRatio: '16:9',
174175
},
175-
aspectRatio: '16:9',
176176
chaining: [{
177177
effect: 'grayscale'
178178
}]
179-
})).toBe('https://res.cloudinary.com/demo/image/upload/c_scale,w_500,h_500,q_auto,ar_16:9,f_auto/e_grayscale/example')
179+
})).toBe('https://res.cloudinary.com/demo/image/upload/c_scale,w_500,h_500,ar_16:9,q_auto,f_auto/e_grayscale/example')
180180
})
181181
})
182182

packages/url/lib/constants.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const TRANSFORMERS = {
6767
rotate: 'a',
6868
audioCodec: 'ac',
6969
audioFrequency: 'af',
70-
aspectRatio: 'ar',
70+
// aspectRatio: 'ar',
7171
background: 'b',
7272
bitRate: 'br',
7373
// border: 'bo', // Border: { width:, height:, type:, color: }
@@ -83,8 +83,8 @@ export const TRANSFORMERS = {
8383
dpr: 'dpr',
8484
// else: '',
8585
// endIf: '',
86-
endOffset: 'eo',
87-
// fallbackContent: '', //to pay attention
86+
endOffset: 'eo', //to remove
87+
// fallbackContent: '',
8888
format: 'f',
8989
// flags: 'fl',
9090
gravity: 'g',
@@ -109,7 +109,7 @@ export const TRANSFORMERS = {
109109
// sourceTransformation,
110110
startOffset: 'so',
111111
streamingProfile: 'sp',
112-
// transformation: 't',
112+
transformation: 't',
113113
underlay: 'u',
114114
// variable,
115115
// variables,

packages/url/lib/transformers/format.ts

Whitespace-only changes.

packages/url/lib/transformers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { rawTransformation } from './rawTransformation'
55
export type Transformation = Array<string | string[]>
66

77
export const getResize = (options):string => {
8-
const hasResize = options.resize || options.width || options.height
8+
const hasResize = options.resize || options.width || options.height || options.aspectRatio
99

1010
if (!hasResize) return ''
1111

1212
const { resize } = require('./resize')
1313

14-
return resize(options.resize || { width: options.width, height: options.height, type: options.crop })
14+
return resize(options.resize || { width: options.width, height: options.height, type: options.crop, aspectRatio: options.aspectRatio })
1515
}
1616

1717
export const getBorder = (options):string => {

packages/url/lib/transformers/resize.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ export type ResizeType = 'imaggaScale' | 'imaggaCrop' | 'crop' | 'fill' | 'scale
33
export interface Resize {
44
type?: ResizeType,
55
width?: number | string,
6-
height?: number | string
6+
height?: number | string,
7+
aspectRatio?: string,
78
}
89

9-
export const resize = ({ type, width, height }: Resize) => {
10+
export const resize = ({ type, width, height, aspectRatio }: Resize) => {
1011
const w = width ? `w_${width}` : ''
1112
const h = height ? `h_${height}` : ''
1213
const crop = type ? `c_${type}` : ''
14+
const ar = aspectRatio ? `ar_${aspectRatio}` : ''
1315

14-
return [ crop, w, h ].filter(Boolean).join()
16+
return [ crop, w, h, ar ].filter(Boolean).join()
1517
}

packages/url/lib/types/CldOptions.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,30 @@ export interface TransformerOption {
4040
colorSpace?: string,
4141
customFunction?: CustomFunction,
4242
defaultImage?: string,
43-
delay?: string | number,
44-
density?: string,
45-
duration?: string | number,
43+
delay?: number,
44+
density?: number,
4645
dpr?: string | number,
4746
else?: string,
4847
endIf?: string,
49-
fallbackContent?: string,
5048
format?: string,
5149
fetchFormat?: string,
5250
gravity?: string,
5351
if?: string,
5452
flags?: string | string[],
55-
ocr?: string,
5653
opacity?: number,
5754
overlay?: string,
5855
page?: string,
5956
prefix?: string,
6057
quality?: string,
61-
radius?: number,
58+
radius?: number | string,
6259
rawTransformation?: string,
60+
transformation?: string,
6361
chaining?: TransformerOption[],
6462
underlay?: string,
6563
variable?: string,
6664
variables?: string,
67-
x?: string | number,
68-
y?: string | number,
65+
x?: number,
66+
y?: number,
6967
zoom?: string | number
7068
}
7169

@@ -79,6 +77,9 @@ export interface TransformerVideoOption extends TransformerOption{
7977
poster?: string,
8078
sourceTypes?: string[],
8179
videoCodec?: string,
80+
duration?: string | number,
8281
videoSampling?: string
82+
fallbackContent?: string,
83+
ocr?: string,
8384
}
8485

packages/url/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@
3535
"@types/jest": "^26.0.15",
3636
"@types/node": "^14.14.7",
3737
"jest": "^26.6.3",
38+
"jest-html-reporters": "^2.1.0",
3839
"ts-jest": "^26.4.4",
3940
"typescript": "^4.0.5"
4041
},
4142
"bugs": {
4243
"url": "https://github.com/mayashavin/cloudinary-api/issues"
4344
},
44-
"homepage": "https://github.com/mayashavin/cloudinary-api/packages/url#readme",
45+
"homepage": "https://github.com/mayashavin/cloudinary-api/tree/main/packages/url#README",
4546
"publishConfig": {
4647
"access": "public"
4748
},

0 commit comments

Comments
 (0)