utils.js 511 B

1234567891011121314151617181920212223242526
  1. exports.assert = function assert(cond, text) {
  2. if (!cond)
  3. throw new Error(text);
  4. };
  5. exports.stringify = function stringify(arr) {
  6. var res = '';
  7. for (var i = 0; i < arr.length; i++)
  8. res += String.fromCharCode(arr[i]);
  9. return res;
  10. };
  11. exports.toArray = function toArray(str) {
  12. var res = [];
  13. for (var i = 0; i < str.length; i++) {
  14. var c = str.charCodeAt(i);
  15. var hi = c >>> 8;
  16. var lo = c & 0xff;
  17. if (hi)
  18. res.push(hi, lo);
  19. else
  20. res.push(lo);
  21. }
  22. return res;
  23. };