# Strings ## `String.prototype.*` * `charAt(pos: number): string` ES1 Returns the character at index `pos`, as a string (JavaScript does not have a datatype for characters). `str[i]` is equivalent to `str.charAt(i)` and more concise. ```repl > 'abc'.charAt(1) 'b' ``` * `charCodeAt(pos: number): number` ES1 Returns the 16-bit number (0–65535) of the UTF-16 code unit (character) at index `pos`. ```repl > 'abc'.charCodeAt(1) 98 ``` * `codePointAt(pos: number): number | undefined` ES6 Returns the number of the Unicode code point of the 1–2 characters at index `pos`. If there is no such index, it returns `undefined`. * `concat(...strings: string[]): string` ES3 Returns the concatenation of `this` and `strings`. `'a'+'b'` is equivalent to `'a'.concat('b')` and more concise. ```repl > 'ab'.concat('cd', 'ef', 'gh') 'abcdefgh' ``` * `endsWith(searchString: string, endPos=this.length): boolean` ES6 Returns `true` if `this` ends with `searchString` at index `endPos` and `false`, otherwise. ```repl > 'foo.txt'.endsWith('.txt') true > 'abc'.endsWith('ab', 2) true ``` * `includes(searchString: string, startPos=0): boolean` ES6 Returns `true` if `this` contains the `searchString` and `false`, otherwise. The search starts at `startPos`. ```repl > 'abc'.includes('b') true > 'abc'.includes('b', 2) false ``` * `indexOf(searchString: string, minIndex=0): number` ES1 Returns the lowest index at which `searchString` appears within `this`, or `-1`, otherwise. Any returned index will be `minIndex` or higher. ```repl > 'abab'.indexOf('a') 0 > 'abab'.indexOf('a', 1) 2 > 'abab'.indexOf('c') -1 ``` * `lastIndexOf(searchString: string, maxIndex=Infinity): number` ES1 Returns the highest index at which `searchString` appears within `this`, or `-1`, otherwise. Any returned index will be `maxIndex` or lower. ```repl > 'abab'.lastIndexOf('ab', 2) 2 > 'abab'.lastIndexOf('ab', 1) 0 > 'abab'.lastIndexOf('ab') 2 ``` ## TODO * String.prototype.localeCompare ( that [ , reserved1 [ , reserved2 ] ] ) * String.prototype.match ( regexp ) * String.prototype.normalize ( [ form ] ) * String.prototype.padEnd( maxLength [ , fillString ] ) * String.prototype.padStart( maxLength [ , fillString ] ) * String.prototype.repeat ( count ) * String.prototype.replace ( searchValue, replaceValue ) * String.prototype.search ( regexp ) * String.prototype.slice ( start, end ) * String.prototype.split ( separator, limit ) * String.prototype.startsWith ( searchString [ , position ] ) * String.prototype.substring ( start, end ) * String.prototype.toLocaleLowerCase ( [ reserved1 [ , reserved2 ] ] ) * String.prototype.toLocaleUpperCase ( [ reserved1 [ , reserved2 ] ] ) * String.prototype.toLowerCase ( ) * String.prototype.toString ( ) * String.prototype.toUpperCase ( ) * String.prototype.trim ( ) * String.prototype.valueOf ( ) * String.prototype [ @@iterator ] ( ) ## More information * String methods of various ECMAScript versions in detail: http://exploringjs.com ## Sources * https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts * MDN * ECMAScript spec