lib/en.js
function switchPersonStr( str ) {
	var switchPersonStrVerb = {} ;

	return str.replace( /\s+|(i|you|he|she|it|we|they)\s+(\S+)(?=\s)/gi , ( match , pronoun , verb ) => {
		if ( ! pronoun ) { return match ; }

		var person = null , plural = null , switchedPronoun = null ;

		pronoun = pronoun.toLowerCase() ;
		verb = verb.toLowerCase() ;

		switch ( pronoun ) {
			case 'he' :
			case 'she' :
			case 'it' :
			case 'they' :
				return match ;
			case 'i' : person = 1 ; plural = false ; switchedPronoun = 'you' ; break ;
			case 'you' : person = 2 ; switchedPronoun = 'I' ; break ;
			case 'we' : person = 1 ; plural = true ; switchedPronoun = 'you' ; break ;
		}

		if ( ! switchPersonStrVerb[ verb ] ) {
			// Damned! We don't know that verb!
			return switchedPronoun + ' ' + verb ;
		}

		return switchedPronoun + ' ' + switchPersonStrVerb[ verb ] ;
	} ) ;
}
function switchPersonStr( str ) {
	var switchPersonStrVerb = {} ;

	return str.replace( /\s+|(i|you|he|she|it|we|they)\s+(\S+)(?=\s)/gi , ( match , pronoun , verb ) => {
		if ( ! pronoun ) { return match ; }

		var person = null , plural = null , switchedPronoun = null ;

		pronoun = pronoun.toLowerCase() ;
		verb = verb.toLowerCase() ;

		switch ( pronoun ) {
			case 'he' :
			case 'she' :
			case 'it' :
			case 'they' :
				return match ;
			case 'i' : person = 1 ; plural = false ; switchedPronoun = 'you' ; break ;
			case 'you' : person = 2 ; switchedPronoun = 'I' ; break ;
			case 'we' : person = 1 ; plural = true ; switchedPronoun = 'you' ; break ;
		}

		if ( ! switchPersonStrVerb[ verb ] ) {
			// Damned! We don't know that verb!
			return switchedPronoun + ' ' + verb ;
		}

		return switchedPronoun + ' ' + switchPersonStrVerb[ verb ] ;
	} ) ;
}
function switchPersonStr ( str ) { var switchPersonStrVerb = { } ; return str . replace ( / \s+|(i|you|he|she|it|we|they)\s+(\S+)(?=\s) / gi , ( match , pronoun , verb ) => { if ( ! pronoun ) { return match ; } var person = null , plural = null , switchedPronoun = null ; pronoun = pronoun . toLowerCase ( ) ; verb = verb . toLowerCase ( ) ; switch ( pronoun ) { case 'he' : case 'she' : case 'it' : case 'they' : return match ; case 'i' : person = 1 ; plural = false ; switchedPronoun = 'you' ; break ; case 'you' : person = 2 ; switchedPronoun = 'I' ; break ; case 'we' : person = 1 ; plural = true ; switchedPronoun = 'you' ; break ; } if ( ! switchPersonStrVerb [ verb ] ) { // Damned! We don't know that verb! return switchedPronoun + ' ' + verb ; } return switchedPronoun + ' ' + switchPersonStrVerb [ verb ] ; } ) ; }
Switch a person, using a string
Switch a person using a string