Skip to content

Instantly share code, notes, and snippets.

@loonison123
Created November 1, 2014 21:48
Show Gist options
  • Select an option

  • Save loonison123/d2094ed86fc3946e5b63 to your computer and use it in GitHub Desktop.

Select an option

Save loonison123/d2094ed86fc3946e5b63 to your computer and use it in GitHub Desktop.
JavaScript module shared between node or browser
(function(exports){
// Only allow files uploaded below a maximum size
exports.isValidSize = function(sourceSize){
var maxSize = 1024 * 1024 * 10; // 10MB
return sourceSize <= maxSize;
};
})(typeof exports === 'undefined'? this['lib.image']={}: exports);
// -----------------------------------------------------------------
// Use in Node.JS
var imageHelper = require('lib.image');
imageHelper.isValidSize(1024); // true
// Use client side
// <script src="localhost:3000/lib.image.js"></script>
<script>
var isValidSize = lib.image.isValidSize(1024); // true
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment