findandreplacedomtext
Advanced tools
Comparing version 0.4.3 to 0.4.4
{ | ||
"name": "findandreplacedomtext", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"main": "./src/findAndReplaceDOMText.js", | ||
"description": "findAndReplaceDOMText: DOM find/replace utility", | ||
@@ -5,0 +6,0 @@ "repository": { |
@@ -55,2 +55,6 @@ # findAndReplaceDOMText | ||
## Installation | ||
Grab the latest [findAndReplaceDOMText.js](https://github.com/padolsey/findAndReplaceDOMText/blob/master/src/findAndReplaceDOMText.js) (or `npm install findandreplacedomtext`) and include it as a `<script>` on your page. | ||
## API / Usage | ||
@@ -67,4 +71,22 @@ | ||
### `preset:prose` | ||
### API | ||
#### Options | ||
The `options` object includes: | ||
* **find** (`RegExp | String`): Something to search for. A string will perform a global search by default (looking for all matches), but a RegExp will only do so if you include the global (`/.../g`) flag. | ||
* **replace** *optional* (`String | Function`): A String of text to replace matches with, or a Function which should return replacement Node or String. If you use a string, it can contain various tokens: | ||
* `$n` to represent the *n*th captured group of a regular expression (i.e. `$1`, `$2`, ...) | ||
* `$0` or `$&` to represent the entire match | ||
* <code>$`</code> to represent everything to the left of the match. | ||
* `$'` to represent everything to the right of the match. | ||
* **wrap** *optional* (`String | Node`): A string representing the node-name of an element that will be wrapped around matches (e.g. `span` or `em`). Or a Node (i.e. a stencil node) that we will clone for each match portion. | ||
* **portionMode** *optional* (`String`, one of `"retain"` or `"first"`): Indicates whether to re-use existing node boundaries when replacing a match with text (i.e. the default, `"retain"`), or whether to instead place the entire replacement in the first-found match portion's node. *Most of the time you'll want the default*. | ||
* **filterElements** *optional* (`Function`): A function to be called on every element encountered by `findAndReplaceDOMText`. If the function returns false the element will be altogether ignored. | ||
* **forceContext** *optional* (`Function | Boolean`): A boolean or a boolean-returning function that'll be called on every element to determine if it should be considered as its own matching context. See below under [*Contexts*](#user-content-contexts) for more info. | ||
* **preset** *optional* (`String`): Currently there's only one preset: `prose`. See below. | ||
#### `preset:prose` | ||
The most common usage of `findAndReplaceDOMText` is to replace text found in regular prose, not all DOM nodes. To make this easier there is a preset that you can use to instruct it to: | ||
@@ -86,19 +108,2 @@ | ||
### API | ||
#### Options | ||
The `options` object includes: | ||
* **find** (`RegExp | String`): Something to search for. A string will perform a global search by default (looking for all matches), but a RegExp will only do so if you include the global (`/.../g`) flag. | ||
* **replace** *optional* (`String | Function`): A String of text to replace matches with, or a Function which should return replacement Node or String. If you use a string, it can contain various tokens: | ||
* `$n` to represent the *n*th captured group of a regular expression (i.e. `$1`, `$2`, ...) | ||
* `$0` or `$&` to represent the entire match | ||
* <code>$`</code> to represent everything to the left of the match. | ||
* `$'` to represent everything to the right of the match. | ||
* **wrap** *optional* (`String | Node`): A string representing the node-name of an element that will be wrapped around matches (e.g. `span` or `em`). Or a Node (i.e. a stencil node) that we will clone for each match portion. | ||
* **portionMode** *optional* (`String`, one of `"retain"` or `"first"`): Indicates whether to re-use existing node boundaries when replacing a match with text (i.e. the default, `"retain"`), or whether to instead place the entire replacement in the first-found match portion's node. *Most of the time you'll want the default*. | ||
* **filterElements** *optional* (`Function`): A function to be called on every element encountered by `findAndReplaceDOMText`. If the function returns false the element will be altogether ignored. | ||
* **forceContext** *optional* (`Function | Boolean`): A boolean or a boolean-returning function that'll be called on every element to determine if it should be considered as its own matching context. See below under [*Contexts*](#user-content-contexts) for more info. | ||
#### What is a portion? | ||
@@ -209,2 +214,3 @@ | ||
* 0.4.4 (4 May 2015): Remove duplicate key from `NON_CONTIGUOUS_PROSE_ELEMENTS`. Expose library via UMD ([See #32](https://github.com/padolsey/findAndReplaceDOMText/issues/32)). | ||
* 0.4.3 (28 Apr 2015): Add `preset:prose` and `forceContext` features. [See #29](https://github.com/padolsey/findAndReplaceDOMText/issues/29). | ||
@@ -211,0 +217,0 @@ * 0.4.2 (30 Mar 2014): Fix IE to avoid incorrectly-closed-tags issue ([see #20](https://github.com/padolsey/findAndReplaceDOMText/issues/20)). Thanks to [shauryamal](https://github.com/shauryamal)! |
@@ -10,3 +10,14 @@ /** | ||
*/ | ||
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() { | ||
@@ -114,3 +125,3 @@ var PORTION_MODE_RETAIN = 'retain'; | ||
// Block Elements | ||
address:1, article:1, aside:1, blockquote:1, canvas:1, dd:1, div:1, | ||
address:1, article:1, aside:1, blockquote:1, dd:1, div:1, | ||
dl:1, fieldset:1, figcaption:1, figure:1, footer:1, form:1, h1:1, h2:1, h3:1, | ||
@@ -622,2 +633,2 @@ h4:1, h5:1, h6:1, header:1, hgroup:1, hr:1, main:1, nav:1, noscript:1, ol:1, | ||
}()); | ||
})); |
106240
2928
249