Ohm-Management - Projektarbeit B-ME
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.

generate-code-points.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. const bitfield = require('sparse-bitfield');
  3. const codePoints = require('./lib/code-points');
  4. const unassigned_code_points = bitfield();
  5. const commonly_mapped_to_nothing = bitfield();
  6. const non_ascii_space_characters = bitfield();
  7. const prohibited_characters = bitfield();
  8. const bidirectional_r_al = bitfield();
  9. const bidirectional_l = bitfield();
  10. /**
  11. * Iterare over code points and
  12. * convert it into an buffer.
  13. * @param {bitfield} bits
  14. * @param {Array} src
  15. * @returns {Buffer}
  16. */
  17. function traverse(bits, src) {
  18. for (const code of src.keys()) {
  19. bits.set(code, true);
  20. }
  21. const buffer = bits.toBuffer();
  22. return Buffer.concat([createSize(buffer), buffer]);
  23. }
  24. /**
  25. * @param {Buffer} buffer
  26. * @returns {Buffer}
  27. */
  28. function createSize(buffer) {
  29. const buf = Buffer.alloc(4);
  30. buf.writeUInt32BE(buffer.length);
  31. return buf;
  32. }
  33. const memory = [];
  34. memory.push(
  35. traverse(unassigned_code_points, codePoints.unassigned_code_points),
  36. traverse(commonly_mapped_to_nothing, codePoints.commonly_mapped_to_nothing),
  37. traverse(non_ascii_space_characters, codePoints.non_ASCII_space_characters),
  38. traverse(prohibited_characters, codePoints.prohibited_characters),
  39. traverse(bidirectional_r_al, codePoints.bidirectional_r_al),
  40. traverse(bidirectional_l, codePoints.bidirectional_l)
  41. );
  42. process.stdout.write(Buffer.concat(memory));