From a8ad0e4e0743f37200008e8e9cd92a35f35e728c Mon Sep 17 00:00:00 2001 From: Andrea Giammarchi Date: Fri, 7 Nov 2014 10:02:24 +0000 Subject: [PATCH] avoid errors when required via node and no location is present --- package.json | 2 +- twemoji-dist.js | 9 ++++++++- twemoji.npm.js | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ed6731fb..a3e6c0ca 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.1", "name": "twemoji", "license": ["MIT", "CC-BY-4.0"], "description": "A Unicode standard based way to implement emoji across all platforms.", diff --git a/twemoji-dist.js b/twemoji-dist.js index 0a41b1dd..195aec21 100755 --- a/twemoji-dist.js +++ b/twemoji-dist.js @@ -8,7 +8,14 @@ var fs = require('fs'); fs.writeFileSync( 'twemoji.npm.js', - fs.readFileSync('twemoji.js') + '\nmodule.exports = twemoji;' + [ + 'var location = global.location || {};', + fs.readFileSync('twemoji.js'), + 'if (!location.protocol) {', + ' twemoji.base = twemoji.base.replace(/^http:/, "");', + '}', + 'module.exports = twemoji;' + ].join('\n') ); fs.writeFileSync( diff --git a/twemoji.npm.js b/twemoji.npm.js index e255fb85..20e67c9b 100644 --- a/twemoji.npm.js +++ b/twemoji.npm.js @@ -1,3 +1,4 @@ +var location = global.location || {}; /*jslint indent: 2, browser: true, bitwise: true, plusplus: true */ var twemoji = (function ( /*! Copyright Twitter Inc. and other contributors. Licensed under MIT *//* @@ -510,4 +511,7 @@ var twemoji = (function ( } }()); +if (!location.protocol) { + twemoji.base = twemoji.base.replace(/^http:/, ""); +} module.exports = twemoji; \ No newline at end of file