From e8e9beb9a70d31e68cb81dcb48c9ae5b83ebbfbd Mon Sep 17 00:00:00 2001 From: Jacob Waller Date: Sun, 3 May 2015 15:44:07 +0200 Subject: [PATCH 1/2] Add `main` field to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index c64cce1..2f998d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "findandreplacedomtext", "version": "0.4.3", + "main": "./src/findAndReplaceDOMText.js", "description": "findAndReplaceDOMText: DOM find/replace utility", "repository": { "type": "git", From 00179c614d7d3d1545d2f62497245e0f12e04ca8 Mon Sep 17 00:00:00 2001 From: Jacob Waller Date: Sun, 3 May 2015 15:44:43 +0200 Subject: [PATCH 2/2] Export method using UMD --- src/findAndReplaceDOMText.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/findAndReplaceDOMText.js b/src/findAndReplaceDOMText.js index e5acde2..27121bf 100644 --- a/src/findAndReplaceDOMText.js +++ b/src/findAndReplaceDOMText.js @@ -7,7 +7,18 @@ * and replaces each match (or node-separated portions of the match) * in the specified element. */ -window.findAndReplaceDOMText = (function() { + (function (root, factory) { + if (typeof module === 'object' && module.exports) { + // Node/CommonJS + module.exports = factory(); + } else if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(factory); + } else { + // Browser globals + root.findAndReplaceDOMText = factory(); + } + }(this, function factory() { var PORTION_MODE_RETAIN = 'retain'; var PORTION_MODE_FIRST = 'first'; @@ -617,4 +628,4 @@ window.findAndReplaceDOMText = (function() { return exposed; -}()); +}));