GithubHelp home page GithubHelp logo

asset-helper's Introduction

Asset Helper

Build Status

A simple and easy to use module to manage asset path and versions.

Installation

Install the module through NPM:

$ npm install asset-helper --save

Requires Node 4 or above

Examples

Include the module and create a new AssetHelper object:

const AssetHelper = require('asset-helper');

// Will output style/main.css
const assetHelper = new AssetHelper();
console.log(assetHelper.path('style/main.css')); 

// Will output http://www.foo.com/style/main.css
const assetHelperWithBaseUrl = new AssetHelper({
  baseUrl: 'http://www.foo.com/'
});
console.log(assetHelperWithBaseUrl.path('style/main.css')); 

// Will output /style/main.css?v=3094302hdhsd9fu9023
const assetHelperWithHash = new AssetHelper({
  baseDirectory: __dirname + '/../public/',
  appendHash: true
});
console.log(assetHelperWithHash.path('style/main.css'));

// You can override configuration params on individual calls:
// Will output /style/main.css
console.log(assetHelperWithHash.path('style/main.css', { appendHash: false }));

Configuration options

baseUrl

It will prepend a base url to your asset. Useful in case you use a CDN and want the local path when on development environment.

baseDirectory

Needed for calculating the hash, it should point to your asset main directory.

appendHash

It will append a querystring with a MD5 calculated on file content.

Testing

$ npm test

Contributing

This module was originally written to be used with Receiptful and is used in a production environment currently. This will ensure that this module is well maintained, bug free and as up to date as possible.

Receiptful's developers will continue to make updates as often as required to have a consistently bug free platform, but we are happy to review any feature requests or issues and are accepting constructive pull requests.

asset-helper's People

Contributors

stefanosala avatar dlebech avatar kenany avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.