imgix-core-js is an npm and bower package that provides the common boilerplate for imgix server-side and client-side JavaScript-based functionality. For a turn-key imgix solution, please see imgix.js.
imgix-core-js adheres to the imgix-blueprint for definitions of its functionality.
imgix-core-js can be installed as either via npm or via bower:
$ npm install --save imgix-core-js
or
$ bower install --save imgix-core-js
imgix-core-js and its tests are written in ES6 JavaScript. Babel is used for transpilation into the lib/ directory.
Depending on your module system, using imgix-core-js is done a few different ways. The most common entry point will be the Client class. Whenever you provide data to imgix-core-js, make sure it is not already URL-encoded, as the library handles proper encoding internally.
var ImgixClient = require('imgix-core-js');
var client = new ImgixClient("my-social-network.imgix.net", "<SECURE TOKEN>");
var url = client.path("/path/to/image.png").toUrl({ w: 400, h: 300 }).toString();
console.log(url); // => "https://my-social-network.imgix.net/users/1.png?w=400&h=300&s=…"import Client from "imgix/client";
let imgixClient = new Client("my-social-network.imgix.net", "<SECURE TOKEN>");
let url = imgixClient.path("/path/to/image.png").toUrl({ w: 400, h: 300 }).toString();
console.log(url); // => "https://my-social-network.imgix.net/users/1.png?w=400&h=300&s=…"// Include dist/imgix-core-js.umd.js somewhere on the head
let imgixClient = new Client("my-social-network.imgix.net", "<SECURE TOKEN>");
let url = imgixClient.path("/path/to/image.png").toUrl({ w: 400, h: 300 }).toString();
console.log(url); // => "https://my-social-network.imgix.net/users/1.png?w=400&h=300&s=…"For security and diagnostic purposes, we sign all requests with the language and version of library used to generate the URL.
This can be disabled by passing a falsy value for the librarySignature param to either new Path or new Client:
// `librarySignature` is the last param in both examples
new Path('my-image.png', 'my-source.imgix.net', null, true, null);
new Client('my-source.imgix.net', null, true, null);imgix-core-js uses mocha for testing. Here’s how to run those tests:
npm test
Publishing a new version needs to be done for both NPM and Bower. To publish a new version of the NPM package:
$ npm publishTo publish a new version of the Bower package:
$ npm run compile_umd # dist/imgix-core-js.umd.js is the entry point for Bower
$ git add -f dist/imgix-core-js.umd.js
$ git tag -a vX.Y.Z
$ git push origin --tags master