@cfg.plat/configure-sprite-sizes
Configure sprite sizing conventions
$ cnpm install @cfg.plat/configure-sprite-sizes 
SYNC missed versions from official npm registry.

Configure Sprite Sizes

Configure sprite sizing conventions.

Fluid CI Build Status Fluid CI Code Coverage Fluid CI Dependencies

This library will help keeping this rules consistent across different systems (same rounding and dynamic scales) without product specific configurations.

Installation

npm install git+ssh://git@bitbucket.org/fluidretail/configure-sprite-sizes.git --save

Usage

CLI interface

Generates intermediary scales when the width and height of scale 1 is provided.

./node_modules/.bin/configure-sprite-sizes --width 20000 --height 10000

Outputs

[{"scale":1,"width":20000,"height":10000},{"scale":0.333,"width":6660,"height":3330},{"scale":0.111,"width":2220,"height":1110},{"scale":0.037,"width":740,"height":370}]

As a Node.js module

Include the library on Node.js

const configureSpriteSizes = require("configure-sprite-sizes");

getScales

This method will return an array of scales that changes depending on the size of the original images.

const scales = configureSpriteSizes.getScales({
  width: 10000, // max width as defined on the admin
  height: 500 // max height as defined on the admin
});

scales now contains an array with the different sprite scales expected for a product. For example:

[
  {scale: 1, width: 10000, height: 5000},
  {scale: 0.6, width: 6000, height: 3000},
  {scale: 0.3, width: 3000, height: 1500}
]

getSpriteScale

Gets scale details that for downloading the sprites required to compose an image.

const scale = configureSpriteSizes.getSpriteScale({
  width: 10000, // max width as defined on the admin
  height: 500 // max height as defined on the admin
  scale: 0.5 // The scale the user requested
});

console.log(scale); // {scale: 0.6, width: 6000, height: 3000}

This allows us to find the smallest sprite size that can be downloaded to generate the image using the desired size.

getSpriteBasePath

Gets the base path for a sprite on S3. Takes a hash with the following properties (all required): customerId, workflow, productId, configVersion, scale.

const path = configureSpriteSizes.getSpriteBasePath({
  customerId: 1554,
  workflow: "prod",
  productId: 123456,
  configVersion: 67890,
  scale: 0.5
});
console.log(path); // 0963-1554/prod/123456/67890/0.5/

Note: per the S3 docs, its recommended to prepend the first few characters of an md5 checksum at the beginning of the object path in order to allow S3 to rebalance their index under the hood (done automatically).

Testing

make test

Continuous linting and testing

make dev

Releasing new versions

make release

The tasks release (same as release-patch), release-minor and release-major should be used for pushing new versions of the code.

License

Copyright (c) 2016 Fluid Inc, All rights reserved.

Current Tags

  • 1.6.1                                ...           latest (9 months ago)

1 Versions

  • 1.6.1                                ...           9 months ago

Copyright 2014 - 2016 © taobao.org |