encoder.js 582 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _constants = require('./constants');
  6. // Encode data string
  7. var encode = function encode(data, structure, separator) {
  8. var encoded = data.split('').map(function (val, idx) {
  9. return _constants.BINARIES[structure[idx]];
  10. }).map(function (val, idx) {
  11. return val ? val[data[idx]] : '';
  12. });
  13. if (separator) {
  14. var last = data.length - 1;
  15. encoded = encoded.map(function (val, idx) {
  16. return idx < last ? val + separator : val;
  17. });
  18. }
  19. return encoded.join('');
  20. };
  21. exports.default = encode;