src/cssjanus.js
function ( css, options ) { // eslint-disable-line quote-props, (for closure compiler)
			// Tokenizers
			var noFlipSingleTokenizer = new Tokenizer( noFlipSingleRegExp, noFlipSingleToken ),
				noFlipClassTokenizer = new Tokenizer( noFlipClassRegExp, noFlipClassToken ),
				commentTokenizer = new Tokenizer( commentRegExp, commentToken );

			// Tokenize
			css = commentTokenizer.tokenize(
				noFlipClassTokenizer.tokenize(
					noFlipSingleTokenizer.tokenize(
						// We wrap tokens in ` , not ~ like the original implementation does.
						// This was done because ` is not a legal character in CSS and can only
						// occur in URLs, where we escape it to %60 before inserting our tokens.
						css.replace( '`', '%60' )
					)
				)
			);

			// Transform URLs
			if ( options.transformDirInUrl ) {
				// Replace 'ltr' with 'rtl' and vice versa in background URLs
				css = css
					.replace( ltrInUrlRegExp, '$1' + temporaryToken )
					.replace( rtlInUrlRegExp, '$1ltr' )
					.replace( temporaryTokenRegExp, 'rtl' );
			}
			if ( options.transformEdgeInUrl ) {
				// Replace 'left' with 'right' and vice versa in background URLs
				css = css
					.replace( leftInUrlRegExp, '$1' + temporaryToken )
					.replace( rightInUrlRegExp, '$1left' )
					.replace( temporaryTokenRegExp, 'right' );
			}

			// Transform rules
			css = css
				// Replace direction: ltr; with direction: rtl; and vice versa.
				.replace( directionLtrRegExp, '$1' + temporaryToken )
				.replace( directionRtlRegExp, '$1ltr' )
				.replace( temporaryTokenRegExp, 'rtl' )
				// Flip rules like left: , padding-right: , etc.
				.replace( leftRegExp, '$1' + temporaryToken )
				.replace( rightRegExp, '$1left' )
				.replace( temporaryTokenRegExp, 'right' )
				// Flip East and West in rules like cursor: nw-resize;
				.replace( cursorEastRegExp, '$1$2' + temporaryToken )
				.replace( cursorWestRegExp, '$1$2e-resize' )
				.replace( temporaryTokenRegExp, 'w-resize' )
				// Border radius
				.replace( borderRadiusRegExp, calculateNewBorderRadius )
				// Shadows
				.replace( boxShadowRegExp, calculateNewShadow )
				.replace( textShadow1RegExp, calculateNewFourTextShadow )
				.replace( textShadow2RegExp, calculateNewFourTextShadow )
				.replace( textShadow3RegExp, calculateNewShadow )
				// Translate
				.replace( translateXRegExp, calculateNewTranslate )
				.replace( translateRegExp, calculateNewTranslate )
				// Swap the second and fourth parts in four-part notation rules
				// like padding: 1px 2px 3px 4px;
				.replace( fourNotationQuantRegExp, '$1$2$3$8$5$6$7$4$9' )
				.replace( fourNotationColorRegExp, '$1$2$3$8$5$6$7$4$9' )
				// Flip horizontal background percentages
				.replace( bgHorizontalPercentageRegExp, calculateNewBackgroundPosition )
				.replace( bgHorizontalPercentageXRegExp, calculateNewBackgroundPosition );

			// Detokenize
			css = noFlipSingleTokenizer.detokenize(
				noFlipClassTokenizer.detokenize(
					commentTokenizer.detokenize( css )
				)
			);

			return css;
		}
function ( css, options ) { // eslint-disable-line quote-props, (for closure compiler)
			// Tokenizers
			var noFlipSingleTokenizer = new Tokenizer( noFlipSingleRegExp, noFlipSingleToken ),
				noFlipClassTokenizer = new Tokenizer( noFlipClassRegExp, noFlipClassToken ),
				commentTokenizer = new Tokenizer( commentRegExp, commentToken );

			// Tokenize
			css = commentTokenizer.tokenize(
				noFlipClassTokenizer.tokenize(
					noFlipSingleTokenizer.tokenize(
						// We wrap tokens in ` , not ~ like the original implementation does.
						// This was done because ` is not a legal character in CSS and can only
						// occur in URLs, where we escape it to %60 before inserting our tokens.
						css.replace( '`', '%60' )
					)
				)
			);

			// Transform URLs
			if ( options.transformDirInUrl ) {
				// Replace 'ltr' with 'rtl' and vice versa in background URLs
				css = css
					.replace( ltrInUrlRegExp, '$1' + temporaryToken )
					.replace( rtlInUrlRegExp, '$1ltr' )
					.replace( temporaryTokenRegExp, 'rtl' );
			}
			if ( options.transformEdgeInUrl ) {
				// Replace 'left' with 'right' and vice versa in background URLs
				css = css
					.replace( leftInUrlRegExp, '$1' + temporaryToken )
					.replace( rightInUrlRegExp, '$1left' )
					.replace( temporaryTokenRegExp, 'right' );
			}

			// Transform rules
			css = css
				// Replace direction: ltr; with direction: rtl; and vice versa.
				.replace( directionLtrRegExp, '$1' + temporaryToken )
				.replace( directionRtlRegExp, '$1ltr' )
				.replace( temporaryTokenRegExp, 'rtl' )
				// Flip rules like left: , padding-right: , etc.
				.replace( leftRegExp, '$1' + temporaryToken )
				.replace( rightRegExp, '$1left' )
				.replace( temporaryTokenRegExp, 'right' )
				// Flip East and West in rules like cursor: nw-resize;
				.replace( cursorEastRegExp, '$1$2' + temporaryToken )
				.replace( cursorWestRegExp, '$1$2e-resize' )
				.replace( temporaryTokenRegExp, 'w-resize' )
				// Border radius
				.replace( borderRadiusRegExp, calculateNewBorderRadius )
				// Shadows
				.replace( boxShadowRegExp, calculateNewShadow )
				.replace( textShadow1RegExp, calculateNewFourTextShadow )
				.replace( textShadow2RegExp, calculateNewFourTextShadow )
				.replace( textShadow3RegExp, calculateNewShadow )
				// Translate
				.replace( translateXRegExp, calculateNewTranslate )
				.replace( translateRegExp, calculateNewTranslate )
				// Swap the second and fourth parts in four-part notation rules
				// like padding: 1px 2px 3px 4px;
				.replace( fourNotationQuantRegExp, '$1$2$3$8$5$6$7$4$9' )
				.replace( fourNotationColorRegExp, '$1$2$3$8$5$6$7$4$9' )
				// Flip horizontal background percentages
				.replace( bgHorizontalPercentageRegExp, calculateNewBackgroundPosition )
				.replace( bgHorizontalPercentageXRegExp, calculateNewBackgroundPosition );

			// Detokenize
			css = noFlipSingleTokenizer.detokenize(
				noFlipClassTokenizer.detokenize(
					commentTokenizer.detokenize( css )
				)
			);

			return css;
		}
function ( css , options ) { // eslint-disable-line quote-props, (for closure compiler) // Tokenizers var noFlipSingleTokenizer = new Tokenizer ( noFlipSingleRegExp , noFlipSingleToken ) , noFlipClassTokenizer = new Tokenizer ( noFlipClassRegExp , noFlipClassToken ) , commentTokenizer = new Tokenizer ( commentRegExp , commentToken ) ; // Tokenize css = commentTokenizer . tokenize ( noFlipClassTokenizer . tokenize ( noFlipSingleTokenizer . tokenize ( // We wrap tokens in ` , not ~ like the original implementation does. // This was done because ` is not a legal character in CSS and can only // occur in URLs, where we escape it to %60 before inserting our tokens. css . replace ( '`' , '%60' ) ) ) ) ; // Transform URLs if ( options . transformDirInUrl ) { // Replace 'ltr' with 'rtl' and vice versa in background URLs css = css . replace ( ltrInUrlRegExp , '$1' + temporaryToken ) . replace ( rtlInUrlRegExp , '$1ltr' ) . replace ( temporaryTokenRegExp , 'rtl' ) ; } if ( options . transformEdgeInUrl ) { // Replace 'left' with 'right' and vice versa in background URLs css = css . replace ( leftInUrlRegExp , '$1' + temporaryToken ) . replace ( rightInUrlRegExp , '$1left' ) . replace ( temporaryTokenRegExp , 'right' ) ; } // Transform rules css = css // Replace direction: ltr; with direction: rtl; and vice versa. . replace ( directionLtrRegExp , '$1' + temporaryToken ) . replace ( directionRtlRegExp , '$1ltr' ) . replace ( temporaryTokenRegExp , 'rtl' ) // Flip rules like left: , padding-right: , etc. . replace ( leftRegExp , '$1' + temporaryToken ) . replace ( rightRegExp , '$1left' ) . replace ( temporaryTokenRegExp , 'right' ) // Flip East and West in rules like cursor: nw-resize; . replace ( cursorEastRegExp , '$1$2' + temporaryToken ) . replace ( cursorWestRegExp , '$1$2e-resize' ) . replace ( temporaryTokenRegExp , 'w-resize' ) // Border radius . replace ( borderRadiusRegExp , calculateNewBorderRadius ) // Shadows . replace ( boxShadowRegExp , calculateNewShadow ) . replace ( textShadow1RegExp , calculateNewFourTextShadow ) . replace ( textShadow2RegExp , calculateNewFourTextShadow ) . replace ( textShadow3RegExp , calculateNewShadow ) // Translate . replace ( translateXRegExp , calculateNewTranslate ) . replace ( translateRegExp , calculateNewTranslate ) // Swap the second and fourth parts in four-part notation rules // like padding: 1px 2px 3px 4px; . replace ( fourNotationQuantRegExp , '$1$2$3$8$5$6$7$4$9' ) . replace ( fourNotationColorRegExp , '$1$2$3$8$5$6$7$4$9' ) // Flip horizontal background percentages . replace ( bgHorizontalPercentageRegExp , calculateNewBackgroundPosition ) . replace ( bgHorizontalPercentageXRegExp , calculateNewBackgroundPosition ) ; // Detokenize css = noFlipSingleTokenizer . detokenize ( noFlipClassTokenizer . detokenize ( commentTokenizer . detokenize ( css ) ) ) ; return css ; }
Transform a left-to-right stylesheet to right-to-left.

@param {string} css Stylesheet to transform
@param {Object} options Options
@param {boolean} [options.transformDirInUrl=false] Transform directions in URLs (e.g. 'ltr', 'rtl')
@param {boolean} [options.transformEdgeInUrl=false] Transform edges in URLs (e.g. 'left', 'right')
@return {string} Transformed stylesheet
Transform a left - to - right stylesheet to right - to - left .