You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
511 B

4 years ago
  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. };