Guest User

Untitled

a guest
Dec 9th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. /* call with file to be cleaned
  2. write result into file with postfix ".cleaned"
  3. */
  4.  
  5. var fs = require('fs');
  6. var system = require('system');
  7.  
  8. var text = fs.read(system.args[1]);
  9.  
  10. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  11.  
  12. if (cx.test(text)) {
  13. text = text.replace(cx, function(a) {
  14. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  15. });
  16. }
  17. fs.write(system.args[0] + '.cleaned', text);
Add Comment
Please, Sign In to add comment