From 74acd22117c6b0d3c49e74a242637bf8cd69bdab Mon Sep 17 00:00:00 2001 From: Chris Gathercole Date: Wed, 31 May 2017 14:59:16 +0100 Subject: [PATCH] UMD-ified js file so can work as is outaide of Node --- src/js/crossword_parser.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/js/crossword_parser.js b/src/js/crossword_parser.js index bae55e3..e45504f 100644 --- a/src/js/crossword_parser.js +++ b/src/js/crossword_parser.js @@ -1,3 +1,16 @@ +// Using UMD (Universal Module Definition), see https://github.com/umdjs/umd, and Jake, +// for a js file to be included as-is in Node code and in browser code. +(function (root, factory) { + if (typeof module === 'object' && module.exports) { + // Node. Does not work with strict CommonJS, but + // only CommonJS-like environments that support module.exports, + // like Node. + module.exports = factory(); + } else { + // Browser globals (root is window) + root.CrosswordDSL = factory(); + } +}(this, function () { // given the DSL, ensure we have all the relevant pieces, // and assume there will be subsequent checking to ensure they are valid function parseDSL(text){ @@ -489,7 +502,8 @@ return jsonText; } - module.exports = { + return { 'whateverItIs' : parseWhateverItIs, 'intoSpecJson' : parseWhateverItIsIntoSpecJson }; +}));