Created
August 8, 2018 09:45
-
-
Save samokoder/ce786a2ba844deffc2bea2a8660849da to your computer and use it in GitHub Desktop.
Snippet to append rtl prefix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require('fs'); | |
| const rtlcss = require('rtlcss'); | |
| const options = { | |
| 'autoRename': false, | |
| 'autoRenameStrict': false, | |
| 'blacklist':{}, | |
| 'clean': true, | |
| 'greedy': false, | |
| 'processUrls': false, | |
| 'stringMap': [ | |
| { | |
| 'name' : 'left-right', | |
| 'priority': 100, | |
| 'search' : ['left', 'Left', 'LEFT'], | |
| 'replace' : ['right', 'Right', 'RIGHT'], | |
| 'options' : { | |
| 'scope' : '*', | |
| 'ignoreCase' : false | |
| } | |
| }, | |
| { | |
| 'name' : 'ltr-rtl', | |
| 'priority': 100, | |
| 'search' : ['ltr', 'Ltr', 'LTR'], | |
| 'replace' : ['rtl', 'Rtl', 'RTL'], | |
| 'options' : { | |
| 'scope' : '*', | |
| 'ignoreCase' : false | |
| } | |
| } | |
| ], | |
| 'useCalc': false | |
| }; | |
| var hooks = { | |
| post:function(root, postcss){ | |
| root.nodes.forEach(x => { | |
| if ('atrule' == x.type) { | |
| x.nodes.forEach(y => { | |
| const selectors = y.selector.split(',').map(w => `[dir="rtl"] ${w.trim()}`); | |
| y.selector = selectors.join(', '); | |
| }); | |
| } else if ('rule' == x.type) { | |
| const selectors = x.selector.split(',').map(z => `[dir="rtl"] ${z.trim()}`); | |
| x.selector = selectors.join(', '); | |
| } | |
| }); | |
| } | |
| }; | |
| fs.readFile('./file.css', 'utf-8', function(err, contents) { | |
| const newContent = rtlcss.process(contents, options, /*plugins*/ [], hooks); | |
| console.log(newContent); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment