stringbean

String helper methods that doesn't clobber the String prototype

Stringbean

Stringbean is a collection of string helper methods that don't clobber the String prototype.

npm install stringbean
var stringbean = require('stringbean');

Escapes HTML to entities

var someString = "<script>XSS Baby!</script>";
console.log(stringbean.escapeHTML(someString));

&lt;script&gt;XSS Baby!&lt;/script&gt

Unescapes escaped HTML

var someString = "&lt;script&gt;alert(&quot;oh hai&quot;);&lt;/script&gt;";
console.log(stringbean.escapeHTML(someString));

<script>alert("oh hai")</script>;

Removes non alpha characters from a string

var someString = "ABC123def";
console.log(stringbean.removeAlpha(someString));

ABCdef

Removes non alphanumeric characters from a string

var someString = "$£@@$%^foo(*&^%$£!@";
console.log(stringbean.removeNonAlphanumeric(someString));

foo

Removes non alphanumeric characters from a string

var someString = "ABCefg123hij";
console.log(stringbean.removeNonNumeric(someString));

123

Removes numeric characters from a string

var someString = "foo1a2b3cbar";
console.log(stringbean.removeNumeric(someString));

fooabcbar

Base64 encodes a string

var someString = "base64encodethisplz";
console.log(stringbean.base64Encode(someString));

YmFzZTY0ZW5jb2RldGhpc3Bseg==

Base64 decodes a string

var someString = "YmFzZTY0ZGVjb2RldGhpc3Bsegl";
console.log(stringbean.base64Decode(someString));

base64decodethisplz

Returns true if a string is JSON

var someString = '{"some":"json"}';
console.log(stringbean.isJSON(someString));

true