strings.js 729 B

1234567891011121314151617181920212223
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.utf8 = exports.ascii = void 0;
  4. const bufferToUint8Array_1 = require("./bufferToUint8Array");
  5. const ascii = (txt) => {
  6. if (typeof txt === 'string')
  7. return (0, exports.ascii)([txt]);
  8. [txt] = txt;
  9. const len = txt.length;
  10. const res = new Uint8Array(len);
  11. for (let i = 0; i < len; i++)
  12. res[i] = txt.charCodeAt(i);
  13. return res;
  14. };
  15. exports.ascii = ascii;
  16. const utf8 = (txt) => {
  17. if (typeof txt === 'string')
  18. return (0, exports.utf8)([txt]);
  19. [txt] = txt;
  20. return (0, bufferToUint8Array_1.bufferToUint8Array)(Buffer.from(txt, 'utf8'));
  21. };
  22. exports.utf8 = utf8;
  23. //# sourceMappingURL=strings.js.map