Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

decodeEntityRanges.js 973 B

il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. *
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. var UnicodeUtils = require("fbjs/lib/UnicodeUtils");
  13. var substr = UnicodeUtils.substr;
  14. /**
  15. * Convert to native JavaScript string lengths to determine ranges.
  16. */
  17. function decodeEntityRanges(text, ranges) {
  18. var entities = Array(text.length).fill(null);
  19. if (ranges) {
  20. ranges.forEach(function (range) {
  21. // Using Unicode-enabled substrings converted to JavaScript lengths,
  22. // fill the output array with entity keys.
  23. var start = substr(text, 0, range.offset).length;
  24. var end = start + substr(text, range.offset, range.length).length;
  25. for (var ii = start; ii < end; ii++) {
  26. entities[ii] = range.key;
  27. }
  28. });
  29. }
  30. return entities;
  31. }
  32. module.exports = decodeEntityRanges;