ted-crushinator-helpers
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -5,4 +5,14 @@ # Changelog | ||
[(Commit list.)](https://github.com/tedconf/js-crushinator-helpers/compare/129f407...master) | ||
[(Commit list.)](https://github.com/tedconf/js-crushinator-helpers/compare/e19749f...master) | ||
### 2.2.0 | ||
* [#5](https://github.com/tedconf/js-crushinator-helpers/issues/5) Allow hyphenated form for Crushinator options | ||
* [#6](https://github.com/tedconf/js-crushinator-helpers/issues/6) Provide AMD-only distribution | ||
* [#9](https://github.com/tedconf/js-crushinator-helpers/issues/9) Add option for custom query parameters | ||
* [#7](https://github.com/tedconf/js-crushinator-helpers/issues/7) Deprecate direct use of string API for query params | ||
* Add `pe.tedcdn.com` to our hosts whitelist | ||
[(Commit list.)](https://github.com/tedconf/js-crushinator-helpers/compare/129f407...e19749f) | ||
### 2.1.0 | ||
@@ -9,0 +19,0 @@ |
{ | ||
"name": "ted-crushinator-helpers", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "JS methods to produce crushinator'd image URLs.", | ||
"license": "MIT", | ||
"main": "dist/crushinator.js", | ||
"main": "dist/crushinator.umd.min.js", | ||
"repository": { | ||
@@ -12,3 +12,3 @@ "type": "git", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"build": "node build", | ||
"lint": "jshint . && jscs .", | ||
@@ -27,4 +27,6 @@ "pretest": "npm run lint", | ||
"rollup": "^0.25.4", | ||
"rollup-plugin-babel": "^2.4.0" | ||
"rollup-plugin-babel": "^2.4.0", | ||
"rollup-plugin-uglify": "^0.2.0", | ||
"sinon": "^1.17.3" | ||
} | ||
} |
@@ -28,3 +28,3 @@ # JS Crushinator Helpers [![NPM Version](https://img.shields.io/npm/v/ted-crushinator-helpers.svg?style=flat)](https://npmjs.org/package/ted-crushinator-helpers) [![Build Status](https://travis-ci.org/tedconf/js-crushinator-helpers.svg?branch=master)](https://travis-ci.org/tedconf/js-crushinator-helpers) | ||
Code in `dist/crushinator.js` can be copied to your application. | ||
Code in `dist/crushinator.umd.min.js` can be copied to your application. | ||
@@ -157,3 +157,3 @@ ## API | ||
}) | ||
// => 'https://tedcdnpi-a.akamaihd.net/r/images.ted.com/image.jpg?quality=93' | ||
// => 'https://tedcdnpi-a.akamaihd.net/r/images.ted.com/image.jpg?w=640&h=480&c=200%2C100%2C50%2C25' | ||
``` | ||
@@ -163,2 +163,29 @@ | ||
Crop configuration options can also be sent in hyphenated form: | ||
```javascript | ||
crushinator.crush('http://images.ted.com/image.jpg', { | ||
width: 640, | ||
height: 480, | ||
'crop-width': 200, 'crop-height': 100, | ||
'crop-x': 50, 'crop-y': 25, | ||
'crop-afterResize': true | ||
}) | ||
// => 'https://tedcdnpi-a.akamaihd.net/r/images.ted.com/image.jpg?w=640&h=480&c=200%2C100%2C50%2C25' | ||
``` | ||
##### query | ||
The `query` option can be used to append custom query parameters to the Crushinator URL: | ||
```javascript | ||
crushinator.crush('http://images.ted.com/image.jpg', { | ||
width: 200, | ||
query: { c: '100,100' } | ||
}) | ||
// => 'https://tedcdnpi-a.akamaihd.net/r/images.ted.com/image.jpg?w=200&c=100%2C100' | ||
``` | ||
This allows you to directly apply [any of Crushinator's query parameters](https://github.com/tedconf/crushinator#usage) instead of using this helper's wrapper API. | ||
### uncrush | ||
@@ -229,3 +256,3 @@ | ||
1. `npm run build` to produce a new `dist/crushinator.js` | ||
1. `npm run build` to produce new JS in the `dist` directory | ||
2. Update "version" in `package.json` and commit | ||
@@ -232,0 +259,0 @@ 3. `git tag` the new semver |
@@ -12,2 +12,4 @@ /** | ||
import {prepNumber} from './lib/preppers'; | ||
import {serialize} from './lib/query-string'; | ||
import {warn} from './lib/log'; | ||
@@ -20,2 +22,3 @@ /** | ||
'pb-assets.tedcdn.com', | ||
'pe.tedcdn.com', | ||
'assets2.tedcdn.com', | ||
@@ -125,5 +128,14 @@ 'tedcdnpf-a.akamaihd.net', | ||
// Complain about use of the deprecated string API | ||
if (typeof options === 'string') { | ||
warn('Sending Crushinator options as a query string is ' + | ||
'deprecated. Please use the object format.'); | ||
} | ||
// Stringify object options | ||
if (typeof options === 'object') { // or: everything is a duck | ||
options = params.serialize(options); | ||
options = serialize(Object.assign( | ||
params.get(options), | ||
options.query || {} | ||
)); | ||
} | ||
@@ -130,0 +142,0 @@ |
'use strict'; | ||
import {serialize} from './query-string'; | ||
export class ParamBuilder { | ||
@@ -15,2 +13,25 @@ | ||
/** | ||
Convert values from hyphenated form to an object tree. | ||
*/ | ||
dehyphenate(values) { | ||
const dehyphenated = {}; | ||
for (const key in values) { | ||
if (values.hasOwnProperty(key)) { | ||
const value = values[key]; | ||
const splitted = key.match(/([^-]+)-+(.*)/); | ||
if (splitted && this.options.hasOwnProperty(splitted[1])) { | ||
dehyphenated[splitted[1]] = dehyphenated[splitted[1]] || {}; | ||
dehyphenated[splitted[1]][splitted[2]] = value; | ||
} else { | ||
dehyphenated[key] = value; | ||
} | ||
} | ||
} | ||
return dehyphenated; | ||
} | ||
/** | ||
Returns parameters in object form. | ||
@@ -21,2 +42,5 @@ */ | ||
// Convert "crop-width" to crop.width etc. | ||
values = this.dehyphenate(values); | ||
for (const key in this.options) { | ||
@@ -38,11 +62,4 @@ if (values.hasOwnProperty(key)) { | ||
/** | ||
Returns parameters in query string form. | ||
*/ | ||
serialize(values) { | ||
return serialize(this.get(values)); | ||
} | ||
} | ||
export default ParamBuilder; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
41753
13
748
258
10