Thanks to visit codestin.com
Credit goes to github.com

Skip to content

imgix/js-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

imgix-core-js

Build Status

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.

Installing

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

ES6

imgix-core-js and its tests are written in ES6 JavaScript. Babel is used for transpilation into the lib/ directory.

Using

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.

CommonJS

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=…"

ES6 Modules

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=…"

In the browser

// 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=…"

What is the ixlib param on every request?

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);

Testing

imgix-core-js uses mocha for testing. Here’s how to run those tests:

npm test

Publishing a new version

Publishing a new version needs to be done for both NPM and Bower. To publish a new version of the NPM package:

$ npm publish

To 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