import S = require('string'); S('hello').s //"hello" S(['a,b']).s //"a,b" S({hi: 'jp'}).s //"[object Object]"" S('foo').between('', '').s // => 'foo' S('foo').between('', '').s // => 'foo' S('foo').between('', '').s // => 'foo' S('foo').between('', '').s // => '' S('Some strings } are very {weird}, dont you think?').between('{', '}').s // => 'weird' S('This is a test string').between('test').s // => ' string' S('This is a test string').between('', 'test').s // => 'This is a ' S('data_rate').camelize().s; //'dataRate' S('background-color').camelize().s; //'backgroundColor' S('-moz-something').camelize().s; //'MozSomething' S('_car_speed_').camelize().s; //'CarSpeed' S('yes_we_can').camelize().s; //'yesWeCan' S('jon').capitalize().s; //'Jon' S('JP').capitalize().s; //'Jp' S('foobar').chompLeft('foo').s; //'bar' S('foobar').chompLeft('bar').s; //'foobar' S('foobar').chompRight('bar').s; //'foo' S('foobar').chompRight('foo').s; //'foobar' var str = S(' String \t libraries are \n\n\t fun\n! ').collapseWhitespace().s; //'String libraries are fun !' S('JavaScript is one of the best languages!').contains('one'); //true S('JP likes to program. JP does not play in the NBA.').count("JP")// 2 S('Does not exist.').count("Flying Spaghetti Monster") //0 S('Does not exist.').count("Bigfoot") //0 S('JavaScript is fun, therefore Node.js is fun').count("fun") //2 S('funfunfun').count("fun") //3 S('dataRate').dasherize().s; //'data-rate' S('CarSpeed').dasherize().s; //'-car-speed' S('yesWeCan').dasherize().s; //'yes-we-can' S('backgroundColor').dasherize().s; //'background-color' S('Ken Thompson & Dennis Ritchie').decodeHTMLEntities().s; //'Ken Thompson & Dennis Ritchie' S('3 < 4').decodeHTMLEntities().s; //'3 < 4' S("hello jon").endsWith('jon'); //true S('
just some text
').stripTags().s //'just some text' S('just some text
').stripTags('p').s //'just some text' var str = "Hello {{name}}! How are you doing during the year of {{date-year}}?" var values = {name: 'JP', 'date-year': 2013} console.log(S(str).template(values).s) //'Hello JP! How are you doing during the year of 2013?' str = "Hello #{name}! How are you doing during the year of #{date-year}?" console.log(S(str).template(values, '#{', '}').s) //'Hello JP! How are you doing during the year of 2013?' S.TMPL_OPEN = '{' S.TMPL_CLOSE = '}' str = "Hello {name}! How are you doing during the year of {date-year}?" console.log(S(str).template(values).s) //'Hello JP! How are you doing during the year of 2013?' S(' ').times(5).s //' ' S('*').times(3).s //'***' S('true').toBoolean() //true S('false').toBoolean() //false S('hello').toBoolean() //false S(true).toBoolean() //true S('on').toBoolean() //true S('yes').toBoolean() //true S('TRUE').toBoolean() //true S('TrUe').toBoolean() //true S('YES').toBoolean() //true S('ON').toBoolean() //true S('').toBoolean() //false S(undefined).toBoolean() //false S('undefined').toBoolean() //false S(null).toBoolean() //false S(false).toBoolean() //false S({}).toBoolean() //false S(1).toBoolean() //true S(-1).toBoolean() //false S(0).toBoolean() //false S(['a', 'b', 'c']).toCSV().s //'"a","b","c"' S(['a', 'b', 'c']).toCSV(':').s //'"a":"b":"c"' S(['a', 'b', 'c']).toCSV(':', null).s //'a:b:c') S(['a', 'b', 'c']).toCSV('*', "'").s //"'a'*'b'*'c'" S(['a"', 'b', 4, 'c']).toCSV({delimiter: ',', qualifier: '"', escape: '\\', encloseNumbers: false}).s //'"a\\"","b",4,"c"' S({firstName: 'JP', lastName: 'Richardson'}).toCSV({keys: true}).s //'"firstName","lastName"' S({firstName: 'JP', lastName: 'Richardson'}).toCSV().s //'"JP","Richardson"' S('5').toFloat() // 5 S('5.3').toFloat() //5.3 S(5.3).toFloat() //5.3 S('-10').toFloat() //-10 S('55.3 adfafaf').toFloat() // 55.3 S('afff 44').toFloat() //NaN S(3.45522222333232).toFloat(2) // 3.46 S('5').toInt(); //5 S('5.3').toInt(); //5; S(5.3).toInt(); //5; S('-10').toInt(); //-10 S('55 adfafaf').toInt(); //55 S('afff 44').toInt(); //NaN S('0xff').toInt() //255 S('my name is JP.').capitalize().toString(); //My name is JP. var a = "Hello " + S('joe!'); //a = "Hello joe!" S("Hello").toString() === S("Hello").s; //true S('hello ').trim().s; //'hello' S(' hello ').trim().s; //'hello' S('\nhello').trim().s; //'hello' S('\nhello\r\n').trim().s; //'hello' S('\thello\t').trim().s; //'hello' S(' How are you?').trimLeft().s; //'How are you?'; S('How are you? ').trimRight().s; //'How are you?'; S('this is some long text').truncate(3).s //'...' S('this is some long text').truncate(7).s //'this is...' S('this is some long text').truncate(11).s //'this is...' S('this is some long text').truncate(12).s //'this is some...' S('this is some long text').truncate(11).s //'this is...' S('this is some long text').truncate(14, ' read more').s //'this is some read more' S('dataRate').underscore().s; //'data_rate' S('CarSpeed').underscore().s; //'_car_speed' S('yesWeCan').underscore().s; //'yes_we_can' S('<div>hi</div>').unescapeHTML().s; //