I am beginner in JavaScript and I am trying to use rtlcss library to conver css files from ltr to rtl. I am using this code but it displays 2 errors:
Uncaught SyntaxError: Illegal return statement
Uncaught ReferenceError: require is not defined
My code
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>convert css to rtl</title>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="js/rtlcss/src/rtlcss.js"></script>
</head>
<body>
<textarea id="source_textarea" placeholder="place your css" ></textarea>
<button id="convert_btn">Convert</button>
<textarea id="result_textarea"></textarea>
<script>
(function myfunction() {
rtlcss = require('rtlcss');
var output = rtlcss.process('css/main.css');
console.log(output);
$("#result_textarea").val(output);
})();
</script>
</body>
</html>
I believe i am doing something wrong, it's not library problem.. so anyone can help?
This is a node package, as @haakym mentioned, you should be using NPM (node package manager). For more details on how to install and use NPM, follow the Getting Started guide.
If you want to use it in the browser, you can use Browserify; it lets you require('modules') in the browser by bundling up all of your dependencies.
After you have node/npm setup complete, do the following:
From the command line, run these commands to install RTLCSS and Browserify
Create a file with the following contents and save it as
main.js
:Run this command to create a browser usable bundle:
Include the resulting script in your page:
That's all, Now you'll be able to use it in the browser:
Online Demo