0.0.4 • Published 8 years ago

srnd v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

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

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

var tags = {
  open_tag: "<a href='some_url.com'>",
  close_tag: "</a>"
};

srnd.surround(text, 'string', tags);

output

Really, really long <a href='some_url.com'>string</a> of text.

tag(text, term, properties, caseSensitive)

Shorthand for creating HTML elements.

Example

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 class="btn btn-danger" some_attribute>button</button> around a word.

License

MIT

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago