stringish
Helper for creating string backed objects
Wrap strings and provide additional information. This is especially useful for parser tokens, or anytime the backing data is just a string, but you want to add sugar methods that provide additional functionality.
Usage
var stringish = ;var assert = ; { this_stringValue = backingString;} ; // adds `toString`, `valueOf`, and some delegate methods. var token = 'Token Value'; // this is the useful bit; // toString just returns what you put in.assert; // toValue is overridden, so you can do non-strict comparisonassert; // can be used with regularExpressions;assert;
Each instance has the following delegate methods that will be called on the underlying String.
- charAt
- charCodeAt
- concat
- indexOf
- lastIndexOf
- match
- replace
- search
- slice
- split
- substr
- substring
- toLowerCase
- toUpperCase
- trim
API
stringish(proto [, propertyName])
Adds a number of functions to ConstructorFn.prototype
, including toString
, valueOf
,
and a host of methods that delegate directly to the string.
ConstructorFn
Required
type: function
An object that you want to add the delegate functions to, usually a prototype value.
propertyName
Optional
type: string
The property name of the string you want to delegate to. Defaults to _stringValue
.
License
MIT © James Talmage