https://github.com/wellsjo/srnd
Search text and wrap results in tags
https://github.com/wellsjo/srnd
Last synced: 29 days ago
JSON representation
Search text and wrap results in tags
- Host: GitHub
- URL: https://github.com/wellsjo/srnd
- Owner: wellsjo
- License: mit
- Created: 2014-06-26T13:59:21.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-12-05T14:47:19.000Z (over 9 years ago)
- Last Synced: 2025-03-26T10:48:13.178Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# srnd
srnd provides utility functions for searching through large strings of text and wrapping search results in custom tags.
## Api
### surround(text, term, tag[, caseSensitive])
Wrap search terms in `text` with `term`. Optionally case sensitive search, default is true.**Example 1**
code
```javascript
var srnd = require('srnd');var text = 'Really, really long string of text.';
srnd.surround(text, 'really', '*');
```
output
```
*Really*, *really* long string of text.
```
**Example 2**
code
```javascript
var tags = {
open_tag: "",
close_tag: ""
};srnd.surround(text, 'string', tags);
```
output
```
Really, really long string of text.
```### tag(text, term, properties[, caseSensitive])
Shorthand for creating HTML elements.
Example
```javascript
var text = 'I want to make a button around a word.';// specify the element with the 'element' property
var element_properties = {
'element': 'button',
'class': 'btn btn-danger',
'some_attribute': null // if an attribute is null or false, it will
// just appear by itself without a value
};srnd.tag(text, 'buttons', element_properties);
// I want to make a button around a word.
```# License
MIT