Socket
Socket
Sign inDemoInstall

ted-crushinator-helpers

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ted-crushinator-helpers

JS methods to produce crushinator'd image URLs.


Version published
Weekly downloads
31
increased by675%
Maintainers
1
Weekly downloads
 
Created
Source

JS Crushinator Helpers NPM Version Build Status

JavaScript methods to produce Crushinator'd image URLs.

crushinator.crush('http://images.ted.com/image.jpg', 'w=320')
  // => 'https://tedcdnpi-a.akamaihd.net/r/images.ted.com/image.jpg?w=320'

Installation

With NPM

npm install ted-crushinator-helpers

With Bower

bower install ted-crushinator-helpers

Manual

Code in lib/crushinator.js can be copied to your application.

This file is in UMD and has no other dependencies, so you can import it as an AMD/CommonJS module or simply let it occupy the crushinator namespace in your app's global.

API

This library provides the following methods:

crush ( url , [ options ] )

  • url: (string, required) - URL of the image you would like to be crushed.
  • options: (string, optional) - String of query params corresponding to crushinator's query params

For images on whitelisted domains, this method will return the URL for a crushed version of the specified image:

crushinator.crush('http://images.ted.com/image.jpg', 'w=320')
  // => 'https://tedcdnpi-a.akamaihd.net/r/images.ted.com/image.jpg?w=320'

For images hosted outside Crushinator's whitelisted domains, it will simply return the original URL:

crushinator.crush('http://celly.xxx/waffles.jpg', 'w=320')
  // => 'http://celly.xxx/waffles.jpg'

It will also avoid double-crushing images, and will update old Crushinator URLs to the new host:

crushinator.crush('https://tedcdnpi-a.akamaihd.net/r/images.ted.com/image.jpg?w=320', 'w=640')
  // => 'https://tedcdnpi-a.akamaihd.net/r/images.ted.com/image.jpg?w=640'
crushinator.crush('https://img-ssl.tedcdn.com/r/images.ted.com/image.jpg', 'w=320')
  // => 'https://tedcdnpi-a.akamaihd.net/r/images.ted.com/image.jpg?w=320'

uncrush ( url )

  • url: (string, required) - URL of previously crushed image.

Restore a previously crushed URL to its original form.

Note that the protocol must be borrowed from the crushed URL regardless of whether or not the host actually supports HTTPS.

crushinator.uncrush('https://tedcdnpi-a.akamaihd.net/r/images.ted.com/image.jpg?w=320')
  // => 'https://images.ted.com/image.jpg'

crushable ( url )

  • url: (string, required) - URL of image to check.

Returns true if the image's host is in Crushinator's whitelist, false otherwise.

crushinator.crushable('http://images.ted.com/image.jpg')
  // => true
crushinator.crushable('http://celly.xxx/waffles.jpg')
  // => false

Contributing

Setup

Use NVM to make sure you have the correct Node version installed for local development.

  • git clone git@github.com:tedconf/js-crushinator-helpers.git
  • Change into the new directory
  • nvm use and if the required Node version is not installed on your system, nvm install <version>
  • npm install

Running tests

npm test will lint and test the library.

Releasing a new version

  1. npm run build to produce a new lib/crushinator.js
  2. Update "version" in package.json and commit
  3. git tag the new semver
  4. Push master and the new tag upstream

FAQs

Package last updated on 17 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc