node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org ยป


(  /        _/_      
  /--   (   /  _   __
(/____//_)_(__/ (_(_)

Estro is a tiny Extended String Object helper enables you to get more out of the string class.


var string = "Hello";

if (!string.isEmpty()) alert(string);
if (string.equals("Hello")) alert("Hi :D!");
if (string.equalsIgnoreCase("hello")) alert("Hello again!");
if (string.startsWith("H")) alert("Starts with H!");
if (string.endsWith("ello")) alert("Ends with ello!");
if (string.contains("e")) alert(string + " contains an e! Who knew?");
alert("  trimmed  ".trim());

You can view a demo here.


Estro contains the following string extensions (Unless they already exist; Estro is meant to be un-obtrusive):

  • string.equals(string) Check one string against another. Returns: Boolean
  • string.equalsIgnoreCase(string) Check one string against another without case sensitivity. Returns: Boolean
  • string.startsWith(prefix) Check to see if a string starts with the given string. Returns: Boolean
  • string.endsWith(suffix) Check to see if a string ends with the given string. Returns: Boolean
  • string.contains(needle) Check to see if a string contains a given string. Returns Boolean
  • string.trim() Trim the string of whitespace. Returns: String
  • string.isEmpty() Check to see if the string is empty, and really empty. Returns Boolean
  • string.reverse() Reverses string. IE: Hello -> olleH
  • string.repeat(n) Repeat string n times
  • string.capitalize() Capitalize each word in the string and lower the rest. Returns String
  • string.camelize() CamelCase string, hello-there -> helloThere. Returns String
  • string.bind(data) Small template layer. Ex: "Hi %{name}".bind({'name': 'Estro'});" Outputs: Hi Estro
  • string.extract(regex, n) Extract data into an array based on regex and group(n). Returns Array

In the future?

Hopefully, in the future I will extend this to work with other objects and not just strings.


Copyright Nijikokun 2011

GNUv3 Affero License