Skip to content

Commit

Permalink
Make cssjanus.js compatible with closure compiler
Browse files Browse the repository at this point in the history
Closes #61.
  • Loading branch information
scriby authored and Krinkle committed Jun 25, 2018
1 parent d0d6a1c commit e2b39ec
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions src/cssjanus.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function CSSJanus() {
* @param {boolean} [options.transformEdgeInUrl=false] Transform edges in URLs (e.g. 'left', 'right')
* @return {string} Transformed stylesheet
*/
transform: function ( css, options ) {
'transform': function ( css, options ) { // eslint-disable-line quote-props, (for closure compiler)
// Tokenizers
var noFlipSingleTokenizer = new Tokenizer( noFlipSingleRegExp, noFlipSingleToken ),
noFlipClassTokenizer = new Tokenizer( noFlipClassRegExp, noFlipClassToken ),
Expand Down Expand Up @@ -389,30 +389,37 @@ cssjanus = new CSSJanus();

/* Exports */

/**
* Transform a left-to-right stylesheet to right-to-left.
*
* This function is a static wrapper around the transform method of an instance of CSSJanus.
*
* @param {string} css Stylesheet to transform
* @param {Object|boolean} [options] Options object, or transformDirInUrl option (back-compat)
* @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')
* @param {boolean} [transformEdgeInUrl] Back-compat parameter
* @return {string} Transformed stylesheet
*/
exports.transform = function ( css, options, transformEdgeInUrl ) {
var norm;
if ( typeof options === 'object' ) {
norm = options;
} else {
norm = {};
if ( typeof options === 'boolean' ) {
norm.transformDirInUrl = options;
}
if ( typeof transformEdgeInUrl === 'boolean' ) {
norm.transformEdgeInUrl = transformEdgeInUrl;
if ( typeof module !== 'undefined' && module.exports ) {
/**
* Transform a left-to-right stylesheet to right-to-left.
*
* This function is a static wrapper around the transform method of an instance of CSSJanus.
*
* @param {string} css Stylesheet to transform
* @param {Object|boolean} [options] Options object, or transformDirInUrl option (back-compat)
* @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')
* @param {boolean} [transformEdgeInUrl] Back-compat parameter
* @return {string} Transformed stylesheet
*/
exports.transform = function ( css, options, transformEdgeInUrl ) {
var norm;
if ( typeof options === 'object' ) {
norm = options;
} else {
norm = {};
if ( typeof options === 'boolean' ) {
norm.transformDirInUrl = options;
}
if ( typeof transformEdgeInUrl === 'boolean' ) {
norm.transformEdgeInUrl = transformEdgeInUrl;
}
}
}
return cssjanus.transform( css, norm );
};
return cssjanus.transform( css, norm );
};
} else if ( typeof window !== 'undefined' ) {
/* global window */
// Allow cssjanus to be used in a browser.
// eslint-disable-next-line dot-notation
window[ 'cssjanus' ] = cssjanus;
}

0 comments on commit e2b39ec

Please sign in to comment.